1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-reduce -S %s | FileCheck %s
4 ; Make sure SCEVExpander does not crash and introduce unnecessary LCSSA PHI nodes.
6 define void @schedule_block(i1 %arg) {
7 ; CHECK-LABEL: @schedule_block(
9 ; CHECK-NEXT: switch i16 0, label [[IF_END156_I:%.*]] [
10 ; CHECK-NEXT: i16 27, label [[IF_THEN_I:%.*]]
11 ; CHECK-NEXT: i16 28, label [[IF_THEN_I]]
12 ; CHECK-NEXT: i16 29, label [[IF_THEN13_I:%.*]]
13 ; CHECK-NEXT: i16 32, label [[LAND_LHS_TRUE136_I:%.*]]
16 ; CHECK-NEXT: unreachable
18 ; CHECK-NEXT: unreachable
19 ; CHECK: land.lhs.true136.i:
20 ; CHECK-NEXT: unreachable
22 ; CHECK-NEXT: switch i16 32, label [[WHILE_END256:%.*]] [
23 ; CHECK-NEXT: i16 29, label [[IF_THEN210:%.*]]
24 ; CHECK-NEXT: i16 28, label [[IF_THEN210]]
25 ; CHECK-NEXT: i16 27, label [[LAND_LHS_TRUE191:%.*]]
26 ; CHECK-NEXT: i16 32, label [[IF_END248:%.*]]
28 ; CHECK: land.lhs.true191:
29 ; CHECK-NEXT: unreachable
31 ; CHECK-NEXT: unreachable
33 ; CHECK-NEXT: br label [[FOR_END:%.*]]
34 ; CHECK: while.end256:
35 ; CHECK-NEXT: unreachable
37 ; CHECK-NEXT: br label [[WHILE_BODY1013:%.*]]
38 ; CHECK: while.body1013:
39 ; CHECK-NEXT: br label [[FOR_COND_I2472:%.*]]
40 ; CHECK: for.cond.i2472:
41 ; CHECK-NEXT: [[I_0_I:%.*]] = phi i32 [ 0, [[WHILE_BODY1013]] ], [ [[TMP2:%.*]], [[FOR_END34_I:%.*]] ]
42 ; CHECK-NEXT: br i1 false, label [[FOR_COND3_PREHEADER_I:%.*]], label [[IF_END107_I_LOOPEXIT:%.*]]
43 ; CHECK: for.cond3.preheader.i:
44 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[I_0_I]] to i64
45 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], 1
46 ; CHECK-NEXT: br label [[FOR_COND3_I:%.*]]
48 ; CHECK-NEXT: [[INDVARS_IV301_I2691:%.*]] = phi i64 [ [[INDVARS_IV_NEXT302_I:%.*]], [[FOR_BODY5_I:%.*]] ], [ [[TMP1]], [[FOR_COND3_PREHEADER_I]] ]
49 ; CHECK-NEXT: [[INDVARS_IV_NEXT302_I]] = add nsw i64 [[INDVARS_IV301_I2691]], 1
50 ; CHECK-NEXT: br label [[FOR_BODY5_I]]
52 ; CHECK-NEXT: br i1 false, label [[FOR_COND3_I]], label [[FOR_BODY5_I_FOR_END_I2475_LOOPEXIT_CRIT_EDGE:%.*]]
53 ; CHECK: for.body5.i.for.end.i2475.loopexit_crit_edge:
54 ; CHECK-NEXT: [[TMP2]] = trunc i64 [[INDVARS_IV_NEXT302_I]] to i32
55 ; CHECK-NEXT: br label [[FOR_END34_I]]
57 ; CHECK-NEXT: br i1 false, label [[FOR_COND_I2472]], label [[IF_ELSE_I2488:%.*]]
58 ; CHECK: if.else.i2488:
59 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[IF_END107_I:%.*]], label [[FOR_BODY45_PREHEADER_I:%.*]]
60 ; CHECK: for.body45.preheader.i:
61 ; CHECK-NEXT: [[TMP3:%.*]] = sext i32 [[I_0_I]] to i64
62 ; CHECK-NEXT: unreachable
63 ; CHECK: if.end107.i.loopexit:
64 ; CHECK-NEXT: br label [[IF_END107_I]]
66 ; CHECK-NEXT: unreachable
69 switch i16 0, label %if.end156.i [
70 i16 27, label %if.then.i
71 i16 28, label %if.then.i
72 i16 29, label %if.then13.i
73 i16 32, label %land.lhs.true136.i
76 if.then.i: ; preds = %entry, %entry
79 if.then13.i: ; preds = %entry
82 land.lhs.true136.i: ; preds = %entry
85 if.end156.i: ; preds = %entry
86 switch i16 32, label %while.end256 [
87 i16 29, label %if.then210
88 i16 28, label %if.then210
89 i16 27, label %land.lhs.true191
90 i16 32, label %if.end248
93 land.lhs.true191: ; preds = %if.end156.i
96 if.then210: ; preds = %if.end156.i, %if.end156.i
99 if.end248: ; preds = %if.end156.i
102 while.end256: ; preds = %if.end156.i
105 for.end: ; preds = %if.end248
106 br label %while.body1013
108 while.body1013: ; preds = %for.end
109 br label %for.cond.i2472
111 for.cond.i2472: ; preds = %for.end34.i, %while.body1013
112 %i.0.i = phi i32 [ 0, %while.body1013 ], [ %2, %for.end34.i ]
113 br i1 false, label %for.cond3.preheader.i, label %if.end107.i
115 for.cond3.preheader.i: ; preds = %for.cond.i2472
116 %0 = sext i32 %i.0.i to i64
117 %1 = add nsw i64 %0, 1
118 br label %for.cond3.i
120 for.cond3.i: ; preds = %for.body5.i, %for.cond3.preheader.i
121 %indvars.iv301.i2691 = phi i64 [ %indvars.iv.next302.i, %for.body5.i ], [ %1, %for.cond3.preheader.i ]
122 %indvars.iv.next302.i = add nsw i64 %indvars.iv301.i2691, 1
123 br label %for.body5.i
125 for.body5.i: ; preds = %for.cond3.i
126 br i1 false, label %for.cond3.i, label %for.body5.i.for.end.i2475.loopexit_crit_edge
128 for.body5.i.for.end.i2475.loopexit_crit_edge: ; preds = %for.body5.i
129 %2 = trunc i64 %indvars.iv.next302.i to i32
130 br label %for.end34.i
132 for.end34.i: ; preds = %for.body5.i.for.end.i2475.loopexit_crit_edge
133 br i1 false, label %for.cond.i2472, label %if.else.i2488
135 if.else.i2488: ; preds = %for.end34.i
136 br i1 %arg, label %if.end107.i, label %for.body45.preheader.i
138 for.body45.preheader.i: ; preds = %if.else.i2488
139 %3 = sext i32 %i.0.i to i64
142 if.end107.i: ; preds = %if.else.i2488, %for.cond.i2472
146 define void @test_pr58007(ptr %A) {
147 ; CHECK-LABEL: @test_pr58007(
149 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
151 ; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[A:%.*]], align 2
152 ; CHECK-NEXT: br i1 false, label [[LOOP_1]], label [[LOOP_2_HEADER_PREHEADER:%.*]]
153 ; CHECK: loop.2.header.preheader:
154 ; CHECK-NEXT: [[L_LCSSA:%.*]] = phi i16 [ [[L]], [[LOOP_1]] ]
155 ; CHECK-NEXT: br label [[LOOP_2_HEADER:%.*]]
156 ; CHECK: loop.2.header:
157 ; CHECK-NEXT: [[P:%.*]] = phi i16 [ 1, [[LOOP_2_LATCH:%.*]] ], [ 0, [[LOOP_2_HEADER_PREHEADER]] ]
158 ; CHECK-NEXT: [[CMP3_I:%.*]] = icmp eq i16 [[P]], 0
159 ; CHECK-NEXT: br i1 [[CMP3_I]], label [[LOOP_2_LATCH]], label [[EXIT:%.*]]
160 ; CHECK: loop.2.latch:
161 ; CHECK-NEXT: br label [[LOOP_2_HEADER]]
163 ; CHECK-NEXT: store i16 [[L_LCSSA]], ptr [[A]], align 2
164 ; CHECK-NEXT: ret void
169 loop.1: ; preds = %loop.1, %entry
170 %l = load i16, ptr %A, align 2
171 %l.dec = add nsw i16 %l, -1
172 br i1 false, label %loop.1, label %loop.2.header
174 loop.2.header: ; preds = %loop.2.latch, %loop.1
175 %iv = phi i16 [ %l.dec, %loop.1 ], [ %iv.next, %loop.2.latch ]
176 %p = phi i16 [ 0, %loop.1 ], [ 1, %loop.2.latch ]
177 %cmp3.i = icmp eq i16 %p, 0
178 br i1 %cmp3.i, label %loop.2.latch, label %exit
180 loop.2.latch: ; preds = %loop.2.header
181 %iv.next = add nsw i16 %iv, 1
182 br label %loop.2.header
184 exit: ; preds = %loop.2.header
185 %iv.lcssa = phi i16 [ %iv, %loop.2.header ]
186 store i16 %iv.lcssa, ptr %A, align 2