File tree 2 files changed +42
-3
lines changed
lib/SILOptimizer/Transforms
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) {
290
290
llvm::SmallVector<SILValue, 2 > BranchArgs;
291
291
unsigned HasEnumArg = NeedEnumArg.contains (SEDest);
292
292
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
+ }
296
300
}
297
301
if (HasEnumArg) {
298
302
// 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> {
21
21
case some(T)
22
22
}
23
23
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) -> ()
24
31
sil [ossa] @callee : $@convention(thin) () -> ()
25
32
sil [ossa] @use_enum : $@convention(thin) (@guaranteed E) -> ()
26
33
sil [ossa] @use_int : $@convention(thin) (Builtin.Int64) -> ()
@@ -134,6 +141,34 @@ bb6:
134
141
return %r : $()
135
142
}
136
143
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
+
137
172
// CHECK-LABEL: sil [ossa] @simple_switch_enum_forwarding1 :
138
173
// CHECK: bb0({{.*}}):
139
174
// CHECK-NEXT: br bb3
You can’t perform that action at this time.
0 commit comments