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