1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
4 declare void @llvm.assume(i1)
5 declare i8 @llvm.umin(i8, i8)
6 declare i8 @llvm.umax(i8, i8)
7 declare i8 @llvm.smin(i8, i8)
8 declare i8 @llvm.smax(i8, i8)
10 ; If we don't know anything about the arguments, we can't do anything.
12 define i8 @test0(i8 %x, i8 %y) {
13 ; CHECK-LABEL: @test0(
14 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
15 ; CHECK-NEXT: ret i8 [[R]]
17 %r = call i8 @llvm.umin(i8 %x, i8 %y)
20 define i8 @test1(i8 %x, i8 %y) {
21 ; CHECK-LABEL: @test1(
22 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
23 ; CHECK-NEXT: ret i8 [[R]]
25 %r = call i8 @llvm.umax(i8 %x, i8 %y)
28 define i8 @test2(i8 %x, i8 %y) {
29 ; CHECK-LABEL: @test2(
30 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
31 ; CHECK-NEXT: ret i8 [[R]]
33 %r = call i8 @llvm.smin(i8 %x, i8 %y)
36 define i8 @test3(i8 %x, i8 %y) {
37 ; CHECK-LABEL: @test3(
38 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
39 ; CHECK-NEXT: ret i8 [[R]]
41 %r = call i8 @llvm.smax(i8 %x, i8 %y)
45 ; However, if we do know the ranges of arguments, we sometimes can tell that either one is always picked.
47 define i8 @test4(i8 %x) {
48 ; CHECK-LABEL: @test4(
49 ; CHECK-NEXT: [[LIM:%.*]] = icmp ule i8 [[X:%.*]], 43
50 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
51 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 42)
52 ; CHECK-NEXT: ret i8 [[R]]
54 %lim = icmp ule i8 %x, 43
55 call void @llvm.assume(i1 %lim)
56 %r = call i8 @llvm.umin(i8 %x, i8 42)
59 define i8 @test5(i8 %x) {
60 ; CHECK-LABEL: @test5(
61 ; CHECK-NEXT: [[LIM:%.*]] = icmp ule i8 [[X:%.*]], 42
62 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
63 ; CHECK-NEXT: ret i8 [[X]]
65 %lim = icmp ule i8 %x, 42
66 call void @llvm.assume(i1 %lim)
67 %r = call i8 @llvm.umin(i8 %x, i8 42)
70 define i8 @test6(i8 %x) {
71 ; CHECK-LABEL: @test6(
72 ; CHECK-NEXT: [[LIM:%.*]] = icmp uge i8 [[X:%.*]], 42
73 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
74 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 42)
75 ; CHECK-NEXT: ret i8 42
77 %lim = icmp uge i8 %x, 42
78 call void @llvm.assume(i1 %lim)
79 %r = call i8 @llvm.umin(i8 %x, i8 42)
82 define i8 @test7(i8 %x) {
83 ; CHECK-LABEL: @test7(
84 ; CHECK-NEXT: [[LIM:%.*]] = icmp uge i8 [[X:%.*]], 41
85 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
86 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 42)
87 ; CHECK-NEXT: ret i8 [[R]]
89 %lim = icmp uge i8 %x, 41
90 call void @llvm.assume(i1 %lim)
91 %r = call i8 @llvm.umin(i8 %x, i8 42)
95 define i8 @test8(i8 %x) {
96 ; CHECK-LABEL: @test8(
97 ; CHECK-NEXT: [[LIM:%.*]] = icmp uge i8 [[X:%.*]], 41
98 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
99 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 42)
100 ; CHECK-NEXT: ret i8 [[R]]
102 %lim = icmp uge i8 %x, 41
103 call void @llvm.assume(i1 %lim)
104 %r = call i8 @llvm.umax(i8 %x, i8 42)
107 define i8 @test9(i8 %x) {
108 ; CHECK-LABEL: @test9(
109 ; CHECK-NEXT: [[LIM:%.*]] = icmp uge i8 [[X:%.*]], 42
110 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
111 ; CHECK-NEXT: ret i8 [[X]]
113 %lim = icmp uge i8 %x, 42
114 call void @llvm.assume(i1 %lim)
115 %r = call i8 @llvm.umax(i8 %x, i8 42)
118 define i8 @test10(i8 %x) {
119 ; CHECK-LABEL: @test10(
120 ; CHECK-NEXT: [[LIM:%.*]] = icmp ule i8 [[X:%.*]], 42
121 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
122 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 42)
123 ; CHECK-NEXT: ret i8 42
125 %lim = icmp ule i8 %x, 42
126 call void @llvm.assume(i1 %lim)
127 %r = call i8 @llvm.umax(i8 %x, i8 42)
130 define i8 @test11(i8 %x) {
131 ; CHECK-LABEL: @test11(
132 ; CHECK-NEXT: [[LIM:%.*]] = icmp ule i8 [[X:%.*]], 43
133 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
134 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[X]], i8 42)
135 ; CHECK-NEXT: ret i8 [[R]]
137 %lim = icmp ule i8 %x, 43
138 call void @llvm.assume(i1 %lim)
139 %r = call i8 @llvm.umax(i8 %x, i8 42)
143 define i8 @test12(i8 %x) {
144 ; CHECK-LABEL: @test12(
145 ; CHECK-NEXT: [[LIM:%.*]] = icmp sle i8 [[X:%.*]], 43
146 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
147 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 42)
148 ; CHECK-NEXT: ret i8 [[R]]
150 %lim = icmp sle i8 %x, 43
151 call void @llvm.assume(i1 %lim)
152 %r = call i8 @llvm.smin(i8 %x, i8 42)
155 define i8 @test13(i8 %x) {
156 ; CHECK-LABEL: @test13(
157 ; CHECK-NEXT: [[LIM:%.*]] = icmp sle i8 [[X:%.*]], 42
158 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
159 ; CHECK-NEXT: ret i8 [[X]]
161 %lim = icmp sle i8 %x, 42
162 call void @llvm.assume(i1 %lim)
163 %r = call i8 @llvm.smin(i8 %x, i8 42)
166 define i8 @test14(i8 %x) {
167 ; CHECK-LABEL: @test14(
168 ; CHECK-NEXT: [[LIM:%.*]] = icmp sge i8 [[X:%.*]], 42
169 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
170 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 42)
171 ; CHECK-NEXT: ret i8 42
173 %lim = icmp sge i8 %x, 42
174 call void @llvm.assume(i1 %lim)
175 %r = call i8 @llvm.smin(i8 %x, i8 42)
178 define i8 @test15(i8 %x) {
179 ; CHECK-LABEL: @test15(
180 ; CHECK-NEXT: [[LIM:%.*]] = icmp sge i8 [[X:%.*]], 41
181 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
182 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 42)
183 ; CHECK-NEXT: ret i8 [[R]]
185 %lim = icmp sge i8 %x, 41
186 call void @llvm.assume(i1 %lim)
187 %r = call i8 @llvm.smin(i8 %x, i8 42)
191 define i8 @test16(i8 %x) {
192 ; CHECK-LABEL: @test16(
193 ; CHECK-NEXT: [[LIM:%.*]] = icmp sge i8 [[X:%.*]], 41
194 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
195 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 42)
196 ; CHECK-NEXT: ret i8 [[R]]
198 %lim = icmp sge i8 %x, 41
199 call void @llvm.assume(i1 %lim)
200 %r = call i8 @llvm.smax(i8 %x, i8 42)
203 define i8 @test17(i8 %x) {
204 ; CHECK-LABEL: @test17(
205 ; CHECK-NEXT: [[LIM:%.*]] = icmp sge i8 [[X:%.*]], 42
206 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
207 ; CHECK-NEXT: ret i8 [[X]]
209 %lim = icmp sge i8 %x, 42
210 call void @llvm.assume(i1 %lim)
211 %r = call i8 @llvm.smax(i8 %x, i8 42)
214 define i8 @test18(i8 %x) {
215 ; CHECK-LABEL: @test18(
216 ; CHECK-NEXT: [[LIM:%.*]] = icmp sle i8 [[X:%.*]], 42
217 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
218 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 42)
219 ; CHECK-NEXT: ret i8 42
221 %lim = icmp sle i8 %x, 42
222 call void @llvm.assume(i1 %lim)
223 %r = call i8 @llvm.smax(i8 %x, i8 42)
226 define i8 @test19(i8 %x) {
227 ; CHECK-LABEL: @test19(
228 ; CHECK-NEXT: [[LIM:%.*]] = icmp sle i8 [[X:%.*]], 43
229 ; CHECK-NEXT: call void @llvm.assume(i1 [[LIM]])
230 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 42)
231 ; CHECK-NEXT: ret i8 [[R]]
233 %lim = icmp sle i8 %x, 43
234 call void @llvm.assume(i1 %lim)
235 %r = call i8 @llvm.smax(i8 %x, i8 42)