Home | History | Annotate | Download | only in LowerBitSets
      1 ; RUN: opt -S -lowerbitsets < %s | FileCheck %s
      2 ; RUN: opt -S -lowerbitsets -mtriple=x86_64-apple-macosx10.8.0 < %s | FileCheck -check-prefix=CHECK-DARWIN %s
      3 ; RUN: opt -S -O3 < %s | FileCheck -check-prefix=CHECK-NODISCARD %s
      4 
      5 target datalayout = "e-p:32:32"
      6 
      7 ; CHECK: [[G:@[^ ]*]] = private constant { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] } { i32 1, [0 x i8] zeroinitializer, [63 x i32] zeroinitializer, [4 x i8] zeroinitializer, i32 3, [0 x i8] zeroinitializer, [2 x i32] [i32 4, i32 5] }
      8 @a = constant i32 1
      9 @b = hidden constant [63 x i32] zeroinitializer
     10 @c = protected constant i32 3
     11 @d = constant [2 x i32] [i32 4, i32 5]
     12 
     13 ; CHECK: [[BA:@[^ ]*]] = private constant [68 x i8] c"\03\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\00\01"
     14 
     15 ; Offset 0, 4 byte alignment
     16 !0 = !{!"bitset1", i32* @a, i32 0}
     17 ; CHECK-NODISCARD-DAG: !{!"bitset1", i32* @a, i32 0}
     18 !1 = !{!"bitset1", [63 x i32]* @b, i32 0}
     19 ; CHECK-NODISCARD-DAG: !{!"bitset1", [63 x i32]* @b, i32 0}
     20 !2 = !{!"bitset1", [2 x i32]* @d, i32 4}
     21 ; CHECK-NODISCARD-DAG: !{!"bitset1", [2 x i32]* @d, i32 4}
     22 
     23 ; Offset 4, 256 byte alignment
     24 !3 = !{!"bitset2", [63 x i32]* @b, i32 0}
     25 ; CHECK-NODISCARD-DAG: !{!"bitset2", [63 x i32]* @b, i32 0}
     26 !4 = !{!"bitset2", i32* @c, i32 0}
     27 ; CHECK-NODISCARD-DAG: !{!"bitset2", i32* @c, i32 0}
     28 
     29 ; Entries whose second operand is null (the result of a global being DCE'd)
     30 ; should be ignored.
     31 !5 = !{!"bitset2", null, i32 0}
     32 
     33 ; Offset 0, 4 byte alignment
     34 !6 = !{!"bitset3", i32* @a, i32 0}
     35 ; CHECK-NODISCARD-DAG: !{!"bitset3", i32* @a, i32 0}
     36 !7 = !{!"bitset3", i32* @c, i32 0}
     37 ; CHECK-NODISCARD-DAG: !{!"bitset3", i32* @c, i32 0}
     38 
     39 !llvm.bitsets = !{ !0, !1, !2, !3, !4, !5, !6, !7 }
     40 
     41 ; CHECK: @bits_use{{[0-9]*}} = private alias i8, i8* @bits{{[0-9]*}}
     42 ; CHECK: @bits_use.{{[0-9]*}} = private alias i8, i8* @bits{{[0-9]*}}
     43 ; CHECK: @bits_use.{{[0-9]*}} = private alias i8, i8* @bits{{[0-9]*}}
     44 
     45 ; CHECK: @a = alias i32, getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 0)
     46 ; CHECK: @b = hidden alias [63 x i32], getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 2)
     47 ; CHECK: @c = protected alias i32, getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 4)
     48 ; CHECK: @d = alias [2 x i32], getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 6)
     49 
     50 ; CHECK-DARWIN: @aptr = constant i32* getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G:@[^ ]*]], i32 0, i32 0)
     51 @aptr = constant i32* @a
     52 
     53 ; CHECK-DARWIN: @bptr = constant [63 x i32]* getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 2)
     54 @bptr = constant [63 x i32]* @b
     55 
     56 ; CHECK-DARWIN: @cptr = constant i32* getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 4)
     57 @cptr = constant i32* @c
     58 
     59 ; CHECK-DARWIN: @dptr = constant [2 x i32]* getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 6)
     60 @dptr = constant [2 x i32]* @d
     61 
     62 ; CHECK-DARWIN: [[G]] = private constant
     63 
     64 ; CHECK: @bits{{[0-9]*}} = private alias i8, getelementptr inbounds ([68 x i8], [68 x i8]* [[BA]], i32 0, i32 0)
     65 ; CHECK: @bits.{{[0-9]*}} = private alias i8, getelementptr inbounds ([68 x i8], [68 x i8]* [[BA]], i32 0, i32 0)
     66 
     67 declare i1 @llvm.bitset.test(i8* %ptr, metadata %bitset) nounwind readnone
     68 
     69 ; CHECK: @foo(i32* [[A0:%[^ ]*]])
     70 define i1 @foo(i32* %p) {
     71   ; CHECK-NOT: llvm.bitset.test
     72 
     73   ; CHECK: [[R0:%[^ ]*]] = bitcast i32* [[A0]] to i8*
     74   %pi8 = bitcast i32* %p to i8*
     75   ; CHECK: [[R1:%[^ ]*]] = ptrtoint i8* [[R0]] to i32
     76   ; CHECK: [[R2:%[^ ]*]] = sub i32 [[R1]], ptrtoint ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]] to i32)
     77   ; CHECK: [[R3:%[^ ]*]] = lshr i32 [[R2]], 2
     78   ; CHECK: [[R4:%[^ ]*]] = shl i32 [[R2]], 30
     79   ; CHECK: [[R5:%[^ ]*]] = or i32 [[R3]], [[R4]]
     80   ; CHECK: [[R6:%[^ ]*]] = icmp ult i32 [[R5]], 68
     81   ; CHECK: br i1 [[R6]]
     82 
     83   ; CHECK: [[R8:%[^ ]*]] = getelementptr i8, i8* @bits_use.{{[0-9]*}}, i32 [[R5]]
     84   ; CHECK: [[R9:%[^ ]*]] = load i8, i8* [[R8]]
     85   ; CHECK: [[R10:%[^ ]*]] = and i8 [[R9]], 1
     86   ; CHECK: [[R11:%[^ ]*]] = icmp ne i8 [[R10]], 0
     87 
     88   ; CHECK: [[R16:%[^ ]*]] = phi i1 [ false, {{%[^ ]*}} ], [ [[R11]], {{%[^ ]*}} ]
     89   %x = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset1")
     90 
     91   ; CHECK-NOT: llvm.bitset.test
     92   %y = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset1")
     93 
     94   ; CHECK: ret i1 [[R16]]
     95   ret i1 %x
     96 }
     97 
     98 ; CHECK: @bar(i32* [[B0:%[^ ]*]])
     99 define i1 @bar(i32* %p) {
    100   ; CHECK: [[S0:%[^ ]*]] = bitcast i32* [[B0]] to i8*
    101   %pi8 = bitcast i32* %p to i8*
    102   ; CHECK: [[S1:%[^ ]*]] = ptrtoint i8* [[S0]] to i32
    103   ; CHECK: [[S2:%[^ ]*]] = sub i32 [[S1]], add (i32 ptrtoint ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]] to i32), i32 4)
    104   ; CHECK: [[S3:%[^ ]*]] = lshr i32 [[S2]], 8
    105   ; CHECK: [[S4:%[^ ]*]] = shl i32 [[S2]], 24
    106   ; CHECK: [[S5:%[^ ]*]] = or i32 [[S3]], [[S4]]
    107   ; CHECK: [[S6:%[^ ]*]] = icmp ult i32 [[S5]], 2
    108   %x = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset2")
    109 
    110   ; CHECK: ret i1 [[S6]]
    111   ret i1 %x
    112 }
    113 
    114 ; CHECK: @baz(i32* [[C0:%[^ ]*]])
    115 define i1 @baz(i32* %p) {
    116   ; CHECK: [[T0:%[^ ]*]] = bitcast i32* [[C0]] to i8*
    117   %pi8 = bitcast i32* %p to i8*
    118   ; CHECK: [[T1:%[^ ]*]] = ptrtoint i8* [[T0]] to i32
    119   ; CHECK: [[T2:%[^ ]*]] = sub i32 [[T1]], ptrtoint ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]] to i32)
    120   ; CHECK: [[T3:%[^ ]*]] = lshr i32 [[T2]], 2
    121   ; CHECK: [[T4:%[^ ]*]] = shl i32 [[T2]], 30
    122   ; CHECK: [[T5:%[^ ]*]] = or i32 [[T3]], [[T4]]
    123   ; CHECK: [[T6:%[^ ]*]] = icmp ult i32 [[T5]], 66
    124   ; CHECK: br i1 [[T6]]
    125 
    126   ; CHECK: [[T8:%[^ ]*]] = getelementptr i8, i8* @bits_use.{{[0-9]*}}, i32 [[T5]]
    127   ; CHECK: [[T9:%[^ ]*]] = load i8, i8* [[T8]]
    128   ; CHECK: [[T10:%[^ ]*]] = and i8 [[T9]], 2
    129   ; CHECK: [[T11:%[^ ]*]] = icmp ne i8 [[T10]], 0
    130 
    131   ; CHECK: [[T16:%[^ ]*]] = phi i1 [ false, {{%[^ ]*}} ], [ [[T11]], {{%[^ ]*}} ]
    132   %x = call i1 @llvm.bitset.test(i8* %pi8, metadata !"bitset3")
    133   ; CHECK: ret i1 [[T16]]
    134   ret i1 %x
    135 }
    136 
    137 ; CHECK-NOT: !llvm.bitsets
    138