1 ; RUN: opt -S -demanded-bits -analyze < %s | FileCheck %s
2 ; RUN: opt -S -disable-output -passes="print<demanded-bits>" < %s 2>&1 | FileCheck %s
4 ; CHECK-DAG: DemandedBits: 0xff00 for %x = or <2 x i32> %a, zeroinitializer
5 ; CHECK-DAG: DemandedBits: 0xff00 for %y = or <2 x i32> %b, zeroinitializer
6 ; CHECK-DAG: DemandedBits: 0xff00 for %z = or <2 x i32> %x, %y
7 ; CHECK-DAG: DemandedBits: 0xff for %u = lshr <2 x i32> %z, <i32 8, i32 8>
8 ; CHECK-DAG: DemandedBits: 0xff for %r = trunc <2 x i32> %u to <2 x i8>
9 define <2 x i8> @test_basic(<2 x i32> %a, <2 x i32> %b) {
10 %x = or <2 x i32> %a, zeroinitializer
11 %y = or <2 x i32> %b, zeroinitializer
12 %z = or <2 x i32> %x, %y
13 %u = lshr <2 x i32> %z, <i32 8, i32 8>
14 %r = trunc <2 x i32> %u to <2 x i8>
18 ; Vector-specific instructions
20 ; CHECK-DAG: DemandedBits: 0xff for %x = or <2 x i32> %a, zeroinitializer
21 ; CHECK-DAG: DemandedBits: 0xf0 for %z = extractelement <2 x i32> %x, i32 1
22 ; CHECK-DAG: DemandedBits: 0xf for %y = extractelement <2 x i32> %x, i32 0
23 ; CHECK-DAG: DemandedBits: 0xffffffff for %u = and i32 %y, 15
24 ; CHECK-DAG: DemandedBits: 0xffffffff for %v = and i32 %z, 240
25 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = or i32 %u, %v
26 define i32 @test_extractelement(<2 x i32> %a) {
27 %x = or <2 x i32> %a, zeroinitializer
28 %y = extractelement <2 x i32> %x, i32 0
29 %z = extractelement <2 x i32> %x, i32 1
36 ; CHECK-DAG: DemandedBits: 0xff for %x = or i32 %a, 0
37 ; CHECK-DAG: DemandedBits: 0xff for %y = or i32 %b, 0
38 ; CHECK-DAG: DemandedBits: 0xff for %z = insertelement <2 x i32> undef, i32 %x, i32 0
39 ; CHECK-DAG: DemandedBits: 0xff for %u = insertelement <2 x i32> %z, i32 %y, i32 1
40 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <2 x i32> %u, <i32 255, i32 127>
41 define <2 x i32> @test_insertelement(i32 %a, i32 %b) {
44 %z = insertelement <2 x i32> undef, i32 %x, i32 0
45 %u = insertelement <2 x i32> %z, i32 %y, i32 1
46 %r = and <2 x i32> %u, <i32 255, i32 127>
50 ; CHECK-DAG: DemandedBits: 0xff for %x = or <2 x i32> %a, zeroinitializer
51 ; CHECK-DAG: DemandedBits: 0xff for %y = or <2 x i32> %b, zeroinitializer
52 ; CHECK-DAG: DemandedBits: 0xff for %z = shufflevector <2 x i32> %x, <2 x i32> %y, <3 x i32> <i32 0, i32 3, i32 1>
53 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <3 x i32> %z, <i32 255, i32 127, i32 0>
54 define <3 x i32> @test_shufflevector(<2 x i32> %a, <2 x i32> %b) {
55 %x = or <2 x i32> %a, zeroinitializer
56 %y = or <2 x i32> %b, zeroinitializer
57 %z = shufflevector <2 x i32> %x, <2 x i32> %y, <3 x i32> <i32 0, i32 3, i32 1>
58 %r = and <3 x i32> %z, <i32 255, i32 127, i32 0>
62 ; Shifts with splat shift amounts
64 ; CHECK-DAG: DemandedBits: 0xf for %x = or <2 x i32> %a, zeroinitializer
65 ; CHECK-DAG: DemandedBits: 0xf0 for %y = shl <2 x i32> %x, <i32 4, i32 4>
66 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <2 x i32> %y, <i32 240, i32 240>
67 define <2 x i32> @test_shl(<2 x i32> %a) {
68 %x = or <2 x i32> %a, zeroinitializer
69 %y = shl <2 x i32> %x, <i32 4, i32 4>
70 %r = and <2 x i32> %y, <i32 240, i32 240>
74 ; CHECK-DAG: DemandedBits: 0xf00 for %x = or <2 x i32> %a, zeroinitializer
75 ; CHECK-DAG: DemandedBits: 0xf0 for %y = ashr <2 x i32> %x, <i32 4, i32 4>
76 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <2 x i32> %y, <i32 240, i32 240>
77 define <2 x i32> @test_ashr(<2 x i32> %a) {
78 %x = or <2 x i32> %a, zeroinitializer
79 %y = ashr <2 x i32> %x, <i32 4, i32 4>
80 %r = and <2 x i32> %y, <i32 240, i32 240>
84 ; CHECK-DAG: DemandedBits: 0xf00 for %x = or <2 x i32> %a, zeroinitializer
85 ; CHECK-DAG: DemandedBits: 0xf0 for %y = lshr <2 x i32> %x, <i32 4, i32 4>
86 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <2 x i32> %y, <i32 240, i32 240>
87 define <2 x i32> @test_lshr(<2 x i32> %a) {
88 %x = or <2 x i32> %a, zeroinitializer
89 %y = lshr <2 x i32> %x, <i32 4, i32 4>
90 %r = and <2 x i32> %y, <i32 240, i32 240>
94 declare <2 x i32> @llvm.fshl.i32(<2 x i32>, <2 x i32>, <2 x i32>)
95 declare <2 x i32> @llvm.fshr.i32(<2 x i32>, <2 x i32>, <2 x i32>)
97 ; CHECK-DAG: DemandedBits: 0xf for %x = or <2 x i32> %a, zeroinitializer
98 ; CHECK-DAG: DemandedBits: 0xf0000000 for %y = or <2 x i32> %b, zeroinitializer
99 ; CHECK-DAG: DemandedBits: 0xff for %z = call <2 x i32> @llvm.fshl.v2i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 4, i32 4>)
100 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <2 x i32> %z, <i32 255, i32 255>
101 define <2 x i32> @test_fshl(<2 x i32> %a, <2 x i32> %b) {
102 %x = or <2 x i32> %a, zeroinitializer
103 %y = or <2 x i32> %b, zeroinitializer
104 %z = call <2 x i32> @llvm.fshl.i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 4, i32 4>)
105 %r = and <2 x i32> %z, <i32 255, i32 255>
109 ; CHECK-DAG: DemandedBits: 0xf for %x = or <2 x i32> %a, zeroinitializer
110 ; CHECK-DAG: DemandedBits: 0xf0000000 for %y = or <2 x i32> %b, zeroinitializer
111 ; CHECK-DAG: DemandedBits: 0xff for %z = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 28, i32 28>)
112 ; CHECK-DAG: DemandedBits: 0xffffffff for %r = and <2 x i32> %z, <i32 255, i32 255>
113 define <2 x i32> @test_fshr(<2 x i32> %a, <2 x i32> %b) {
114 %x = or <2 x i32> %a, zeroinitializer
115 %y = or <2 x i32> %b, zeroinitializer
116 %z = call <2 x i32> @llvm.fshr.i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 28, i32 28>)
117 %r = and <2 x i32> %z, <i32 255, i32 255>
121 ; FP / Int conversion. These have different input / output types.
123 ; CHECK-DAG: DemandedBits: 0xffffffff for %x = or <2 x i32> %a, zeroinitializer
124 define <2 x float> @test_uitofp(<2 x i32> %a) {
125 %x = or <2 x i32> %a, zeroinitializer
126 %r = uitofp <2 x i32> %x to <2 x float>
130 ; CHECK-DAG: DemandedBits: 0xffffffff for %y = fptoui <2 x float> %x to <2 x i32>
131 define <2 x i32> @test_fptoui(<2 x float> %a) {
132 %x = fadd <2 x float> %a, <float 1.0, float 1.0>
133 %y = fptoui <2 x float> %x to <2 x i32>
134 %r = and <2 x i32> %y, <i32 255, i32 255>