Skip to content

Commit 5cb0f4d

Browse files
committed
[SimplifyCFG] Don't limit the number of simultaneous forwards from switch condition
1 parent ea16f9c commit 5cb0f4d

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5818,8 +5818,6 @@ static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
58185818
for (auto &ForwardingNode : ForwardingNodes) {
58195819
PHINode *Phi = ForwardingNode.first;
58205820
SmallVectorImpl<int> &Indexes = ForwardingNode.second;
5821-
if (Indexes.size() < 2)
5822-
continue;
58235821

58245822
for (int Index : Indexes)
58255823
Phi->setIncomingValue(Index, SI->getCondition());

llvm/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ define i32 @forward_one(i32 %m) {
9797
; FWD: sw.bb4:
9898
; FWD-NEXT: br label [[RETURN]]
9999
; FWD: return:
100-
; FWD-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 4, [[SW_BB4]] ], [ 5, [[SW_BB3]] ], [ 6, [[SW_BB2]] ], [ 1, [[SW_BB1]] ], [ 8, [[ENTRY:%.*]] ]
100+
; FWD-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 4, [[SW_BB4]] ], [ 5, [[SW_BB3]] ], [ 6, [[SW_BB2]] ], [ [[M]], [[SW_BB1]] ], [ 8, [[ENTRY:%.*]] ]
101101
; FWD-NEXT: ret i32 [[RETVAL_0]]
102102
;
103103
entry:
@@ -207,19 +207,15 @@ define { i64, i64 } @PR95919(i64 noundef %arg, i64 noundef %arg1) {
207207
;
208208
; FWD-LABEL: @PR95919(
209209
; FWD-NEXT: bb:
210-
; FWD-NEXT: switch i64 [[ARG1:%.*]], label [[BB3:%.*]] [
211-
; FWD-NEXT: i64 0, label [[BB5:%.*]]
212-
; FWD-NEXT: i64 1, label [[BB2:%.*]]
213-
; FWD-NEXT: ]
214-
; FWD: bb2:
215-
; FWD-NEXT: br label [[BB5]]
210+
; FWD-NEXT: [[SWITCH:%.*]] = icmp ult i64 [[ARG1:%.*]], 2
211+
; FWD-NEXT: br i1 [[SWITCH]], label [[BB5:%.*]], label [[BB3:%.*]]
216212
; FWD: bb3:
217213
; FWD-NEXT: [[I:%.*]] = udiv i64 [[ARG:%.*]], [[ARG1]]
218214
; FWD-NEXT: [[I4:%.*]] = shl nuw i64 [[I]], 1
219215
; FWD-NEXT: br label [[BB5]]
220216
; FWD: bb5:
221-
; FWD-NEXT: [[I6:%.*]] = phi i64 [ [[I4]], [[BB3]] ], [ [[ARG]], [[BB2]] ], [ undef, [[BB:%.*]] ]
222-
; FWD-NEXT: [[I7:%.*]] = phi i64 [ 1, [[BB3]] ], [ 1, [[BB2]] ], [ [[ARG1]], [[BB]] ]
217+
; FWD-NEXT: [[I6:%.*]] = phi i64 [ [[I4]], [[BB3]] ], [ [[ARG]], [[BB:%.*]] ]
218+
; FWD-NEXT: [[I7:%.*]] = phi i64 [ 1, [[BB3]] ], [ [[ARG1]], [[BB]] ]
223219
; FWD-NEXT: [[I8:%.*]] = insertvalue { i64, i64 } poison, i64 [[I7]], 0
224220
; FWD-NEXT: [[I9:%.*]] = insertvalue { i64, i64 } [[I8]], i64 [[I6]], 1
225221
; FWD-NEXT: ret { i64, i64 } [[I9]]

0 commit comments

Comments
 (0)