1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
3 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
5 declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b)
6 declare {i8, i1} @llvm.sadd.with.overflow.i8(i8 %a, i8 %b)
7 declare {i8, i1} @llvm.usub.with.overflow.i8(i8 %a, i8 %b)
8 declare {i8, i1} @llvm.ssub.with.overflow.i8(i8 %a, i8 %b)
9 declare {i8, i1} @llvm.umul.with.overflow.i8(i8 %a, i8 %b)
10 declare {i8, i1} @llvm.smul.with.overflow.i8(i8 %a, i8 %b)
12 define i1 @test_uadd1() {
13 ; CHECK-LABEL: @test_uadd1(
14 ; CHECK-NEXT: ret i1 true
16 %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 254, i8 3)
17 %overflow = extractvalue {i8, i1} %x, 1
21 define i8 @test_uadd2() {
22 ; CHECK-LABEL: @test_uadd2(
23 ; CHECK-NEXT: ret i8 42
25 %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 254, i8 44)
26 %result = extractvalue {i8, i1} %x, 0
30 define {i8, i1} @test_uadd3(i8 %v) {
31 ; CHECK-LABEL: @test_uadd3(
32 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
34 %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 undef)
38 define {i8, i1} @test_uadd4(i8 %v) {
39 ; CHECK-LABEL: @test_uadd4(
40 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
42 %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 undef, i8 %v)
46 define i1 @test_sadd1() {
47 ; CHECK-LABEL: @test_sadd1(
48 ; CHECK-NEXT: ret i1 true
50 %x = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 126, i8 3)
51 %overflow = extractvalue {i8, i1} %x, 1
55 define i8 @test_sadd2() {
56 ; CHECK-LABEL: @test_sadd2(
57 ; CHECK-NEXT: ret i8 -86
59 %x = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 126, i8 44)
60 %result = extractvalue {i8, i1} %x, 0
64 define {i8, i1} @test_sadd3(i8 %v) {
65 ; CHECK-LABEL: @test_sadd3(
66 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
68 %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v, i8 undef)
72 define {i8, i1} @test_sadd4(i8 %v) {
73 ; CHECK-LABEL: @test_sadd4(
74 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
76 %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 undef, i8 %v)
80 define {i8, i1} @test_usub1(i8 %V) {
81 ; CHECK-LABEL: @test_usub1(
82 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
84 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 %V)
88 define {i8, i1} @test_usub2(i8 %V) {
89 ; CHECK-LABEL: @test_usub2(
90 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
92 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 undef)
96 define {i8, i1} @test_usub3(i8 %V) {
97 ; CHECK-LABEL: @test_usub3(
98 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
100 %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 undef, i8 %V)
104 define {i8, i1} @test_ssub1(i8 %V) {
105 ; CHECK-LABEL: @test_ssub1(
106 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
108 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 %V)
112 define {i8, i1} @test_ssub2(i8 %V) {
113 ; CHECK-LABEL: @test_ssub2(
114 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
116 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 undef)
120 define {i8, i1} @test_ssub3(i8 %V) {
121 ; CHECK-LABEL: @test_ssub3(
122 ; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
124 %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 undef, i8 %V)
128 define {i8, i1} @test_umul1(i8 %V) {
129 ; CHECK-LABEL: @test_umul1(
130 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
132 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 0)
136 define {i8, i1} @test_umul2(i8 %V) {
137 ; CHECK-LABEL: @test_umul2(
138 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
140 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 undef)
144 define {i8, i1} @test_umul3(i8 %V) {
145 ; CHECK-LABEL: @test_umul3(
146 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
148 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 0, i8 %V)
152 define {i8, i1} @test_umul4(i8 %V) {
153 ; CHECK-LABEL: @test_umul4(
154 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
156 %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 undef, i8 %V)
160 define {i8, i1} @test_smul1(i8 %V) {
161 ; CHECK-LABEL: @test_smul1(
162 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
164 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 0)
168 define {i8, i1} @test_smul2(i8 %V) {
169 ; CHECK-LABEL: @test_smul2(
170 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
172 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 undef)
176 define {i8, i1} @test_smul3(i8 %V) {
177 ; CHECK-LABEL: @test_smul3(
178 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
180 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 0, i8 %V)
184 define {i8, i1} @test_smul4(i8 %V) {
185 ; CHECK-LABEL: @test_smul4(
186 ; CHECK-NEXT: ret { i8, i1 } zeroinitializer
188 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 undef, i8 %V)
192 ; Test a non-intrinsic that we know about as a library call.
193 declare float @fabs(float %x)
195 define float @test_fabs_libcall() {
196 ; CHECK-LABEL: @test_fabs_libcall(
197 ; CHECK-NEXT: [[X:%.*]] = call float @fabs(float -4.200000e+01)
198 ; CHECK-NEXT: ret float 4.200000e+01
201 %x = call float @fabs(float -42.0)
202 ; This is still a real function call, so instsimplify won't nuke it -- other
203 ; passes have to do that.
209 declare float @llvm.fabs.f32(float) nounwind readnone
210 declare float @llvm.floor.f32(float) nounwind readnone
211 declare float @llvm.ceil.f32(float) nounwind readnone
212 declare float @llvm.trunc.f32(float) nounwind readnone
213 declare float @llvm.rint.f32(float) nounwind readnone
214 declare float @llvm.nearbyint.f32(float) nounwind readnone
215 declare float @llvm.canonicalize.f32(float) nounwind readnone
217 ; Test idempotent intrinsics
218 define float @test_idempotence(float %a) {
219 ; CHECK-LABEL: @test_idempotence(
220 ; CHECK-NEXT: [[A0:%.*]] = call float @llvm.fabs.f32(float [[A:%.*]])
221 ; CHECK-NEXT: [[B0:%.*]] = call float @llvm.floor.f32(float [[A]])
222 ; CHECK-NEXT: [[C0:%.*]] = call float @llvm.ceil.f32(float [[A]])
223 ; CHECK-NEXT: [[D0:%.*]] = call float @llvm.trunc.f32(float [[A]])
224 ; CHECK-NEXT: [[E0:%.*]] = call float @llvm.rint.f32(float [[A]])
225 ; CHECK-NEXT: [[F0:%.*]] = call float @llvm.nearbyint.f32(float [[A]])
226 ; CHECK-NEXT: [[G0:%.*]] = call float @llvm.canonicalize.f32(float [[A]])
227 ; CHECK-NEXT: [[R0:%.*]] = fadd float [[A0]], [[B0]]
228 ; CHECK-NEXT: [[R1:%.*]] = fadd float [[R0]], [[C0]]
229 ; CHECK-NEXT: [[R2:%.*]] = fadd float [[R1]], [[D0]]
230 ; CHECK-NEXT: [[R3:%.*]] = fadd float [[R2]], [[E0]]
231 ; CHECK-NEXT: [[R4:%.*]] = fadd float [[R3]], [[F0]]
232 ; CHECK-NEXT: [[R5:%.*]] = fadd float [[R4]], [[G0]]
233 ; CHECK-NEXT: ret float [[R5]]
236 %a0 = call float @llvm.fabs.f32(float %a)
237 %a1 = call float @llvm.fabs.f32(float %a0)
239 %b0 = call float @llvm.floor.f32(float %a)
240 %b1 = call float @llvm.floor.f32(float %b0)
242 %c0 = call float @llvm.ceil.f32(float %a)
243 %c1 = call float @llvm.ceil.f32(float %c0)
245 %d0 = call float @llvm.trunc.f32(float %a)
246 %d1 = call float @llvm.trunc.f32(float %d0)
248 %e0 = call float @llvm.rint.f32(float %a)
249 %e1 = call float @llvm.rint.f32(float %e0)
251 %f0 = call float @llvm.nearbyint.f32(float %a)
252 %f1 = call float @llvm.nearbyint.f32(float %f0)
254 %g0 = call float @llvm.canonicalize.f32(float %a)
255 %g1 = call float @llvm.canonicalize.f32(float %g0)
257 %r0 = fadd float %a1, %b1
258 %r1 = fadd float %r0, %c1
259 %r2 = fadd float %r1, %d1
260 %r3 = fadd float %r2, %e1
261 %r4 = fadd float %r3, %f1
262 %r5 = fadd float %r4, %g1
267 define i8* @operator_new() {
268 ; CHECK-LABEL: @operator_new(
270 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @_Znwm(i64 8)
271 ; CHECK-NEXT: br i1 false, label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]]
272 ; CHECK: cast.notnull:
273 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4
274 ; CHECK-NEXT: br label [[CAST_END]]
276 ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ]
277 ; CHECK-NEXT: ret i8* [[CAST_RESULT]]
280 %call = tail call noalias i8* @_Znwm(i64 8)
281 %cmp = icmp eq i8* %call, null
282 br i1 %cmp, label %cast.end, label %cast.notnull
284 cast.notnull: ; preds = %entry
285 %add.ptr = getelementptr inbounds i8, i8* %call, i64 4
288 cast.end: ; preds = %cast.notnull, %entry
289 %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
294 declare nonnull noalias i8* @_Znwm(i64)
296 %"struct.std::nothrow_t" = type { i8 }
297 @_ZSt7nothrow = external global %"struct.std::nothrow_t"
299 define i8* @operator_new_nothrow_t() {
300 ; CHECK-LABEL: @operator_new_nothrow_t(
302 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @_ZnamRKSt9nothrow_t(i64 8, %"struct.std::nothrow_t"* @_ZSt7nothrow)
303 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null
304 ; CHECK-NEXT: br i1 [[CMP]], label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]]
305 ; CHECK: cast.notnull:
306 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4
307 ; CHECK-NEXT: br label [[CAST_END]]
309 ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ]
310 ; CHECK-NEXT: ret i8* [[CAST_RESULT]]
313 %call = tail call noalias i8* @_ZnamRKSt9nothrow_t(i64 8, %"struct.std::nothrow_t"* @_ZSt7nothrow)
314 %cmp = icmp eq i8* %call, null
315 br i1 %cmp, label %cast.end, label %cast.notnull
317 cast.notnull: ; preds = %entry
318 %add.ptr = getelementptr inbounds i8, i8* %call, i64 4
321 cast.end: ; preds = %cast.notnull, %entry
322 %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
327 declare i8* @_ZnamRKSt9nothrow_t(i64, %"struct.std::nothrow_t"*) nounwind
329 define i8* @malloc_can_return_null() {
330 ; CHECK-LABEL: @malloc_can_return_null(
332 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 8)
333 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null
334 ; CHECK-NEXT: br i1 [[CMP]], label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]]
335 ; CHECK: cast.notnull:
336 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4
337 ; CHECK-NEXT: br label [[CAST_END]]
339 ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ]
340 ; CHECK-NEXT: ret i8* [[CAST_RESULT]]
343 %call = tail call noalias i8* @malloc(i64 8)
344 %cmp = icmp eq i8* %call, null
345 br i1 %cmp, label %cast.end, label %cast.notnull
347 cast.notnull: ; preds = %entry
348 %add.ptr = getelementptr inbounds i8, i8* %call, i64 4
351 cast.end: ; preds = %cast.notnull, %entry
352 %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ]
357 define i32 @call_null() {
358 ; CHECK-LABEL: @call_null(
360 ; CHECK-NEXT: [[CALL:%.*]] = call i32 null()
361 ; CHECK-NEXT: ret i32 undef
364 %call = call i32 null()
368 define i32 @call_undef() {
369 ; CHECK-LABEL: @call_undef(
371 ; CHECK-NEXT: [[CALL:%.*]] = call i32 undef()
372 ; CHECK-NEXT: ret i32 undef
375 %call = call i32 undef()
379 @GV = private constant [8 x i32] [i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49]
381 define <8 x i32> @partial_masked_load() {
382 ; CHECK-LABEL: @partial_masked_load(
383 ; CHECK-NEXT: ret <8 x i32> <i32 undef, i32 undef, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47>
385 %masked.load = call <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>* bitcast (i32* getelementptr ([8 x i32], [8 x i32]* @GV, i64 0, i64 -2) to <8 x i32>*), i32 4, <8 x i1> <i1 false, i1 false, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef)
386 ret <8 x i32> %masked.load
389 define <8 x i32> @masked_load_undef_mask(<8 x i32>* %V) {
390 ; CHECK-LABEL: @masked_load_undef_mask(
391 ; CHECK-NEXT: ret <8 x i32> <i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0>
393 %masked.load = call <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>* %V, i32 4, <8 x i1> undef, <8 x i32> <i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0>)
394 ret <8 x i32> %masked.load
397 declare noalias i8* @malloc(i64)
399 declare <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>*, i32, <8 x i1>, <8 x i32>)
401 declare double @llvm.powi.f64(double, i32)
402 declare <2 x double> @llvm.powi.v2f64(<2 x double>, i32)
404 define double @constant_fold_powi() {
405 ; CHECK-LABEL: @constant_fold_powi(
406 ; CHECK-NEXT: ret double 9.000000e+00
408 %t0 = call double @llvm.powi.f64(double 3.00000e+00, i32 2)
412 define <2 x double> @constant_fold_powi_vec() {
413 ; CHECK-LABEL: @constant_fold_powi_vec(
414 ; CHECK-NEXT: ret <2 x double> <double 9.000000e+00, double 2.500000e+01>
416 %t0 = call <2 x double> @llvm.powi.v2f64(<2 x double> <double 3.00000e+00, double 5.00000e+00>, i32 2)
420 declare i8 @llvm.fshl.i8(i8, i8, i8)
421 declare i9 @llvm.fshr.i9(i9, i9, i9)
422 declare <2 x i7> @llvm.fshl.v2i7(<2 x i7>, <2 x i7>, <2 x i7>)
423 declare <2 x i8> @llvm.fshr.v2i8(<2 x i8>, <2 x i8>, <2 x i8>)
425 define i8 @fshl_no_shift(i8 %x, i8 %y) {
426 ; CHECK-LABEL: @fshl_no_shift(
427 ; CHECK-NEXT: ret i8 [[X:%.*]]
429 %z = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 0)
433 define i9 @fshr_no_shift(i9 %x, i9 %y) {
434 ; CHECK-LABEL: @fshr_no_shift(
435 ; CHECK-NEXT: ret i9 [[Y:%.*]]
437 %z = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 0)
441 define i8 @fshl_no_shift_modulo_bitwidth(i8 %x, i8 %y) {
442 ; CHECK-LABEL: @fshl_no_shift_modulo_bitwidth(
443 ; CHECK-NEXT: ret i8 [[X:%.*]]
445 %z = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 40)
449 define i9 @fshr_no_shift_modulo_bitwidth(i9 %x, i9 %y) {
450 ; CHECK-LABEL: @fshr_no_shift_modulo_bitwidth(
451 ; CHECK-NEXT: ret i9 [[Y:%.*]]
453 %z = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 189)
457 define <2 x i7> @fshl_no_shift_modulo_bitwidth_splat(<2 x i7> %x, <2 x i7> %y) {
458 ; CHECK-LABEL: @fshl_no_shift_modulo_bitwidth_splat(
459 ; CHECK-NEXT: ret <2 x i7> [[X:%.*]]
461 %z = call <2 x i7> @llvm.fshl.v2i7(<2 x i7> %x, <2 x i7> %y, <2 x i7> <i7 21, i7 21>)
465 define <2 x i8> @fshr_no_shift_modulo_bitwidth_splat(<2 x i8> %x, <2 x i8> %y) {
466 ; CHECK-LABEL: @fshr_no_shift_modulo_bitwidth_splat(
467 ; CHECK-NEXT: ret <2 x i8> [[Y:%.*]]
469 %z = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> %x, <2 x i8> %y, <2 x i8> <i8 72, i8 72>)
473 ; If y is poison, eliminating the guard is not safe.
475 define i8 @fshl_zero_shift_guard(i8 %x, i8 %y, i8 %sh) {
476 ; CHECK-LABEL: @fshl_zero_shift_guard(
477 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[SH:%.*]], 0
478 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[SH]])
479 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[F]]
480 ; CHECK-NEXT: ret i8 [[S]]
482 %c = icmp eq i8 %sh, 0
483 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
484 %s = select i1 %c, i8 %x, i8 %f
488 ; If y is poison, eliminating the guard is not safe.
490 define i8 @fshl_zero_shift_guard_swapped(i8 %x, i8 %y, i8 %sh) {
491 ; CHECK-LABEL: @fshl_zero_shift_guard_swapped(
492 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[SH:%.*]], 0
493 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[SH]])
494 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[F]], i8 [[X]]
495 ; CHECK-NEXT: ret i8 [[S]]
497 %c = icmp ne i8 %sh, 0
498 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
499 %s = select i1 %c, i8 %f, i8 %x
503 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
505 define i8 @fshl_zero_shift_guard_inverted(i8 %x, i8 %y, i8 %sh) {
506 ; CHECK-LABEL: @fshl_zero_shift_guard_inverted(
507 ; CHECK-NEXT: ret i8 [[X:%.*]]
509 %c = icmp eq i8 %sh, 0
510 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
511 %s = select i1 %c, i8 %f, i8 %x
515 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
517 define i8 @fshl_zero_shift_guard_inverted_swapped(i8 %x, i8 %y, i8 %sh) {
518 ; CHECK-LABEL: @fshl_zero_shift_guard_inverted_swapped(
519 ; CHECK-NEXT: ret i8 [[X:%.*]]
521 %c = icmp ne i8 %sh, 0
522 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
523 %s = select i1 %c, i8 %x, i8 %f
527 ; If x is poison, eliminating the guard is not safe.
529 define i9 @fshr_zero_shift_guard(i9 %x, i9 %y, i9 %sh) {
530 ; CHECK-LABEL: @fshr_zero_shift_guard(
531 ; CHECK-NEXT: [[C:%.*]] = icmp eq i9 [[SH:%.*]], 0
532 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[Y:%.*]], i9 [[SH]])
533 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i9 [[Y]], i9 [[F]]
534 ; CHECK-NEXT: ret i9 [[S]]
536 %c = icmp eq i9 %sh, 0
537 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
538 %s = select i1 %c, i9 %y, i9 %f
542 ; If x is poison, eliminating the guard is not safe.
544 define i9 @fshr_zero_shift_guard_swapped(i9 %x, i9 %y, i9 %sh) {
545 ; CHECK-LABEL: @fshr_zero_shift_guard_swapped(
546 ; CHECK-NEXT: [[C:%.*]] = icmp ne i9 [[SH:%.*]], 0
547 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[Y:%.*]], i9 [[SH]])
548 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i9 [[F]], i9 [[Y]]
549 ; CHECK-NEXT: ret i9 [[S]]
551 %c = icmp ne i9 %sh, 0
552 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
553 %s = select i1 %c, i9 %f, i9 %y
557 ; When the shift amount is 0, fshr returns its 2nd parameter (y), so everything is deleted.
559 define i9 @fshr_zero_shift_guard_inverted(i9 %x, i9 %y, i9 %sh) {
560 ; CHECK-LABEL: @fshr_zero_shift_guard_inverted(
561 ; CHECK-NEXT: ret i9 [[Y:%.*]]
563 %c = icmp eq i9 %sh, 0
564 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
565 %s = select i1 %c, i9 %f, i9 %y
569 ; When the shift amount is 0, fshr returns its 2nd parameter (y), so everything is deleted.
571 define i9 @fshr_zero_shift_guard_inverted_swapped(i9 %x, i9 %y, i9 %sh) {
572 ; CHECK-LABEL: @fshr_zero_shift_guard_inverted_swapped(
573 ; CHECK-NEXT: ret i9 [[Y:%.*]]
575 %c = icmp ne i9 %sh, 0
576 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 %sh)
577 %s = select i1 %c, i9 %y, i9 %f
581 ; When the shift amount is 0, fshl returns its 1st parameter (x), so the guard is not needed.
583 define i8 @rotl_zero_shift_guard(i8 %x, i8 %sh) {
584 ; CHECK-LABEL: @rotl_zero_shift_guard(
585 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[SH:%.*]])
586 ; CHECK-NEXT: ret i8 [[F]]
588 %c = icmp eq i8 %sh, 0
589 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
590 %s = select i1 %c, i8 %x, i8 %f
594 ; When the shift amount is 0, fshl returns its 1st parameter (x), so the guard is not needed.
596 define i8 @rotl_zero_shift_guard_swapped(i8 %x, i8 %sh) {
597 ; CHECK-LABEL: @rotl_zero_shift_guard_swapped(
598 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[SH:%.*]])
599 ; CHECK-NEXT: ret i8 [[F]]
601 %c = icmp ne i8 %sh, 0
602 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
603 %s = select i1 %c, i8 %f, i8 %x
607 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
609 define i8 @rotl_zero_shift_guard_inverted(i8 %x, i8 %sh) {
610 ; CHECK-LABEL: @rotl_zero_shift_guard_inverted(
611 ; CHECK-NEXT: ret i8 [[X:%.*]]
613 %c = icmp eq i8 %sh, 0
614 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
615 %s = select i1 %c, i8 %f, i8 %x
619 ; When the shift amount is 0, fshl returns its 1st parameter (x), so everything is deleted.
621 define i8 @rotl_zero_shift_guard_inverted_swapped(i8 %x, i8 %sh) {
622 ; CHECK-LABEL: @rotl_zero_shift_guard_inverted_swapped(
623 ; CHECK-NEXT: ret i8 [[X:%.*]]
625 %c = icmp ne i8 %sh, 0
626 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %sh)
627 %s = select i1 %c, i8 %x, i8 %f
631 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so the guard is not needed.
633 define i9 @rotr_zero_shift_guard(i9 %x, i9 %sh) {
634 ; CHECK-LABEL: @rotr_zero_shift_guard(
635 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[X]], i9 [[SH:%.*]])
636 ; CHECK-NEXT: ret i9 [[F]]
638 %c = icmp eq i9 %sh, 0
639 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
640 %s = select i1 %c, i9 %x, i9 %f
644 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so the guard is not needed.
646 define i9 @rotr_zero_shift_guard_swapped(i9 %x, i9 %sh) {
647 ; CHECK-LABEL: @rotr_zero_shift_guard_swapped(
648 ; CHECK-NEXT: [[F:%.*]] = call i9 @llvm.fshr.i9(i9 [[X:%.*]], i9 [[X]], i9 [[SH:%.*]])
649 ; CHECK-NEXT: ret i9 [[F]]
651 %c = icmp ne i9 %sh, 0
652 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
653 %s = select i1 %c, i9 %f, i9 %x
657 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so everything is deleted.
659 define i9 @rotr_zero_shift_guard_inverted(i9 %x, i9 %sh) {
660 ; CHECK-LABEL: @rotr_zero_shift_guard_inverted(
661 ; CHECK-NEXT: ret i9 [[X:%.*]]
663 %c = icmp eq i9 %sh, 0
664 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
665 %s = select i1 %c, i9 %f, i9 %x
669 ; When the shift amount is 0, fshr returns its 2nd parameter (x), so everything is deleted.
671 define i9 @rotr_zero_shift_guard_inverted_swapped(i9 %x, i9 %sh) {
672 ; CHECK-LABEL: @rotr_zero_shift_guard_inverted_swapped(
673 ; CHECK-NEXT: ret i9 [[X:%.*]]
675 %c = icmp ne i9 %sh, 0
676 %f = call i9 @llvm.fshr.i9(i9 %x, i9 %x, i9 %sh)
677 %s = select i1 %c, i9 %x, i9 %f
681 ; Negative test - make sure we're matching the correct parameter of fshl.
683 define i8 @fshl_zero_shift_guard_wrong_select_op(i8 %x, i8 %y, i8 %sh) {
684 ; CHECK-LABEL: @fshl_zero_shift_guard_wrong_select_op(
685 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[SH:%.*]], 0
686 ; CHECK-NEXT: [[F:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[SH]])
687 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[Y]], i8 [[F]]
688 ; CHECK-NEXT: ret i8 [[S]]
690 %c = icmp eq i8 %sh, 0
691 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %sh)
692 %s = select i1 %c, i8 %y, i8 %f
696 ; Vector types work too.
698 define <2 x i8> @rotr_zero_shift_guard_splat(<2 x i8> %x, <2 x i8> %sh) {
699 ; CHECK-LABEL: @rotr_zero_shift_guard_splat(
700 ; CHECK-NEXT: [[F:%.*]] = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[X]], <2 x i8> [[SH:%.*]])
701 ; CHECK-NEXT: ret <2 x i8> [[F]]
703 %c = icmp eq <2 x i8> %sh, zeroinitializer
704 %f = call <2 x i8> @llvm.fshr.v2i8(<2 x i8> %x, <2 x i8> %x, <2 x i8> %sh)
705 %s = select <2 x i1> %c, <2 x i8> %x, <2 x i8> %f
709 ; If first two operands of funnel shift are undef, the result is undef
711 define i8 @fshl_ops_undef(i8 %shamt) {
712 ; CHECK-LABEL: @fshl_ops_undef(
713 ; CHECK-NEXT: ret i8 undef
715 %r = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 %shamt)
719 define i9 @fshr_ops_undef(i9 %shamt) {
720 ; CHECK-LABEL: @fshr_ops_undef(
721 ; CHECK-NEXT: ret i9 undef
723 %r = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 %shamt)
727 ; If shift amount is undef, treat it as zero, returning operand 0 or 1
729 define i8 @fshl_shift_undef(i8 %x, i8 %y) {
730 ; CHECK-LABEL: @fshl_shift_undef(
731 ; CHECK-NEXT: ret i8 [[X:%.*]]
733 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 undef)
737 define i9 @fshr_shift_undef(i9 %x, i9 %y) {
738 ; CHECK-LABEL: @fshr_shift_undef(
739 ; CHECK-NEXT: ret i9 [[Y:%.*]]
741 %r = call i9 @llvm.fshr.i9(i9 %x, i9 %y, i9 undef)
745 declare double @llvm.fma.f64(double,double,double)
746 declare double @llvm.fmuladd.f64(double,double,double)
748 define double @fma_undef_op0(double %x, double %y) {
749 ; CHECK-LABEL: @fma_undef_op0(
750 ; CHECK-NEXT: ret double 0x7FF8000000000000
752 %r = call double @llvm.fma.f64(double undef, double %x, double %y)
756 define double @fma_undef_op1(double %x, double %y) {
757 ; CHECK-LABEL: @fma_undef_op1(
758 ; CHECK-NEXT: ret double 0x7FF8000000000000
760 %r = call double @llvm.fma.f64(double %x, double undef, double %y)
764 define double @fma_undef_op2(double %x, double %y) {
765 ; CHECK-LABEL: @fma_undef_op2(
766 ; CHECK-NEXT: ret double 0x7FF8000000000000
768 %r = call double @llvm.fma.f64(double %x, double %y, double undef)
772 define double @fmuladd_undef_op0(double %x, double %y) {
773 ; CHECK-LABEL: @fmuladd_undef_op0(
774 ; CHECK-NEXT: ret double 0x7FF8000000000000
776 %r = call double @llvm.fmuladd.f64(double undef, double %x, double %y)
780 define double @fmuladd_undef_op1(double %x, double %y) {
781 ; CHECK-LABEL: @fmuladd_undef_op1(
782 ; CHECK-NEXT: ret double 0x7FF8000000000000
784 %r = call double @llvm.fmuladd.f64(double %x, double undef, double %y)
788 define double @fmuladd_undef_op2(double %x, double %y) {
789 ; CHECK-LABEL: @fmuladd_undef_op2(
790 ; CHECK-NEXT: ret double 0x7FF8000000000000
792 %r = call double @llvm.fmuladd.f64(double %x, double %y, double undef)
796 define double @fma_nan_op0(double %x, double %y) {
797 ; CHECK-LABEL: @fma_nan_op0(
798 ; CHECK-NEXT: ret double 0x7FF8000000000000
800 %r = call double @llvm.fma.f64(double 0x7ff8000000000000, double %x, double %y)
804 define double @fma_nan_op1(double %x, double %y) {
805 ; CHECK-LABEL: @fma_nan_op1(
806 ; CHECK-NEXT: ret double 0x7FF8000000000001
808 %r = call double @llvm.fma.f64(double %x, double 0x7ff8000000000001, double %y)
812 define double @fma_nan_op2(double %x, double %y) {
813 ; CHECK-LABEL: @fma_nan_op2(
814 ; CHECK-NEXT: ret double 0x7FF8000000000002
816 %r = call double @llvm.fma.f64(double %x, double %y, double 0x7ff8000000000002)
820 define double @fmuladd_nan_op0_op1(double %x) {
821 ; CHECK-LABEL: @fmuladd_nan_op0_op1(
822 ; CHECK-NEXT: ret double 0x7FF8000000001234
824 %r = call double @llvm.fmuladd.f64(double 0x7ff8000000001234, double 0x7ff800000000dead, double %x)
828 define double @fmuladd_nan_op0_op2(double %x) {
829 ; CHECK-LABEL: @fmuladd_nan_op0_op2(
830 ; CHECK-NEXT: ret double 0x7FF8000000005678
832 %r = call double @llvm.fmuladd.f64(double 0x7ff8000000005678, double %x, double 0x7ff800000000dead)
836 define double @fmuladd_nan_op1_op2(double %x) {
837 ; CHECK-LABEL: @fmuladd_nan_op1_op2(
838 ; CHECK-NEXT: ret double 0x7FF80000AAAAAAAA
840 %r = call double @llvm.fmuladd.f64(double %x, double 0x7ff80000aaaaaaaa, double 0x7ff800000000dead)
844 define double @fma_nan_multiplicand_inf_zero(double %x) {
845 ; CHECK-LABEL: @fma_nan_multiplicand_inf_zero(
846 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double 0x7FF0000000000000, double 0.000000e+00, double [[X:%.*]])
847 ; CHECK-NEXT: ret double [[R]]
849 %r = call double @llvm.fma.f64(double 0x7ff0000000000000, double 0.0, double %x)
853 define double @fma_nan_multiplicand_zero_inf(double %x) {
854 ; CHECK-LABEL: @fma_nan_multiplicand_zero_inf(
855 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double 0.000000e+00, double 0x7FF0000000000000, double [[X:%.*]])
856 ; CHECK-NEXT: ret double [[R]]
858 %r = call double @llvm.fma.f64(double 0.0, double 0x7ff0000000000000, double %x)
862 define double @fma_nan_addend_inf_neginf(double %x, i32 %y) {
863 ; CHECK-LABEL: @fma_nan_addend_inf_neginf(
864 ; CHECK-NEXT: [[NOTNAN:%.*]] = uitofp i32 [[Y:%.*]] to double
865 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double 0x7FF0000000000000, double [[NOTNAN]], double 0xFFF0000000000000)
866 ; CHECK-NEXT: ret double [[R]]
868 %notnan = uitofp i32 %y to double
869 %r = call double @llvm.fma.f64(double 0x7ff0000000000000, double %notnan, double 0xfff0000000000000)
873 define double @fma_nan_addend_neginf_inf(double %x, i1 %y) {
874 ; CHECK-LABEL: @fma_nan_addend_neginf_inf(
875 ; CHECK-NEXT: [[NOTNAN:%.*]] = select i1 [[Y:%.*]], double 4.200000e+01, double -1.000000e-01
876 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fma.f64(double [[NOTNAN]], double 0xFFF0000000000000, double 0x7FF0000000000000)
877 ; CHECK-NEXT: ret double [[R]]
879 %notnan = select i1 %y, double 42.0, double -0.1
880 %r = call double @llvm.fma.f64(double %notnan, double 0xfff0000000000000, double 0x7ff0000000000000)
884 define double @fmuladd_nan_multiplicand_neginf_zero(double %x) {
885 ; CHECK-LABEL: @fmuladd_nan_multiplicand_neginf_zero(
886 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double 0xFFF0000000000000, double 0.000000e+00, double [[X:%.*]])
887 ; CHECK-NEXT: ret double [[R]]
889 %r = call double @llvm.fmuladd.f64(double 0xfff0000000000000, double 0.0, double %x)
893 define double @fmuladd_nan_multiplicand_negzero_inf(double %x) {
894 ; CHECK-LABEL: @fmuladd_nan_multiplicand_negzero_inf(
895 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double -0.000000e+00, double 0x7FF0000000000000, double [[X:%.*]])
896 ; CHECK-NEXT: ret double [[R]]
898 %r = call double @llvm.fmuladd.f64(double -0.0, double 0x7ff0000000000000, double %x)
902 define double @fmuladd_nan_addend_inf_neginf(double %x, i32 %y) {
903 ; CHECK-LABEL: @fmuladd_nan_addend_inf_neginf(
904 ; CHECK-NEXT: [[NOTNAN:%.*]] = sitofp i32 [[Y:%.*]] to double
905 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double 0x7FF0000000000000, double [[NOTNAN]], double 0xFFF0000000000000)
906 ; CHECK-NEXT: ret double [[R]]
908 %notnan = sitofp i32 %y to double
909 %r = call double @llvm.fmuladd.f64(double 0x7ff0000000000000, double %notnan, double 0xfff0000000000000)
913 define double @fmuladd_nan_addend_neginf_inf(double %x, i1 %y) {
914 ; CHECK-LABEL: @fmuladd_nan_addend_neginf_inf(
915 ; CHECK-NEXT: [[NOTNAN:%.*]] = select i1 [[Y:%.*]], double 4.200000e+01, double -1.000000e-01
916 ; CHECK-NEXT: [[R:%.*]] = call double @llvm.fmuladd.f64(double [[NOTNAN]], double 0xFFF0000000000000, double 0x7FF0000000000000)
917 ; CHECK-NEXT: ret double [[R]]
919 %notnan = select i1 %y, double 42.0, double -0.1
920 %r = call double @llvm.fmuladd.f64(double %notnan, double 0xfff0000000000000, double 0x7ff0000000000000)