1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -loop-reduce -S %s | FileCheck %s
4 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx"
8 declare void @use.i32(i32)
9 declare void @use.i8(i8)
11 define i32 @test_pr38847() {
12 ; CHECK-LABEL: define i32 @test_pr38847() {
14 ; CHECK-NEXT: br label [[LOOP:%.*]]
16 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i32 [ [[LSR_IV_NEXT2:%.*]], [[LOOP]] ], [ 1, [[ENTRY:%.*]] ]
17 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[LOOP]] ], [ 1, [[ENTRY]] ]
18 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add nsw i32 [[LSR_IV1]], -1
19 ; CHECK-NEXT: [[LSR:%.*]] = trunc i32 [[LSR_IV_NEXT2]] to i8
20 ; CHECK-NEXT: call void @use(i64 [[LSR_IV]])
21 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], -1
22 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[LSR]], -1
23 ; CHECK-NEXT: br i1 [[CMP2]], label [[LOOP]], label [[EXIT:%.*]]
25 ; CHECK-NEXT: [[TMP2:%.*]] = urem i32 [[LSR_IV_NEXT2]], 9
26 ; CHECK-NEXT: ret i32 [[TMP2]]
32 %iv = phi i8 [ 1, %entry ], [ %iv.next, %loop ]
33 %iv.next = add nsw i8 %iv, -1
34 %ext = zext i8 %iv to i64
35 call void @use(i64 %ext)
36 %cmp2 = icmp sgt i8 %iv.next, -1
37 br i1 %cmp2, label %loop, label %exit
40 %sext = sext i8 %iv.next to i32
41 %rem = urem i32 %sext, 9
45 define i64 @test_pr58039() {
46 ; CHECK-LABEL: define i64 @test_pr58039() {
48 ; CHECK-NEXT: br label [[LOOP:%.*]]
50 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[LOOP]] ], [ -4294967213, [[ENTRY:%.*]] ]
51 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
52 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[IV]] to i32
53 ; CHECK-NEXT: call void @use.i32(i32 [[TMP2]])
54 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
55 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], 4294967295
56 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
58 ; CHECK-NEXT: [[TMP0:%.*]] = udiv i64 [[LSR_IV_NEXT]], 12
59 ; CHECK-NEXT: [[TMP1:%.*]] = mul nuw nsw i64 [[TMP0]], 12
60 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 4294967221
61 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[TMP2]], [[IV_NEXT]]
62 ; CHECK-NEXT: [[TMP:%.*]] = trunc i64 [[TMP3]] to i32
63 ; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i32 [[TMP]], 32
64 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[CMP3]], i64 0, i64 [[IV_NEXT]]
65 ; CHECK-NEXT: ret i64 [[SPEC_SELECT]]
71 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
72 %iv1 = phi i32 [ -74, %entry ], [ %iv1.next, %loop ]
73 %iv2 = phi i32 [ 83, %entry ], [ %iv2.next, %loop ]
74 %iv3 = phi i32 [ 0, %entry ], [ %iv3.next, %loop ]
75 call void @use.i32(i32 %iv3)
76 %iv.next = add nuw nsw i64 %iv, 1
77 %iv1.next = add nuw nsw i32 %iv1, 1
78 %iv2.next = add nsw i32 %iv2, -1
79 %iv3.next = add nuw nsw i32 %iv3, 1
80 br i1 false, label %loop, label %exit
83 %i2 = udiv i32 %iv2.next, 12
84 %i5 = mul nuw nsw i32 %i2, 12
85 %i6 = add i32 %iv1, %i5
86 %cmp3 = icmp ult i32 %i6, 32
87 %spec.select = select i1 %cmp3, i64 0, i64 %iv.next
91 define i32 @test_pr62852() {
92 ; CHECK-LABEL: define i32 @test_pr62852() {
94 ; CHECK-NEXT: br label [[LOOP:%.*]]
96 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ [[LSR_IV_NEXT2:%.*]], [[LOOP]] ], [ -1, [[ENTRY:%.*]] ]
97 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[LOOP]] ], [ 2, [[ENTRY]] ]
98 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[DEC_1:%.*]], [[LOOP]] ]
99 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[LSR_IV1]], 1
100 ; CHECK-NEXT: [[DEC_1]] = add nsw i32 [[IV_1]], -1
101 ; CHECK-NEXT: call void @use(i64 [[TMP0]])
102 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], -1
103 ; CHECK-NEXT: [[TMP:%.*]] = trunc i64 [[LSR_IV_NEXT]] to i32
104 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add nsw i64 [[LSR_IV1]], 1
105 ; CHECK-NEXT: [[CMP6_1:%.*]] = icmp sgt i32 [[TMP]], 0
106 ; CHECK-NEXT: br i1 [[CMP6_1]], label [[LOOP]], label [[EXIT:%.*]]
108 ; CHECK-NEXT: call void @use(i64 [[LSR_IV_NEXT]])
109 ; CHECK-NEXT: call void @use(i64 [[LSR_IV_NEXT2]])
110 ; CHECK-NEXT: [[TMP3:%.*]] = urem i32 [[DEC_1]], 53
111 ; CHECK-NEXT: ret i32 [[TMP3]]
117 %iv.1 = phi i32 [ 1, %entry ], [ %dec.1, %loop ]
118 %iv.2 = phi i64 [ 0, %entry ], [ %inc.1, %loop ]
119 %inc.1 = add nsw i64 %iv.2, 1
120 %dec.1 = add nsw i32 %iv.1, -1
121 call void @use(i64 %iv.2)
122 %cmp6.1 = icmp sgt i32 %iv.1, 0
123 br i1 %cmp6.1, label %loop, label %exit
126 %iv.1.ext = zext i32 %iv.1 to i64
127 call void @use(i64 %iv.1.ext)
128 call void @use(i64 %iv.2)
129 %rem = urem i32 %dec.1, 53
133 define i64 @test_normalization_failure_in_any_extend(ptr %i, i64 %i1, i8 %i25) {
134 ; CHECK-LABEL: define i64 @test_normalization_failure_in_any_extend
135 ; CHECK-SAME: (ptr [[I:%.*]], i64 [[I1:%.*]], i8 [[I25:%.*]]) {
137 ; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
138 ; CHECK: loop.1.header:
139 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_1_NEXT:%.*]], [[LOOP_1_LATCH:%.*]] ]
140 ; CHECK-NEXT: [[IV_2:%.*]] = phi i64 [ [[I1]], [[ENTRY]] ], [ [[TMP1:%.*]], [[LOOP_1_LATCH]] ]
141 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[IV_2]], 2
142 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
144 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[LOOP_2]] ], [ 2, [[LOOP_1_HEADER]] ]
145 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i32 [[LSR_IV]], -1
146 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[LSR_IV_NEXT]], 0
147 ; CHECK-NEXT: br i1 [[C_1]], label [[LOOP_2]], label [[LOOP_3_PREHEADER:%.*]]
148 ; CHECK: loop.3.preheader:
149 ; CHECK-NEXT: br label [[LOOP_3:%.*]]
151 ; CHECK-NEXT: [[LSR_IV5:%.*]] = phi i64 [ 0, [[LOOP_3_PREHEADER]] ], [ [[LSR_IV_NEXT6:%.*]], [[LOOP_3]] ]
152 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ 2, [[LOOP_3_PREHEADER]] ], [ [[LSR_IV_NEXT2:%.*]], [[LOOP_3]] ]
153 ; CHECK-NEXT: [[IV_5:%.*]] = phi i32 [ [[IV_5_NEXT:%.*]], [[LOOP_3]] ], [ 1, [[LOOP_3_PREHEADER]] ]
154 ; CHECK-NEXT: [[IV_5_NEXT]] = add nsw i32 [[IV_5]], -1
155 ; CHECK-NEXT: [[LSR:%.*]] = trunc i32 [[IV_5_NEXT]] to i8
156 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add nsw i64 [[LSR_IV1]], -1
157 ; CHECK-NEXT: [[TMP:%.*]] = trunc i64 [[LSR_IV_NEXT2]] to i32
158 ; CHECK-NEXT: [[LSR_IV_NEXT6]] = add nsw i64 [[LSR_IV5]], -1
159 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i32 [[TMP]], 0
160 ; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_3]], label [[LOOP_1_LATCH]]
161 ; CHECK: loop.1.latch:
162 ; CHECK-NEXT: [[IV_1_NEXT]] = add nuw nsw i32 [[IV_1]], 1
163 ; CHECK-NEXT: [[TMP1]] = sub i64 [[TMP0]], [[LSR_IV_NEXT6]]
164 ; CHECK-NEXT: [[C_3:%.*]] = icmp eq i32 [[IV_1_NEXT]], 8
165 ; CHECK-NEXT: br i1 [[C_3]], label [[EXIT:%.*]], label [[LOOP_1_HEADER]]
167 ; CHECK-NEXT: call void @use.i32(i32 [[IV_5_NEXT]])
168 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[IV_2]], 1
169 ; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], [[LSR_IV_NEXT6]]
170 ; CHECK-NEXT: call void @use(i64 [[TMP3]])
171 ; CHECK-NEXT: call void @use(i64 [[LSR_IV_NEXT2]])
172 ; CHECK-NEXT: [[TMP4:%.*]] = udiv i32 [[IV_5_NEXT]], 53
173 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i8
174 ; CHECK-NEXT: [[TMP6:%.*]] = mul i8 [[TMP5]], 53
175 ; CHECK-NEXT: [[TMP7:%.*]] = sub i8 [[LSR]], [[TMP6]]
176 ; CHECK-NEXT: call void @use.i8(i8 [[TMP7]])
177 ; CHECK-NEXT: [[I26:%.*]] = xor i8 [[I25]], 5
178 ; CHECK-NEXT: [[I27:%.*]] = zext i8 [[I26]] to i64
179 ; CHECK-NEXT: ret i64 [[I27]]
182 br label %loop.1.header
185 %iv.1 = phi i32 [ 0, %entry ], [ %iv.1.next, %loop.1.latch ]
186 %iv.2 = phi i64 [ %i1, %entry ], [ %iv.6.next, %loop.1.latch ]
190 %iv.3 = phi i32 [ 1, %loop.1.header ], [ %iv.3.next, %loop.2 ]
191 %iv.4 = phi i64 [ %iv.2, %loop.1.header ], [ %iv.4.next, %loop.2 ]
192 %iv.4.next = add nsw i64 %iv.4, 1
193 %iv.3.next = add nsw i32 %iv.3, -1
194 %c.1 = icmp sgt i32 %iv.3, 0
195 br i1 %c.1, label %loop.2, label %loop.3
198 %iv.5 = phi i32 [ 1, %loop.2 ], [ %iv.5.next, %loop.3 ]
199 %iv.6 = phi i64 [ %iv.4.next, %loop.2 ], [ %iv.6.next, %loop.3 ]
200 %iv.6.next = add nsw i64 %iv.6, 1
201 %iv.5.next = add nsw i32 %iv.5, -1
202 %c.2 = icmp sgt i32 %iv.5, 0
203 br i1 %c.2, label %loop.3, label %loop.1.latch
206 %iv.1.next = add nuw nsw i32 %iv.1, 1
207 %c.3 = icmp eq i32 %iv.1.next, 8
208 br i1 %c.3, label %exit, label %loop.1.header
211 call void @use.i32(i32 %iv.5.next)
212 %i21 = zext i32 %iv.5 to i64
213 call void @use(i64 %iv.6)
214 call void @use(i64 %i21)
215 %i22 = urem i32 %iv.5.next, 53
216 %i23 = trunc i32 %i22 to i8
217 call void @use.i8(i8 %i23)
218 %i26 = xor i8 %i25, 5
219 %i27 = zext i8 %i26 to i64