1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
4 define i8 @test0(i8 %a) {
7 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[A:%.*]], 3
8 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
10 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i8 [[A]], 50
11 ; CHECK-NEXT: ret i8 [[MUL]]
13 ; CHECK-NEXT: ret i8 0
16 %cmp = icmp ult i8 %a, 3
17 br i1 %cmp, label %bb, label %exit
27 define i8 @test1(i8 %a) {
28 ; CHECK-LABEL: @test1(
30 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[A:%.*]], 4
31 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
33 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[A]], 50
34 ; CHECK-NEXT: ret i8 [[MUL]]
36 ; CHECK-NEXT: ret i8 0
39 %cmp = icmp ult i8 %a, 4
40 br i1 %cmp, label %bb, label %exit
50 define i8 @test2(i8 %a) {
51 ; CHECK-LABEL: @test2(
53 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[A:%.*]], 6
54 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
56 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[A]], 50
57 ; CHECK-NEXT: ret i8 [[MUL]]
59 ; CHECK-NEXT: ret i8 0
62 %cmp = icmp ult i8 %a, 6
63 br i1 %cmp, label %bb, label %exit
73 define i8 @test3(i8 %a) {
74 ; CHECK-LABEL: @test3(
76 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[A:%.*]], 7
77 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
79 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[A]], 50
80 ; CHECK-NEXT: ret i8 [[MUL]]
82 ; CHECK-NEXT: ret i8 0
85 %cmp = icmp ult i8 %a, 7
86 br i1 %cmp, label %bb, label %exit
96 define i8 @test4(i8 %a) {
97 ; CHECK-LABEL: @test4(
99 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A:%.*]], 3
100 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], -3
101 ; CHECK-NEXT: [[COND:%.*]] = and i1 [[CMP1]], [[CMP2]]
102 ; CHECK-NEXT: br i1 [[COND]], label [[BB:%.*]], label [[EXIT:%.*]]
104 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[A]], 50
105 ; CHECK-NEXT: ret i8 [[MUL]]
107 ; CHECK-NEXT: ret i8 0
110 %cmp1 = icmp slt i8 %a, 3
111 %cmp2 = icmp sgt i8 %a, -3
112 %cond = and i1 %cmp1, %cmp2
113 br i1 %cond, label %bb, label %exit
123 define i8 @test5(i8 %a) {
124 ; CHECK-LABEL: @test5(
126 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A:%.*]], 3
127 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], -4
128 ; CHECK-NEXT: [[COND:%.*]] = and i1 [[CMP1]], [[CMP2]]
129 ; CHECK-NEXT: br i1 [[COND]], label [[BB:%.*]], label [[EXIT:%.*]]
131 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[A]], 50
132 ; CHECK-NEXT: ret i8 [[MUL]]
134 ; CHECK-NEXT: ret i8 0
137 %cmp1 = icmp slt i8 %a, 3
138 %cmp2 = icmp sgt i8 %a, -4
139 %cond = and i1 %cmp1, %cmp2
140 br i1 %cond, label %bb, label %exit
150 define i8 @test6(i8 %a) {
151 ; CHECK-LABEL: @test6(
153 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A:%.*]], 4
154 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], -3
155 ; CHECK-NEXT: [[COND:%.*]] = and i1 [[CMP1]], [[CMP2]]
156 ; CHECK-NEXT: br i1 [[COND]], label [[BB:%.*]], label [[EXIT:%.*]]
158 ; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[A]], 50
159 ; CHECK-NEXT: ret i8 [[MUL]]
161 ; CHECK-NEXT: ret i8 0
164 %cmp1 = icmp slt i8 %a, 4
165 %cmp2 = icmp sgt i8 %a, -3
166 %cond = and i1 %cmp1, %cmp2
167 br i1 %cond, label %bb, label %exit
177 define i1 @nuw_range1(i8 %b) {
178 ; CHECK-LABEL: @nuw_range1(
180 ; CHECK-NEXT: [[C:%.*]] = add nuw nsw i8 [[B:%.*]], 1
181 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[C]], 4
182 ; CHECK-NEXT: ret i1 false
185 %c = add nuw nsw i8 %b, 1
186 %mul = mul nuw i8 %c, 4
187 %cmp = icmp eq i8 %mul, 0
191 define i1 @nuw_range2(i8 %b) {
192 ; CHECK-LABEL: @nuw_range2(
194 ; CHECK-NEXT: [[C:%.*]] = add nuw nsw i8 [[B:%.*]], 3
195 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[C]], 4
196 ; CHECK-NEXT: ret i1 false
199 %c = add nuw nsw i8 %b, 3
200 %mul = mul nuw i8 %c, 4
201 %cmp = icmp ult i8 %mul, 2
205 define i1 @nsw_range1(i8 %b) {
206 ; CHECK-LABEL: @nsw_range1(
208 ; CHECK-NEXT: [[C:%.*]] = add nuw nsw i8 [[B:%.*]], -3
209 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[C]], 4
210 ; CHECK-NEXT: ret i1 false
213 %c = add nuw nsw i8 %b, -3
214 %mul = mul nsw i8 %c, 4
215 %cmp = icmp slt i8 %c, %mul
219 define i1 @one_bit(i1 %a, i1 %b) {
220 ; CHECK-LABEL: @one_bit(
221 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i1 [[A:%.*]], [[B:%.*]]
222 ; CHECK-NEXT: ret i1 [[MUL]]
228 define i1 @test_mul_nuw_nsw_nneg(i32 %x, i32 range(i32 3, 2147483648) %y) {
229 ; CHECK-LABEL: @test_mul_nuw_nsw_nneg(
231 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[X:%.*]], [[Y:%.*]]
232 ; CHECK-NEXT: ret i1 true
235 %mul = mul nuw nsw i32 %x, %y
236 %cmp = icmp sgt i32 %mul, -1
240 define i1 @test_mul_nuw_nsw_nneg_complex(i32 %x, i32 noundef %y, i32 %z) {
241 ; CHECK-LABEL: @test_mul_nuw_nsw_nneg_complex(
243 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[Y:%.*]], 2
244 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[X:%.*]], 0
245 ; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[CMP2]], i32 3, i32 4
246 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[CMP1]], i32 [[Y]], i32 [[SEL1]]
247 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[X]], [[SEL2]]
248 ; CHECK-NEXT: ret i1 true
251 %cmp1 = icmp sgt i32 %y, 2
252 %cmp2 = icmp eq i32 %x, 0
253 %sel1 = select i1 %cmp2, i32 3, i32 4
254 %sel2 = select i1 %cmp1, i32 %y, i32 %sel1
255 %mul = mul nuw nsw i32 %x, %sel2
256 %cmp3 = icmp sgt i32 %mul, -1