1 ; RUN: opt -passes=lower-constant-intrinsics -S < %s | FileCheck %s
3 ;; Ensure that an unfoldable is.constant gets lowered reasonably in
4 ;; optimized codegen, in particular, that the "true" branch is
7 ;; Also ensure that any unfoldable objectsize is resolved in order.
9 ;; CHECK-NOT: tail call i32 @subfun_1()
10 ;; CHECK: tail call i32 @subfun_2()
11 ;; CHECK-NOT: tail call i32 @subfun_1()
13 declare i1 @llvm.is.constant.i32(i32 %a) nounwind readnone
14 declare i1 @llvm.is.constant.i64(i64 %a) nounwind readnone
15 declare i1 @llvm.is.constant.i256(i256 %a) nounwind readnone
16 declare i1 @llvm.is.constant.v2i64(<2 x i64> %a) nounwind readnone
17 declare i1 @llvm.is.constant.f32(float %a) nounwind readnone
18 declare i1 @llvm.is.constant.sl_i32i32s({i32, i32} %a) nounwind readnone
19 declare i1 @llvm.is.constant.a2i64([2 x i64] %a) nounwind readnone
20 declare i1 @llvm.is.constant.p0(ptr %a) nounwind readnone
22 declare i64 @llvm.objectsize.i64.p0(ptr, i1, i1, i1) nounwind readnone
24 declare i32 @subfun_1()
25 declare i32 @subfun_2()
27 define i32 @test_branch(i32 %in) nounwind {
28 %v = call i1 @llvm.is.constant.i32(i32 %in)
29 br i1 %v, label %True, label %False
32 %call1 = tail call i32 @subfun_1()
36 %call2 = tail call i32 @subfun_2()
40 ;; llvm.objectsize is another tricky case which gets folded to -1 very
41 ;; late in the game. We'd like to ensure that llvm.is.constant of
42 ;; llvm.objectsize is true.
43 define i1 @test_objectsize(ptr %obj) nounwind {
44 ;; CHECK-LABEL: test_objectsize
45 ;; CHECK-NOT: llvm.objectsize
46 ;; CHECK-NOT: llvm.is.constant
48 %os = call i64 @llvm.objectsize.i64.p0(ptr %obj, i1 false, i1 false, i1 false)
50 %v = call i1 @llvm.is.constant.i64(i64 %os1)
54 @test_phi_a = dso_local global i32 0, align 4
55 declare dso_local i32 @test_phi_b(...)
57 ; Function Attrs: nounwind uwtable
58 define dso_local i32 @test_phi() {
60 %0 = load i32, ptr @test_phi_a, align 4
61 %1 = tail call i1 @llvm.is.constant.i32(i32 %0)
62 br i1 %1, label %cond.end, label %cond.false
64 cond.false: ; preds = %entry
65 %call = tail call i32 @test_phi_b() #3
66 %.pre = load i32, ptr @test_phi_a, align 4
69 cond.end: ; preds = %entry, %cond.false
70 %2 = phi i32 [ %.pre, %cond.false ], [ %0, %entry ]
71 %cond = phi i32 [ %call, %cond.false ], [ 1, %entry ]
72 %cmp = icmp eq i32 %cond, %2
73 br i1 %cmp, label %cond.true1, label %cond.end4
75 cond.true1: ; preds = %cond.end
76 %call2 = tail call i32 @test_phi_b() #3
79 cond.end4: ; preds = %cond.end, %cond.true1
83 define i1 @test_various_types(i256 %int, float %float, <2 x i64> %vec, {i32, i32} %struct, [2 x i64] %arr, ptr %ptr) #0 {
84 ; CHECK-LABEL: @test_various_types(
85 ; CHECK-NOT: llvm.is.constant
86 %v1 = call i1 @llvm.is.constant.i256(i256 %int)
87 %v2 = call i1 @llvm.is.constant.f32(float %float)
88 %v3 = call i1 @llvm.is.constant.v2i64(<2 x i64> %vec)
89 %v4 = call i1 @llvm.is.constant.sl_i32i32s({i32, i32} %struct)
90 %v5 = call i1 @llvm.is.constant.a2i64([2 x i64] %arr)
91 %v6 = call i1 @llvm.is.constant.p0(ptr %ptr)
93 %c1 = call i1 @llvm.is.constant.i256(i256 -1)
94 %c2 = call i1 @llvm.is.constant.f32(float 17.0)
95 %c3 = call i1 @llvm.is.constant.v2i64(<2 x i64> <i64 -1, i64 44>)
96 %c4 = call i1 @llvm.is.constant.sl_i32i32s({i32, i32} {i32 -1, i32 32})
97 %c5 = call i1 @llvm.is.constant.a2i64([2 x i64] [i64 -1, i64 32])
98 %c6 = call i1 @llvm.is.constant.p0(ptr inttoptr (i32 42 to ptr))
100 %x1 = add i1 %v1, %c1
101 %x2 = add i1 %v2, %c2
102 %x3 = add i1 %v3, %c3
103 %x4 = add i1 %v4, %c4
104 %x5 = add i1 %v5, %c5
105 %x6 = add i1 %v6, %c6
107 %res2 = add i1 %x1, %x2
108 %res3 = add i1 %res2, %x3
109 %res4 = add i1 %res3, %x4
110 %res5 = add i1 %res4, %x5
111 %res6 = add i1 %res5, %x6
116 @real_mode_blob_end = external dso_local global [0 x i8], align 1
117 define i1 @global_array() {
118 ; CHECK-LABEL: @global_array(
119 ; CHECK-NEXT: ret i1 false
120 %1 = call i1 @llvm.is.constant.i64(i64 ptrtoint (ptr @real_mode_blob_end to i64))