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: [[TMP0:%.*]] = udiv i32 [[LSR_IV_NEXT2]], 9
26 ; CHECK-NEXT: [[TMP1:%.*]] = mul nuw i32 [[TMP0]], 9
27 ; CHECK-NEXT: [[TMP2:%.*]] = sub i32 [[LSR_IV_NEXT2]], [[TMP1]]
28 ; CHECK-NEXT: ret i32 [[TMP2]]
34 %iv = phi i8 [ 1, %entry ], [ %iv.next, %loop ]
35 %iv.next = add nsw i8 %iv, -1
36 %ext = zext i8 %iv to i64
37 call void @use(i64 %ext)
38 %cmp2 = icmp sgt i8 %iv.next, -1
39 br i1 %cmp2, label %loop, label %exit
42 %sext = sext i8 %iv.next to i32
43 %rem = urem i32 %sext, 9
47 define i64 @test_pr58039() {
48 ; CHECK-LABEL: define i64 @test_pr58039() {
50 ; CHECK-NEXT: br label [[LOOP:%.*]]
52 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[LOOP]] ], [ -4294967213, [[ENTRY:%.*]] ]
53 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
54 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[IV]] to i32
55 ; CHECK-NEXT: call void @use.i32(i32 [[TMP2]])
56 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
57 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], 4294967295
58 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
60 ; CHECK-NEXT: [[TMP0:%.*]] = udiv i64 [[LSR_IV_NEXT]], 12
61 ; CHECK-NEXT: [[TMP1:%.*]] = mul nuw nsw i64 [[TMP0]], 12
62 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 4294967221
63 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[TMP2]], [[IV_NEXT]]
64 ; CHECK-NEXT: [[TMP:%.*]] = trunc i64 [[TMP3]] to i32
65 ; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i32 [[TMP]], 32
66 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[CMP3]], i64 0, i64 [[IV_NEXT]]
67 ; CHECK-NEXT: ret i64 [[SPEC_SELECT]]
73 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
74 %iv1 = phi i32 [ -74, %entry ], [ %iv1.next, %loop ]
75 %iv2 = phi i32 [ 83, %entry ], [ %iv2.next, %loop ]
76 %iv3 = phi i32 [ 0, %entry ], [ %iv3.next, %loop ]
77 call void @use.i32(i32 %iv3)
78 %iv.next = add nuw nsw i64 %iv, 1
79 %iv1.next = add nuw nsw i32 %iv1, 1
80 %iv2.next = add nsw i32 %iv2, -1
81 %iv3.next = add nuw nsw i32 %iv3, 1
82 br i1 false, label %loop, label %exit
85 %i2 = udiv i32 %iv2.next, 12
86 %i5 = mul nuw nsw i32 %i2, 12
87 %i6 = add i32 %iv1, %i5
88 %cmp3 = icmp ult i32 %i6, 32
89 %spec.select = select i1 %cmp3, i64 0, i64 %iv.next
93 define i32 @test_pr62852() {
94 ; CHECK-LABEL: define i32 @test_pr62852() {
96 ; CHECK-NEXT: br label [[LOOP:%.*]]
98 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ [[LSR_IV_NEXT2:%.*]], [[LOOP]] ], [ -1, [[ENTRY:%.*]] ]
99 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[LOOP]] ], [ 2, [[ENTRY]] ]
100 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[DEC_1:%.*]], [[LOOP]] ]
101 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[LSR_IV1]], 1
102 ; CHECK-NEXT: [[DEC_1]] = add nsw i32 [[IV_1]], -1
103 ; CHECK-NEXT: call void @use(i64 [[TMP0]])
104 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], -1
105 ; CHECK-NEXT: [[TMP:%.*]] = trunc i64 [[LSR_IV_NEXT]] to i32
106 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add nsw i64 [[LSR_IV1]], 1
107 ; CHECK-NEXT: [[CMP6_1:%.*]] = icmp sgt i32 [[TMP]], 0
108 ; CHECK-NEXT: br i1 [[CMP6_1]], label [[LOOP]], label [[EXIT:%.*]]
110 ; CHECK-NEXT: call void @use(i64 [[LSR_IV_NEXT]])
111 ; CHECK-NEXT: call void @use(i64 [[LSR_IV_NEXT2]])
112 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 [[DEC_1]], 53
113 ; CHECK-NEXT: [[TMP2:%.*]] = mul nuw i32 [[TMP1]], 53
114 ; CHECK-NEXT: [[TMP3:%.*]] = sub i32 [[DEC_1]], [[TMP2]]
115 ; CHECK-NEXT: ret i32 [[TMP3]]
121 %iv.1 = phi i32 [ 1, %entry ], [ %dec.1, %loop ]
122 %iv.2 = phi i64 [ 0, %entry ], [ %inc.1, %loop ]
123 %inc.1 = add nsw i64 %iv.2, 1
124 %dec.1 = add nsw i32 %iv.1, -1
125 call void @use(i64 %iv.2)
126 %cmp6.1 = icmp sgt i32 %iv.1, 0
127 br i1 %cmp6.1, label %loop, label %exit
130 %iv.1.ext = zext i32 %iv.1 to i64
131 call void @use(i64 %iv.1.ext)
132 call void @use(i64 %iv.2)
133 %rem = urem i32 %dec.1, 53
137 define i64 @test_normalization_failure_in_any_extend(ptr %i, i64 %i1, i8 %i25) {
138 ; CHECK-LABEL: define i64 @test_normalization_failure_in_any_extend
139 ; CHECK-SAME: (ptr [[I:%.*]], i64 [[I1:%.*]], i8 [[I25:%.*]]) {
141 ; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
142 ; CHECK: loop.1.header:
143 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_1_NEXT:%.*]], [[LOOP_1_LATCH:%.*]] ]
144 ; CHECK-NEXT: [[IV_2:%.*]] = phi i64 [ [[I1]], [[ENTRY]] ], [ [[TMP1:%.*]], [[LOOP_1_LATCH]] ]
145 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[IV_2]], 2
146 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
148 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[LOOP_2]] ], [ 2, [[LOOP_1_HEADER]] ]
149 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i32 [[LSR_IV]], -1
150 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[LSR_IV_NEXT]], 0
151 ; CHECK-NEXT: br i1 [[C_1]], label [[LOOP_2]], label [[LOOP_3_PREHEADER:%.*]]
152 ; CHECK: loop.3.preheader:
153 ; CHECK-NEXT: br label [[LOOP_3:%.*]]
155 ; CHECK-NEXT: [[LSR_IV5:%.*]] = phi i64 [ 0, [[LOOP_3_PREHEADER]] ], [ [[LSR_IV_NEXT6:%.*]], [[LOOP_3]] ]
156 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ 2, [[LOOP_3_PREHEADER]] ], [ [[LSR_IV_NEXT2:%.*]], [[LOOP_3]] ]
157 ; CHECK-NEXT: [[IV_5:%.*]] = phi i32 [ [[IV_5_NEXT:%.*]], [[LOOP_3]] ], [ 1, [[LOOP_3_PREHEADER]] ]
158 ; CHECK-NEXT: [[IV_5_NEXT]] = add nsw i32 [[IV_5]], -1
159 ; CHECK-NEXT: [[LSR:%.*]] = trunc i32 [[IV_5_NEXT]] to i8
160 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add nsw i64 [[LSR_IV1]], -1
161 ; CHECK-NEXT: [[TMP:%.*]] = trunc i64 [[LSR_IV_NEXT2]] to i32
162 ; CHECK-NEXT: [[LSR_IV_NEXT6]] = add nsw i64 [[LSR_IV5]], -1
163 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i32 [[TMP]], 0
164 ; CHECK-NEXT: br i1 [[C_2]], label [[LOOP_3]], label [[LOOP_1_LATCH]]
165 ; CHECK: loop.1.latch:
166 ; CHECK-NEXT: [[IV_1_NEXT]] = add nuw nsw i32 [[IV_1]], 1
167 ; CHECK-NEXT: [[TMP1]] = sub i64 [[TMP0]], [[LSR_IV_NEXT6]]
168 ; CHECK-NEXT: [[C_3:%.*]] = icmp eq i32 [[IV_1_NEXT]], 8
169 ; CHECK-NEXT: br i1 [[C_3]], label [[EXIT:%.*]], label [[LOOP_1_HEADER]]
171 ; CHECK-NEXT: call void @use.i32(i32 [[IV_5_NEXT]])
172 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[IV_2]], 1
173 ; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], [[LSR_IV_NEXT6]]
174 ; CHECK-NEXT: call void @use(i64 [[TMP3]])
175 ; CHECK-NEXT: call void @use(i64 [[LSR_IV_NEXT2]])
176 ; CHECK-NEXT: [[TMP4:%.*]] = udiv i32 [[IV_5_NEXT]], 53
177 ; CHECK-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i8
178 ; CHECK-NEXT: [[TMP6:%.*]] = mul i8 [[TMP5]], 53
179 ; CHECK-NEXT: [[TMP7:%.*]] = sub i8 [[LSR]], [[TMP6]]
180 ; CHECK-NEXT: call void @use.i8(i8 [[TMP7]])
181 ; CHECK-NEXT: [[I26:%.*]] = xor i8 [[I25]], 5
182 ; CHECK-NEXT: [[I27:%.*]] = zext i8 [[I26]] to i64
183 ; CHECK-NEXT: ret i64 [[I27]]
186 br label %loop.1.header
189 %iv.1 = phi i32 [ 0, %entry ], [ %iv.1.next, %loop.1.latch ]
190 %iv.2 = phi i64 [ %i1, %entry ], [ %iv.6.next, %loop.1.latch ]
194 %iv.3 = phi i32 [ 1, %loop.1.header ], [ %iv.3.next, %loop.2 ]
195 %iv.4 = phi i64 [ %iv.2, %loop.1.header ], [ %iv.4.next, %loop.2 ]
196 %iv.4.next = add nsw i64 %iv.4, 1
197 %iv.3.next = add nsw i32 %iv.3, -1
198 %c.1 = icmp sgt i32 %iv.3, 0
199 br i1 %c.1, label %loop.2, label %loop.3
202 %iv.5 = phi i32 [ 1, %loop.2 ], [ %iv.5.next, %loop.3 ]
203 %iv.6 = phi i64 [ %iv.4.next, %loop.2 ], [ %iv.6.next, %loop.3 ]
204 %iv.6.next = add nsw i64 %iv.6, 1
205 %iv.5.next = add nsw i32 %iv.5, -1
206 %c.2 = icmp sgt i32 %iv.5, 0
207 br i1 %c.2, label %loop.3, label %loop.1.latch
210 %iv.1.next = add nuw nsw i32 %iv.1, 1
211 %c.3 = icmp eq i32 %iv.1.next, 8
212 br i1 %c.3, label %exit, label %loop.1.header
215 call void @use.i32(i32 %iv.5.next)
216 %i21 = zext i32 %iv.5 to i64
217 call void @use(i64 %iv.6)
218 call void @use(i64 %i21)
219 %i22 = urem i32 %iv.5.next, 53
220 %i23 = trunc i32 %i22 to i8
221 call void @use.i8(i8 %i23)
222 %i26 = xor i8 %i25, 5
223 %i27 = zext i8 %i26 to i64