From 632b5ce0c8588368cd847bc17ddbf72c2f50e0e6 Mon Sep 17 00:00:00 2001 From: Meghana Gupta Date: Thu, 11 Jun 2020 09:52:11 -0700 Subject: [PATCH] Ignore OnFastPath builtin while looking for valid static initializer of a global variable --- lib/SIL/IR/SILGlobalVariable.cpp | 2 ++ test/SILOptimizer/optionset.swift | 33 +++++++++++++------------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/SIL/IR/SILGlobalVariable.cpp b/lib/SIL/IR/SILGlobalVariable.cpp index a7473bbd287e6..9c0493016f056 100644 --- a/lib/SIL/IR/SILGlobalVariable.cpp +++ b/lib/SIL/IR/SILGlobalVariable.cpp @@ -136,6 +136,8 @@ bool SILGlobalVariable::isValidStaticInitializerInst(const SILInstruction *I, auto *TE = bi->getSingleUserOfType(); return TE && getOffsetSubtract(TE, M); } + case BuiltinValueKind::OnFastPath: + return true; default: break; } diff --git a/test/SILOptimizer/optionset.swift b/test/SILOptimizer/optionset.swift index 6e332bc27281e..4890c8bb5ca5a 100644 --- a/test/SILOptimizer/optionset.swift +++ b/test/SILOptimizer/optionset.swift @@ -12,7 +12,13 @@ public struct TestOptions: OptionSet { static let fourth = TestOptions(rawValue: 1 << 3) } -// CHECK: sil @{{.*}}returnTestOptions{{.*}} +// CHECK-LABEL: sil_global hidden [let] @$s4test17globalTestOptionsAA0cD0Vvp : $TestOptions = { +// CHECK: [[CONST:%.*]] = integer_literal $Builtin.Int{{32|64}}, 15 +// CHECK: [[INT:%.*]] = struct $Int (%0 : $Builtin.Int{{32|64}}) +// CHECK: %initval = struct $TestOptions ([[INT]] : $Int) +let globalTestOptions: TestOptions = [.first, .second, .third, .fourth] + +// CHECK-LABEL: sil @{{.*}}returnTestOptions{{.*}} // CHECK-NEXT: bb0: // CHECK-NEXT: builtin // CHECK-NEXT: integer_literal {{.*}}, 15 @@ -23,24 +29,13 @@ public func returnTestOptions() -> TestOptions { return [.first, .second, .third, .fourth] } -// CHECK: sil @{{.*}}returnEmptyTestOptions{{.*}} -// CHECK: [[ZERO:%[0-9]+]] = integer_literal {{.*}}, 0 -// CHECK: [[ZEROINT:%[0-9]+]] = struct $Int ([[ZERO]] -// CHECK: [[TO:%[0-9]+]] = struct $TestOptions ([[ZEROINT]] -// CHECK: return [[TO]] -// CHECK: } // end sil function {{.*}}returnEmptyTestOptions{{.*}} -public func returnEmptyTestOptions() -> TestOptions { - return [] -} - -// CHECK: alloc_global @{{.*}}globalTestOptions{{.*}} -// CHECK-NEXT: global_addr -// CHECK-NEXT: builtin -// CHECK-NEXT: integer_literal {{.*}}, 15 +// CHECK-LABEL: sil @{{.*}}returnEmptyTestOptions{{.*}} +// CHECK-NEXT: bb0: +// CHECK-NEXT: integer_literal {{.*}}, 0 +// CHECK-NEXT: builtin "onFastPath"() : $() // CHECK-NEXT: struct $Int // CHECK-NEXT: struct $TestOptions -// CHECK-NEXT: store -// CHECK-NEXT: tuple // CHECK-NEXT: return -let globalTestOptions: TestOptions = [.first, .second, .third, .fourth] - +public func returnEmptyTestOptions() -> TestOptions { + return [] +}