1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=indvars -indvars-predicate-loops=0 < %s | FileCheck %s
4 ; Check that we don't reuse %zext instead of %inc11 for LCSSA Phi node. Case
7 define i32 @test_01() {
8 ; CHECK-LABEL: @test_01(
10 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
11 ; CHECK: for.cond1.preheader:
12 ; CHECK-NEXT: br label [[FOR_COND4_PREHEADER:%.*]]
13 ; CHECK: for.cond4.preheader:
14 ; CHECK-NEXT: [[ZEXT:%.*]] = zext i16 1 to i32
15 ; CHECK-NEXT: br label [[FOR_BODY6:%.*]]
17 ; CHECK-NEXT: br i1 true, label [[FOR_BODY6]], label [[FOR_END:%.*]]
19 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[FOR_COND4_PREHEADER]] ], [ [[INC:%.*]], [[FOR_COND4:%.*]] ]
20 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[IV]], [[ZEXT]]
21 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IV]], 1
22 ; CHECK-NEXT: br i1 [[TMP0]], label [[RETURN_LOOPEXIT:%.*]], label [[FOR_COND4]]
24 ; CHECK-NEXT: br i1 false, label [[FOR_COND4_PREHEADER]], label [[FOR_END9:%.*]]
26 ; CHECK-NEXT: br i1 false, label [[FOR_COND1_PREHEADER]], label [[RETURN_LOOPEXIT3:%.*]]
27 ; CHECK: return.loopexit:
28 ; CHECK-NEXT: unreachable
29 ; CHECK: return.loopexit3:
30 ; CHECK-NEXT: br label [[RETURN:%.*]]
32 ; CHECK-NEXT: ret i32 1
35 br label %for.cond1.preheader
37 for.cond1.preheader: ; preds = %for.end9, %entry
38 br label %for.cond4.preheader
40 for.cond4.preheader: ; preds = %for.end, %for.cond1.preheader
41 %zext = zext i16 1 to i32
44 for.cond4: ; preds = %for.body6
45 %cmp5 = icmp ult i32 %inc, 2
46 br i1 %cmp5, label %for.body6, label %for.end
48 for.body6: ; preds = %for.cond4, %for.cond4.preheader
49 %iv = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.cond4 ]
50 %0 = icmp eq i32 %iv, %zext
51 %inc = add nuw nsw i32 %iv, 1
52 br i1 %0, label %return.loopexit, label %for.cond4
54 for.end: ; preds = %for.cond4
55 br i1 false, label %for.cond4.preheader, label %for.end9
57 for.end9: ; preds = %for.end
58 %inc11 = add nuw nsw i32 0, 1
59 br i1 false, label %for.cond1.preheader, label %return.loopexit3
61 return.loopexit: ; preds = %for.body6
64 return.loopexit3: ; preds = %for.end9
65 %inc11.lcssa = phi i32 [ %inc11, %for.end9 ]
68 return: ; preds = %return.loopexit3
72 ; Same as test_01, but the instructions with the same SCEV have a non-constant
74 define i32 @test_02(i32 %x) {
75 ; CHECK-LABEL: @test_02(
77 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
78 ; CHECK: for.cond1.preheader:
79 ; CHECK-NEXT: br label [[FOR_COND4_PREHEADER:%.*]]
80 ; CHECK: for.cond4.preheader:
81 ; CHECK-NEXT: [[ZEXT:%.*]] = mul i32 [[X:%.*]], 1
82 ; CHECK-NEXT: br label [[FOR_BODY6:%.*]]
84 ; CHECK-NEXT: [[CMP5:%.*]] = icmp ult i32 [[INC:%.*]], 2
85 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY6]], label [[FOR_END:%.*]]
87 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[FOR_COND4_PREHEADER]] ], [ [[INC]], [[FOR_COND4:%.*]] ]
88 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[IV]], [[ZEXT]]
89 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IV]], 1
90 ; CHECK-NEXT: br i1 [[TMP0]], label [[RETURN_LOOPEXIT:%.*]], label [[FOR_COND4]]
92 ; CHECK-NEXT: br i1 false, label [[FOR_COND4_PREHEADER]], label [[FOR_END9:%.*]]
94 ; CHECK-NEXT: br i1 false, label [[FOR_COND1_PREHEADER]], label [[RETURN_LOOPEXIT3:%.*]]
95 ; CHECK: return.loopexit:
96 ; CHECK-NEXT: unreachable
97 ; CHECK: return.loopexit3:
98 ; CHECK-NEXT: br label [[RETURN:%.*]]
100 ; CHECK-NEXT: ret i32 [[X]]
103 br label %for.cond1.preheader
105 for.cond1.preheader: ; preds = %for.end9, %entry
106 br label %for.cond4.preheader
108 for.cond4.preheader: ; preds = %for.end, %for.cond1.preheader
109 %zext = mul i32 %x, 1
112 for.cond4: ; preds = %for.body6
113 %cmp5 = icmp ult i32 %inc, 2
114 br i1 %cmp5, label %for.body6, label %for.end
116 for.body6: ; preds = %for.cond4, %for.cond4.preheader
117 %iv = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.cond4 ]
118 %0 = icmp eq i32 %iv, %zext
119 %inc = add nuw nsw i32 %iv, 1
120 br i1 %0, label %return.loopexit, label %for.cond4
122 for.end: ; preds = %for.cond4
123 br i1 false, label %for.cond4.preheader, label %for.end9
125 for.end9: ; preds = %for.end
126 %inc11 = add nuw nsw i32 0, %x
127 br i1 false, label %for.cond1.preheader, label %return.loopexit3
129 return.loopexit: ; preds = %for.body6
132 return.loopexit3: ; preds = %for.end9
133 %inc11.lcssa = phi i32 [ %inc11, %for.end9 ]
136 return: ; preds = %return.loopexit3