1 ; RUN: opt -S -lowerbitsets < %s | FileCheck %s
2 ; RUN: opt -S -O3 < %s | FileCheck -check-prefix=CHECK-NODISCARD %s
4 target datalayout = "e-p:32:32"
6 ; CHECK: [[G:@[^ ]*]] = private constant { i32, [63 x i32], i32, [2 x i32] } { i32 1, [63 x i32] zeroinitializer, i32 3, [2 x i32] [i32 4, i32 5] }
8 @b = constant [63 x i32] zeroinitializer
10 @d = constant [2 x i32] [i32 4, i32 5]
12 ; Offset 0, 4 byte alignment
13 ; CHECK: @bitset1.bits = private constant [9 x i8] c"\03\00\00\00\00\00\00\00\04"
14 !0 = !{!"bitset1", i32* @a, i32 0}
15 ; CHECK-NODISCARD-DAG: !{!"bitset1", i32* @a, i32 0}
16 !1 = !{!"bitset1", [63 x i32]* @b, i32 0}
17 ; CHECK-NODISCARD-DAG: !{!"bitset1", [63 x i32]* @b, i32 0}
18 !2 = !{!"bitset1", [2 x i32]* @d, i32 4}
19 ; CHECK-NODISCARD-DAG: !{!"bitset1", [2 x i32]* @d, i32 4}
21 ; Offset 4, 4 byte alignment
22 ; CHECK: @bitset2.bits = private constant [8 x i8] c"\01\00\00\00\00\00\00\80"
23 !3 = !{!"bitset2", [63 x i32]* @b, i32 0}
24 ; CHECK-NODISCARD-DAG: !{!"bitset2", [63 x i32]* @b, i32 0}
25 !4 = !{!"bitset2", i32* @c, i32 0}
26 ; CHECK-NODISCARD-DAG: !{!"bitset2", i32* @c, i32 0}
28 ; Offset 0, 256 byte alignment
29 ; CHECK: @bitset3.bits = private constant [1 x i8] c"\03"
30 !5 = !{!"bitset3", i32* @a, i32 0}
31 ; CHECK-NODISCARD-DAG: !{!"bitset3", i32* @a, i32 0}
32 !6 = !{!"bitset3", i32* @c, i32 0}
33 ; CHECK-NODISCARD-DAG: !{!"bitset3", i32* @c, i32 0}
35 ; Entries whose second operand is null (the result of a global being DCE'd)
37 !7 = !{!"bitset2", null, i32 0}
39 !llvm.bitsets = !{ !0, !1, !2, !3, !4, !5, !6, !7 }
41 ; CHECK: @a = alias getelementptr inbounds ({ i32, [63 x i32], i32, [2 x i32] }* [[G]], i32 0, i32 0)
42 ; CHECK: @b = alias getelementptr inbounds ({ i32, [63 x i32], i32, [2 x i32] }* [[G]], i32 0, i32 1)
43 ; CHECK: @c = alias getelementptr inbounds ({ i32, [63 x i32], i32, [2 x i32] }* [[G]], i32 0, i32 2)
44 ; CHECK: @d = alias getelementptr inbounds ({ i32, [63 x i32], i32, [2 x i32] }* [[G]], i32 0, i32 3)
46 declare i1 @llvm.bitset.test(i8* %ptr, metadata %bitset) nounwind readnone
48 ; CHECK: @foo(i32* [[A0:%[^ ]*]])
49 define i1 @foo(i32* %p) {
50 ; CHECK-NOT: llvm.bitset.test
52 ; CHECK: [[R0:%[^ ]*]] = bitcast i32* [[A0]] to i8*
53 %pi8 = bitcast i32* %p to i8*
54 ; CHECK: [[R1:%[^ ]*]] = ptrtoint i8* [[R0]] to i32
55 ; CHECK: [[R2:%[^ ]*]] = sub i32 [[R1]], ptrtoint ({ i32, [63 x i32], i32, [2 x i32] }* [[G]] to i32)
56 ; CHECK: [[R3:%[^ ]*]] = lshr i32 [[R2]], 2
57 ; CHECK: [[R4:%[^ ]*]] = shl i32 [[R2]], 30
58 ; CHECK: [[R5:%[^ ]*]] = or i32 [[R3]], [[R4]]
59 ; CHECK: [[R6:%[^ ]*]] = icmp ult i32 [[R5]], 67
62 ; CHECK: [[R8:%[^ ]*]] = lshr i32 [[R5]], 5
63 ; CHECK: [[R9:%[^ ]*]] = getelementptr i32* bitcast ([9 x i8]* @bitset1.bits to i32*), i32 [[R8]]
64 ; CHECK: [[R10:%[^ ]*]] = load i32* [[R9]]
65 ; CHECK: [[R11:%[^ ]*]] = and i32 [[R5]], 31
66 ; CHECK: [[R12:%[^ ]*]] = shl i32 1, [[R11]]
67 ; CHECK: [[R13:%[^ ]*]] = and i32 [[R10]], [[R12]]
68 ; CHECK: [[R14:%[^ ]*]] = icmp ne i32 [[R13]], 0
70 ; CHECK: [[R16:%[^ ]*]] = phi i1 [ false, {{%[^ ]*}} ], [ [[R14]], {{%[^ ]*}} ]
71 %x = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset1")
73 ; CHECK-NOT: llvm.bitset.test
74 %y = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset1")
76 ; CHECK: ret i1 [[R16]]
80 ; CHECK: @bar(i32* [[B0:%[^ ]*]])
81 define i1 @bar(i32* %p) {
82 ; CHECK: [[S0:%[^ ]*]] = bitcast i32* [[B0]] to i8*
83 %pi8 = bitcast i32* %p to i8*
84 ; CHECK: [[S1:%[^ ]*]] = ptrtoint i8* [[S0]] to i32
85 ; CHECK: [[S2:%[^ ]*]] = sub i32 [[S1]], add (i32 ptrtoint ({ i32, [63 x i32], i32, [2 x i32] }* [[G]] to i32), i32 4)
86 ; CHECK: [[S3:%[^ ]*]] = lshr i32 [[S2]], 2
87 ; CHECK: [[S4:%[^ ]*]] = shl i32 [[S2]], 30
88 ; CHECK: [[S5:%[^ ]*]] = or i32 [[S3]], [[S4]]
89 ; CHECK: [[S6:%[^ ]*]] = icmp ult i32 [[S5]], 64
92 ; CHECK: [[S8:%[^ ]*]] = zext i32 [[S5]] to i64
93 ; CHECK: [[S9:%[^ ]*]] = and i64 [[S8]], 63
94 ; CHECK: [[S10:%[^ ]*]] = shl i64 1, [[S9]]
95 ; CHECK: [[S11:%[^ ]*]] = and i64 -9223372036854775807, [[S10]]
96 ; CHECK: [[S12:%[^ ]*]] = icmp ne i64 [[S11]], 0
98 ; CHECK: [[S16:%[^ ]*]] = phi i1 [ false, {{%[^ ]*}} ], [ [[S12]], {{%[^ ]*}} ]
99 %x = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset2")
100 ; CHECK: ret i1 [[S16]]
104 ; CHECK: @baz(i32* [[C0:%[^ ]*]])
105 define i1 @baz(i32* %p) {
106 ; CHECK: [[T0:%[^ ]*]] = bitcast i32* [[C0]] to i8*
107 %pi8 = bitcast i32* %p to i8*
108 ; CHECK: [[T1:%[^ ]*]] = ptrtoint i8* [[T0]] to i32
109 ; CHECK: [[T2:%[^ ]*]] = sub i32 [[T1]], ptrtoint ({ i32, [63 x i32], i32, [2 x i32] }* [[G]] to i32)
110 ; CHECK: [[T3:%[^ ]*]] = lshr i32 [[T2]], 8
111 ; CHECK: [[T4:%[^ ]*]] = shl i32 [[T2]], 24
112 ; CHECK: [[T5:%[^ ]*]] = or i32 [[T3]], [[T4]]
113 ; CHECK: [[T6:%[^ ]*]] = icmp ult i32 [[T5]], 2
114 ; CHECK: br i1 [[T6]]
116 ; CHECK: [[T8:%[^ ]*]] = and i32 [[T5]], 31
117 ; CHECK: [[T9:%[^ ]*]] = shl i32 1, [[T8]]
118 ; CHECK: [[T10:%[^ ]*]] = and i32 3, [[T9]]
119 ; CHECK: [[T11:%[^ ]*]] = icmp ne i32 [[T10]], 0
121 ; CHECK: [[T16:%[^ ]*]] = phi i1 [ false, {{%[^ ]*}} ], [ [[T11]], {{%[^ ]*}} ]
122 %x = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset3")
123 ; CHECK: ret i1 [[T16]]
127 ; CHECK-NOT: !llvm.bitsets