annotate test/Transforms/InstCombine/and2.ll @ 147:c2174574ed3a

LLVM 10
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 16:55:33 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 define i1 @test2(i1 %X, i1 %Y) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
5 ; CHECK-LABEL: @test2(
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
6 ; CHECK-NEXT: [[B:%.*]] = and i1 %X, %Y
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
7 ; CHECK-NEXT: ret i1 [[B]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
8 ;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 %a = and i1 %X, %Y
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 %b = and i1 %a, %X
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 ret i1 %b
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 define i32 @test3(i32 %X, i32 %Y) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
15 ; CHECK-LABEL: @test3(
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
16 ; CHECK-NEXT: [[B:%.*]] = and i32 %X, %Y
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
17 ; CHECK-NEXT: ret i32 [[B]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
18 ;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 %a = and i32 %X, %Y
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 %b = and i32 %Y, %a
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 ret i32 %b
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
24 define i1 @test7(i32 %i, i1 %b) {
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
25 ; CHECK-LABEL: @test7(
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
26 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 %i, 0
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
27 ; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[TMP1]], %b
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
28 ; CHECK-NEXT: ret i1 [[TMP2]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
29 ;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
30 %cmp1 = icmp slt i32 %i, 1
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
31 %cmp2 = icmp sgt i32 %i, -1
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
32 %and1 = and i1 %cmp1, %b
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
33 %and2 = and i1 %and1, %cmp2
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
34 ret i1 %and2
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
35 }
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
36
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
37 define i1 @test8(i32 %i) {
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
38 ; CHECK-LABEL: @test8(
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
39 ; CHECK-NEXT: [[I_OFF:%.*]] = add i32 %i, -1
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
40 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[I_OFF]], 13
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
41 ; CHECK-NEXT: ret i1 [[TMP1]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
42 ;
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
43 %cmp1 = icmp ne i32 %i, 0
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
44 %cmp2 = icmp ult i32 %i, 14
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
45 %cond = and i1 %cmp1, %cmp2
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
46 ret i1 %cond
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
47 }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
48
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
49 ; FIXME: Vectors should fold too.
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
50 define <2 x i1> @test8vec(<2 x i32> %i) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
51 ; CHECK-LABEL: @test8vec(
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
52 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne <2 x i32> %i, zeroinitializer
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
53 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult <2 x i32> %i, <i32 14, i32 14>
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
54 ; CHECK-NEXT: [[COND:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
55 ; CHECK-NEXT: ret <2 x i1> [[COND]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
56 ;
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
57 %cmp1 = icmp ne <2 x i32> %i, zeroinitializer
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
58 %cmp2 = icmp ult <2 x i32> %i, <i32 14, i32 14>
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
59 %cond = and <2 x i1> %cmp1, %cmp2
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
60 ret <2 x i1> %cond
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
61 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
62
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
63 ; combine -x & 1 into x & 1
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
64 define i64 @test9(i64 %x) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
65 ; CHECK-LABEL: @test9(
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
66 ; CHECK-NEXT: [[AND:%.*]] = and i64 %x, 1
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
67 ; CHECK-NEXT: ret i64 [[AND]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
68 ;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
69 %sub = sub nsw i64 0, %x
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
70 %and = and i64 %sub, 1
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
71 ret i64 %and
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
72 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
73
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
74 ; combine -x & 1 into x & 1
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
75 define <2 x i64> @test9vec(<2 x i64> %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
76 ; CHECK-LABEL: @test9vec(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
77 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> %x, <i64 1, i64 1>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
78 ; CHECK-NEXT: ret <2 x i64> [[AND]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
79 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
80 %sub = sub nsw <2 x i64> <i64 0, i64 0>, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
81 %and = and <2 x i64> %sub, <i64 1, i64 1>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
82 ret <2 x i64> %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
83 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
84
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
85 define i64 @test10(i64 %x) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
86 ; CHECK-LABEL: @test10(
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
87 ; CHECK-NEXT: [[AND:%.*]] = and i64 %x, 1
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
88 ; CHECK-NEXT: [[ADD:%.*]] = sub i64 [[AND]], %x
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
89 ; CHECK-NEXT: ret i64 [[ADD]]
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
90 ;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
91 %sub = sub nsw i64 0, %x
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
92 %and = and i64 %sub, 1
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
93 %add = add i64 %sub, %and
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
94 ret i64 %add
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
95 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
96
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
97 ; (1 << x) & 1 --> zext(x == 0)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
98
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
99 define i8 @and1_shl1_is_cmp_eq_0(i8 %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
100 ; CHECK-LABEL: @and1_shl1_is_cmp_eq_0(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
101 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 %x, 0
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
102 ; CHECK-NEXT: [[AND:%.*]] = zext i1 [[TMP1]] to i8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
103 ; CHECK-NEXT: ret i8 [[AND]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
104 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
105 %sh = shl i8 1, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
106 %and = and i8 %sh, 1
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
107 ret i8 %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
108 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
109
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
110 ; Don't do it if the shift has another use.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
111
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
112 define i8 @and1_shl1_is_cmp_eq_0_multiuse(i8 %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
113 ; CHECK-LABEL: @and1_shl1_is_cmp_eq_0_multiuse(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
114 ; CHECK-NEXT: [[SH:%.*]] = shl i8 1, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
115 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[SH]], 1
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
116 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SH]], [[AND]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
117 ; CHECK-NEXT: ret i8 [[ADD]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
118 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
119 %sh = shl i8 1, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
120 %and = and i8 %sh, 1
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
121 %add = add i8 %sh, %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
122 ret i8 %add
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
123 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
124
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
125 ; (1 << x) & 1 --> zext(x == 0)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
126
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
127 define <2 x i8> @and1_shl1_is_cmp_eq_0_vec(<2 x i8> %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
128 ; CHECK-LABEL: @and1_shl1_is_cmp_eq_0_vec(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
129 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> %x, zeroinitializer
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
130 ; CHECK-NEXT: [[AND:%.*]] = zext <2 x i1> [[TMP1]] to <2 x i8>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
131 ; CHECK-NEXT: ret <2 x i8> [[AND]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
132 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
133 %sh = shl <2 x i8> <i8 1, i8 1>, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
134 %and = and <2 x i8> %sh, <i8 1, i8 1>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
135 ret <2 x i8> %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
136 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
137
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
138 ; (1 >> x) & 1 --> zext(x == 0)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
139
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
140 define i8 @and1_lshr1_is_cmp_eq_0(i8 %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
141 ; CHECK-LABEL: @and1_lshr1_is_cmp_eq_0(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
142 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 %x, 0
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
143 ; CHECK-NEXT: [[AND:%.*]] = zext i1 [[TMP1]] to i8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
144 ; CHECK-NEXT: ret i8 [[AND]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
145 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
146 %sh = lshr i8 1, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
147 %and = and i8 %sh, 1
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
148 ret i8 %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
149 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
150
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
151 ; Don't do it if the shift has another use.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
152
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
153 define i8 @and1_lshr1_is_cmp_eq_0_multiuse(i8 %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
154 ; CHECK-LABEL: @and1_lshr1_is_cmp_eq_0_multiuse(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
155 ; CHECK-NEXT: [[SH:%.*]] = lshr i8 1, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
156 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[SH]], 1
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
157 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i8 [[SH]], [[AND]]
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
158 ; CHECK-NEXT: ret i8 [[ADD]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
159 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
160 %sh = lshr i8 1, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
161 %and = and i8 %sh, 1
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
162 %add = add i8 %sh, %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
163 ret i8 %add
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
164 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
165
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
166 ; (1 >> x) & 1 --> zext(x == 0)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
167
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
168 define <2 x i8> @and1_lshr1_is_cmp_eq_0_vec(<2 x i8> %x) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
169 ; CHECK-LABEL: @and1_lshr1_is_cmp_eq_0_vec(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
170 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> %x, zeroinitializer
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
171 ; CHECK-NEXT: [[AND:%.*]] = zext <2 x i1> [[TMP1]] to <2 x i8>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
172 ; CHECK-NEXT: ret <2 x i8> [[AND]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
173 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
174 %sh = lshr <2 x i8> <i8 1, i8 1>, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
175 %and = and <2 x i8> %sh, <i8 1, i8 1>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
176 ret <2 x i8> %and
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
177 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
178
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
179 ; The add in this test is unnecessary because the LSBs of the LHS are 0 and the 'and' only consumes bits from those LSBs. It doesn't matter what happens to the upper bits.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
180 define i32 @test11(i32 %a, i32 %b) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
181 ; CHECK-LABEL: @test11(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
182 ; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
183 ; CHECK-NEXT: [[Z:%.*]] = and i32 [[B:%.*]], 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
184 ; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
185 ; CHECK-NEXT: ret i32 [[W]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
186 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
187 %x = shl i32 %a, 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
188 %y = add i32 %x, %b
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
189 %z = and i32 %y, 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
190 %w = mul i32 %z, %x ; to keep the shift from being removed
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
191 ret i32 %w
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
192 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
193
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
194 ; The add in this test is unnecessary because the LSBs of the RHS are 0 and the 'and' only consumes bits from those LSBs. It doesn't matter what happens to the upper bits.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
195 define i32 @test12(i32 %a, i32 %b) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
196 ; CHECK-LABEL: @test12(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
197 ; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
198 ; CHECK-NEXT: [[Z:%.*]] = and i32 [[B:%.*]], 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
199 ; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
200 ; CHECK-NEXT: ret i32 [[W]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
201 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
202 %x = shl i32 %a, 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
203 %y = add i32 %b, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
204 %z = and i32 %y, 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
205 %w = mul i32 %z, %x ; to keep the shift from being removed
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
206 ret i32 %w
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
207 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
208
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
209 ; The sub in this test is unnecessary because the LSBs of the RHS are 0 and the 'and' only consumes bits from those LSBs. It doesn't matter what happens to the upper bits.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
210 define i32 @test13(i32 %a, i32 %b) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
211 ; CHECK-LABEL: @test13(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
212 ; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
213 ; CHECK-NEXT: [[Z:%.*]] = and i32 [[B:%.*]], 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
214 ; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
215 ; CHECK-NEXT: ret i32 [[W]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
216 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
217 %x = shl i32 %a, 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
218 %y = sub i32 %b, %x
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
219 %z = and i32 %y, 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
220 %w = mul i32 %z, %x ; to keep the shift from being removed
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
221 ret i32 %w
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
222 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
223
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
224 ; The sub in this test cannot be removed because we need to keep the negation of %b. TODO: But we should be able to replace the LHS of it with a 0.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
225 define i32 @test14(i32 %a, i32 %b) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
226 ; CHECK-LABEL: @test14(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
227 ; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
228 ; CHECK-NEXT: [[Y:%.*]] = sub i32 0, [[B:%.*]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
229 ; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
230 ; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
231 ; CHECK-NEXT: ret i32 [[W]]
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
232 ;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
233 %x = shl i32 %a, 8
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
234 %y = sub i32 %x, %b
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
235 %z = and i32 %y, 128
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
236 %w = mul i32 %z, %x ; to keep the shift from being removed
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
237 ret i32 %w
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
238 }