File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -290,9 +290,13 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) {
290290 llvm::SmallVector<SILValue, 2 > BranchArgs;
291291 unsigned HasEnumArg = NeedEnumArg.contains (SEDest);
292292 if (SEDest->getNumArguments () == 1 + HasEnumArg) {
293- // The successor block has an original argument, which is the Enum's
294- // payload.
295- BranchArgs.push_back (EI->getOperand ());
293+ if (SEI->hasDefault () && SEDest == SEI->getDefaultBB ()) {
294+ BranchArgs.push_back (EI);
295+ } else {
296+ // The successor block has an original argument, which is the Enum's
297+ // payload.
298+ BranchArgs.push_back (EI->getOperand ());
299+ }
296300 }
297301 if (HasEnumArg) {
298302 // The successor block has a new argument (which we created above) where
Original file line number Diff line number Diff line change @@ -21,6 +21,13 @@ enum FakeOptional<T> {
2121 case some(T)
2222}
2323
24+ enum PrimaryColor : Int {
25+ case red = 0
26+ case blue = 1
27+ case green = 2
28+ }
29+
30+ sil [ossa] @use_color : $@convention(thin) (PrimaryColor) -> ()
2431sil [ossa] @callee : $@convention(thin) () -> ()
2532sil [ossa] @use_enum : $@convention(thin) (@guaranteed E) -> ()
2633sil [ossa] @use_int : $@convention(thin) (Builtin.Int64) -> ()
@@ -134,6 +141,34 @@ bb6:
134141 return %r : $()
135142}
136143
144+ sil [ossa] @simple_forwarding4 : $@convention(thin) (Builtin.Int1) -> () {
145+ bb0(%0 : $Builtin.Int1):
146+ cond_br %0, bb1, bb2
147+
148+ bb1:
149+ %2 = enum $PrimaryColor, #PrimaryColor.red!enumelt
150+ br bb3(%2 : $PrimaryColor)
151+
152+ bb2:
153+ %3 = enum $PrimaryColor, #PrimaryColor.blue!enumelt
154+ br bb3(%3 : $PrimaryColor)
155+
156+ bb3(%14 : $PrimaryColor):
157+ switch_enum %14 : $PrimaryColor, case #PrimaryColor.red!enumelt: bb4, default bb5
158+
159+ bb4:
160+ br bb6
161+
162+ bb5(%18 : $PrimaryColor):
163+ %15 = function_ref @use_color : $@convention(thin) (PrimaryColor) -> ()
164+ %16 = apply %15(%18) : $@convention(thin) (PrimaryColor) -> ()
165+ br bb6
166+
167+ bb6:
168+ %r = tuple ()
169+ return %r : $()
170+ }
171+
137172// CHECK-LABEL: sil [ossa] @simple_switch_enum_forwarding1 :
138173// CHECK: bb0({{.*}}):
139174// CHECK-NEXT: br bb3
You can’t perform that action at this time.
0 commit comments