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
5 ;; The llc runs above are just to ensure it doesn't blow up upon
6 ;; seeing an is_constant intrinsic.
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)
14 declare i1 @llvm.is.constant.a2i64([2 x i64] %a)
15 declare i1 @llvm.is.constant.p0i64(i64* %a)
17 ;; Basic test that optimization folds away the is.constant when given
19 define i1 @test_constant() #0 {
20 ; CHECK-LABEL: @test_constant(
21 ; CHECK-NOT: llvm.is.constant
23 %y = call i1 @llvm.is.constant.i32(i32 44)
27 ;; And test that the intrinsic sticks around when given a
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)
36 ;; Ensure that nested is.constants fold.
37 define i32 @test_nested() #0 {
38 ; CHECK-LABEL: @test_nested(
39 ; CHECK-NOT: llvm.is.constant
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
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))
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)))
66 define i1 @test_various_types(i256 %int, float %float, <2 x i64> %vec, {i32, i32} %struct, [2 x i64] %arr, i64* %ptr) #0 {
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)
79 %v5 = call i1 @llvm.is.constant.a2i64([2 x i64] %arr)
80 %v6 = call i1 @llvm.is.constant.p0i64(i64* %ptr)
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})
86 %c5 = call i1 @llvm.is.constant.a2i64([2 x i64] [i64 -1, i64 32])
87 %c6 = call i1 @llvm.is.constant.p0i64(i64* inttoptr (i32 42 to i64*))
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
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>,
109 {i32, i32} {i32 -1, i32 55}, [2 x i64] [i64 -1, i64 55],
110 i64* inttoptr (i64 42 to i64*))
114 attributes #0 = { nounwind uwtable }