James Y Knight | 72f76bf | 2018-11-07 15:24:12 +0000 | [diff] [blame] | 1 | ; RUN: opt -O2 -S < %s | FileCheck %s |
| 2 | ; RUN: llc -o /dev/null 2>&1 < %s |
| 3 | ; RUN: llc -O0 -o /dev/null 2>&1 < %s |
| 4 | |
| 5 | ;; The llc runs above are just to ensure it doesn't blow up upon |
| 6 | ;; seeing an is_constant intrinsic. |
| 7 | |
| 8 | declare i1 @llvm.is.constant.i32(i32 %a) |
| 9 | declare i1 @llvm.is.constant.i64(i64 %a) |
| 10 | declare i1 @llvm.is.constant.i256(i256 %a) |
| 11 | declare i1 @llvm.is.constant.v2i64(<2 x i64> %a) |
| 12 | declare i1 @llvm.is.constant.f32(float %a) |
| 13 | declare i1 @llvm.is.constant.sl_i32i32s({i32, i32} %a) |
James Y Knight | 5fbc72f | 2018-11-07 17:01:47 +0000 | [diff] [blame] | 14 | declare i1 @llvm.is.constant.a2i64([2 x i64] %a) |
James Y Knight | 72f76bf | 2018-11-07 15:24:12 +0000 | [diff] [blame] | 15 | declare i1 @llvm.is.constant.p0i64(i64* %a) |
| 16 | |
| 17 | ;; Basic test that optimization folds away the is.constant when given |
| 18 | ;; a constant. |
| 19 | define i1 @test_constant() #0 { |
| 20 | ; CHECK-LABEL: @test_constant( |
| 21 | ; CHECK-NOT: llvm.is.constant |
| 22 | ; CHECK: ret i1 true |
| 23 | %y = call i1 @llvm.is.constant.i32(i32 44) |
| 24 | ret i1 %y |
| 25 | } |
| 26 | |
| 27 | ;; And test that the intrinsic sticks around when given a |
| 28 | ;; non-constant. |
| 29 | define i1 @test_nonconstant(i32 %x) #0 { |
| 30 | ; CHECK-LABEL: @test_nonconstant( |
| 31 | ; CHECK: @llvm.is.constant |
| 32 | %y = call i1 @llvm.is.constant.i32(i32 %x) |
| 33 | ret i1 %y |
| 34 | } |
| 35 | |
| 36 | ;; Ensure that nested is.constants fold. |
| 37 | define i32 @test_nested() #0 { |
| 38 | ; CHECK-LABEL: @test_nested( |
| 39 | ; CHECK-NOT: llvm.is.constant |
| 40 | ; CHECK: ret i32 13 |
| 41 | %val1 = call i1 @llvm.is.constant.i32(i32 27) |
| 42 | %val2 = zext i1 %val1 to i32 |
| 43 | %val3 = add i32 %val2, 12 |
| 44 | %1 = call i1 @llvm.is.constant.i32(i32 %val3) |
| 45 | %2 = zext i1 %1 to i32 |
| 46 | %3 = add i32 %2, 12 |
| 47 | ret i32 %3 |
| 48 | } |
| 49 | |
| 50 | @G = global [2 x i64] zeroinitializer |
| 51 | define i1 @test_global() #0 { |
| 52 | ; CHECK-LABEL: @test_global( |
| 53 | ; CHECK: llvm.is.constant |
| 54 | %ret = call i1 @llvm.is.constant.p0i64(i64* getelementptr ([2 x i64], [2 x i64]* @G, i32 0, i32 0)) |
| 55 | ret i1 %ret |
| 56 | } |
| 57 | |
| 58 | define i1 @test_diff() #0 { |
| 59 | ; CHECK-LABEL: @test_diff( |
| 60 | %ret = call i1 @llvm.is.constant.i64(i64 sub ( |
| 61 | i64 ptrtoint (i64* getelementptr inbounds ([2 x i64], [2 x i64]* @G, i64 0, i64 1) to i64), |
| 62 | i64 ptrtoint ([2 x i64]* @G to i64))) |
| 63 | ret i1 %ret |
| 64 | } |
| 65 | |
James Y Knight | 5fbc72f | 2018-11-07 17:01:47 +0000 | [diff] [blame] | 66 | define i1 @test_various_types(i256 %int, float %float, <2 x i64> %vec, {i32, i32} %struct, [2 x i64] %arr, i64* %ptr) #0 { |
James Y Knight | 72f76bf | 2018-11-07 15:24:12 +0000 | [diff] [blame] | 67 | ; CHECK-LABEL: @test_various_types( |
| 68 | ; CHECK: llvm.is.constant |
| 69 | ; CHECK: llvm.is.constant |
| 70 | ; CHECK: llvm.is.constant |
| 71 | ; CHECK: llvm.is.constant |
| 72 | ; CHECK: llvm.is.constant |
| 73 | ; CHECK: llvm.is.constant |
| 74 | ; CHECK-NOT: llvm.is.constant |
| 75 | %v1 = call i1 @llvm.is.constant.i256(i256 %int) |
| 76 | %v2 = call i1 @llvm.is.constant.f32(float %float) |
| 77 | %v3 = call i1 @llvm.is.constant.v2i64(<2 x i64> %vec) |
| 78 | %v4 = call i1 @llvm.is.constant.sl_i32i32s({i32, i32} %struct) |
James Y Knight | 5fbc72f | 2018-11-07 17:01:47 +0000 | [diff] [blame] | 79 | %v5 = call i1 @llvm.is.constant.a2i64([2 x i64] %arr) |
James Y Knight | 72f76bf | 2018-11-07 15:24:12 +0000 | [diff] [blame] | 80 | %v6 = call i1 @llvm.is.constant.p0i64(i64* %ptr) |
| 81 | |
| 82 | %c1 = call i1 @llvm.is.constant.i256(i256 -1) |
| 83 | %c2 = call i1 @llvm.is.constant.f32(float 17.0) |
| 84 | %c3 = call i1 @llvm.is.constant.v2i64(<2 x i64> <i64 -1, i64 44>) |
| 85 | %c4 = call i1 @llvm.is.constant.sl_i32i32s({i32, i32} {i32 -1, i32 32}) |
James Y Knight | 5fbc72f | 2018-11-07 17:01:47 +0000 | [diff] [blame] | 86 | %c5 = call i1 @llvm.is.constant.a2i64([2 x i64] [i64 -1, i64 32]) |
James Y Knight | 72f76bf | 2018-11-07 15:24:12 +0000 | [diff] [blame] | 87 | %c6 = call i1 @llvm.is.constant.p0i64(i64* inttoptr (i32 42 to i64*)) |
| 88 | |
| 89 | %x1 = add i1 %v1, %c1 |
| 90 | %x2 = add i1 %v2, %c2 |
| 91 | %x3 = add i1 %v3, %c3 |
| 92 | %x4 = add i1 %v4, %c4 |
| 93 | %x5 = add i1 %v5, %c5 |
| 94 | %x6 = add i1 %v6, %c6 |
| 95 | |
| 96 | %res2 = add i1 %x1, %x2 |
| 97 | %res3 = add i1 %res2, %x3 |
| 98 | %res4 = add i1 %res3, %x4 |
| 99 | %res5 = add i1 %res4, %x5 |
| 100 | %res6 = add i1 %res5, %x6 |
| 101 | |
| 102 | ret i1 %res6 |
| 103 | } |
| 104 | |
| 105 | define i1 @test_various_types2() #0 { |
| 106 | ; CHECK-LABEL: @test_various_types2( |
| 107 | ; CHECK: ret i1 false |
| 108 | %r = call i1 @test_various_types(i256 -1, float 22.0, <2 x i64> <i64 -1, i64 44>, |
James Y Knight | 5fbc72f | 2018-11-07 17:01:47 +0000 | [diff] [blame] | 109 | {i32, i32} {i32 -1, i32 55}, [2 x i64] [i64 -1, i64 55], |
James Y Knight | 72f76bf | 2018-11-07 15:24:12 +0000 | [diff] [blame] | 110 | i64* inttoptr (i64 42 to i64*)) |
| 111 | ret i1 %r |
| 112 | } |
| 113 | |
| 114 | attributes #0 = { nounwind uwtable } |