blob: f5d96b1dc4de374d81186a6c104db37edcb71baf [file] [log] [blame]
Sanjay Patel0f95dd22018-01-25 16:03:44 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -data-layout="n8:16:32" -S | FileCheck %s --check-prefix=ALL --check-prefix=LEGAL8
3; RUN: opt < %s -instcombine -data-layout="n16" -S | FileCheck %s --check-prefix=ALL --check-prefix=LEGAL16
4
5; PR35792 - https://bugs.llvm.org/show_bug.cgi?id=35792
6
7define i16 @zext_add(i8 %x) {
8; ALL-LABEL: @zext_add(
9; ALL-NEXT: [[Z:%.*]] = zext i8 [[X:%.*]] to i16
10; ALL-NEXT: [[B:%.*]] = add nuw nsw i16 [[Z]], 44
11; ALL-NEXT: [[R:%.*]] = and i16 [[B]], [[Z]]
12; ALL-NEXT: ret i16 [[R]]
13;
14 %z = zext i8 %x to i16
15 %b = add i16 %z, 44
16 %r = and i16 %b, %z
17 ret i16 %r
18}
19
20define i16 @zext_sub(i8 %x) {
21; ALL-LABEL: @zext_sub(
22; ALL-NEXT: [[Z:%.*]] = zext i8 [[X:%.*]] to i16
23; ALL-NEXT: [[B:%.*]] = sub nsw i16 251, [[Z]]
24; ALL-NEXT: [[R:%.*]] = and i16 [[B]], [[Z]]
25; ALL-NEXT: ret i16 [[R]]
26;
27 %z = zext i8 %x to i16
28 %b = sub i16 -5, %z
29 %r = and i16 %b, %z
30 ret i16 %r
31}
32
33define i16 @zext_mul(i8 %x) {
34; ALL-LABEL: @zext_mul(
35; ALL-NEXT: [[Z:%.*]] = zext i8 [[X:%.*]] to i16
36; ALL-NEXT: [[B:%.*]] = mul nuw nsw i16 [[Z]], 3
37; ALL-NEXT: [[R:%.*]] = and i16 [[B]], [[Z]]
38; ALL-NEXT: ret i16 [[R]]
39;
40 %z = zext i8 %x to i16
41 %b = mul i16 %z, 3
42 %r = and i16 %b, %z
43 ret i16 %r
44}
45
46define i16 @zext_lshr(i8 %x) {
47; ALL-LABEL: @zext_lshr(
48; ALL-NEXT: [[Z:%.*]] = zext i8 [[X:%.*]] to i16
49; ALL-NEXT: [[B:%.*]] = lshr i16 [[Z]], 4
50; ALL-NEXT: [[R:%.*]] = and i16 [[B]], [[Z]]
51; ALL-NEXT: ret i16 [[R]]
52;
53 %z = zext i8 %x to i16
54 %b = lshr i16 %z, 4
55 %r = and i16 %b, %z
56 ret i16 %r
57}
58
59define i16 @zext_ashr(i8 %x) {
60; ALL-LABEL: @zext_ashr(
61; ALL-NEXT: [[Z:%.*]] = zext i8 [[X:%.*]] to i16
62; ALL-NEXT: [[TMP1:%.*]] = lshr i16 [[Z]], 2
63; ALL-NEXT: [[R:%.*]] = and i16 [[TMP1]], [[Z]]
64; ALL-NEXT: ret i16 [[R]]
65;
66 %z = zext i8 %x to i16
67 %b = ashr i16 %z, 2
68 %r = and i16 %b, %z
69 ret i16 %r
70}
71
72define i16 @zext_shl(i8 %x) {
73; ALL-LABEL: @zext_shl(
74; ALL-NEXT: [[Z:%.*]] = zext i8 [[X:%.*]] to i16
75; ALL-NEXT: [[B:%.*]] = shl nuw nsw i16 [[Z]], 3
76; ALL-NEXT: [[R:%.*]] = and i16 [[B]], [[Z]]
77; ALL-NEXT: ret i16 [[R]]
78;
79 %z = zext i8 %x to i16
80 %b = shl i16 %z, 3
81 %r = and i16 %b, %z
82 ret i16 %r
83}
84
85define <2 x i16> @zext_add_vec(<2 x i8> %x) {
86; ALL-LABEL: @zext_add_vec(
87; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
88; ALL-NEXT: [[B:%.*]] = add nuw nsw <2 x i16> [[Z]], <i16 44, i16 42>
89; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
90; ALL-NEXT: ret <2 x i16> [[R]]
91;
92 %z = zext <2 x i8> %x to <2 x i16>
93 %b = add <2 x i16> %z, <i16 44, i16 42>
94 %r = and <2 x i16> %b, %z
95 ret <2 x i16> %r
96}
97
98define <2 x i16> @zext_sub_vec(<2 x i8> %x) {
99; ALL-LABEL: @zext_sub_vec(
100; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
101; ALL-NEXT: [[B:%.*]] = sub nuw nsw <2 x i16> <i16 -5, i16 -4>, [[Z]]
102; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
103; ALL-NEXT: ret <2 x i16> [[R]]
104;
105 %z = zext <2 x i8> %x to <2 x i16>
106 %b = sub <2 x i16> <i16 -5, i16 -4>, %z
107 %r = and <2 x i16> %b, %z
108 ret <2 x i16> %r
109}
110
111define <2 x i16> @zext_mul_vec(<2 x i8> %x) {
112; ALL-LABEL: @zext_mul_vec(
113; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
114; ALL-NEXT: [[B:%.*]] = mul nsw <2 x i16> [[Z]], <i16 3, i16 -2>
115; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
116; ALL-NEXT: ret <2 x i16> [[R]]
117;
118 %z = zext <2 x i8> %x to <2 x i16>
119 %b = mul <2 x i16> %z, <i16 3, i16 -2>
120 %r = and <2 x i16> %b, %z
121 ret <2 x i16> %r
122}
123
124define <2 x i16> @zext_lshr_vec(<2 x i8> %x) {
125; ALL-LABEL: @zext_lshr_vec(
126; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
127; ALL-NEXT: [[B:%.*]] = lshr <2 x i16> [[Z]], <i16 4, i16 2>
128; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
129; ALL-NEXT: ret <2 x i16> [[R]]
130;
131 %z = zext <2 x i8> %x to <2 x i16>
132 %b = lshr <2 x i16> %z, <i16 4, i16 2>
133 %r = and <2 x i16> %b, %z
134 ret <2 x i16> %r
135}
136
137define <2 x i16> @zext_ashr_vec(<2 x i8> %x) {
138; ALL-LABEL: @zext_ashr_vec(
139; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
140; ALL-NEXT: [[B:%.*]] = lshr <2 x i16> [[Z]], <i16 2, i16 3>
141; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
142; ALL-NEXT: ret <2 x i16> [[R]]
143;
144 %z = zext <2 x i8> %x to <2 x i16>
145 %b = ashr <2 x i16> %z, <i16 2, i16 3>
146 %r = and <2 x i16> %b, %z
147 ret <2 x i16> %r
148}
149
150define <2 x i16> @zext_shl_vec(<2 x i8> %x) {
151; ALL-LABEL: @zext_shl_vec(
152; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
153; ALL-NEXT: [[B:%.*]] = shl <2 x i16> [[Z]], <i16 3, i16 2>
154; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
155; ALL-NEXT: ret <2 x i16> [[R]]
156;
157 %z = zext <2 x i8> %x to <2 x i16>
158 %b = shl <2 x i16> %z, <i16 3, i16 2>
159 %r = and <2 x i16> %b, %z
160 ret <2 x i16> %r
161}
162
163; Don't create poison by narrowing a shift below the shift amount.
164
165define <2 x i16> @zext_lshr_vec_overshift(<2 x i8> %x) {
166; ALL-LABEL: @zext_lshr_vec_overshift(
167; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
168; ALL-NEXT: [[B:%.*]] = lshr <2 x i16> [[Z]], <i16 4, i16 8>
169; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
170; ALL-NEXT: ret <2 x i16> [[R]]
171;
172 %z = zext <2 x i8> %x to <2 x i16>
173 %b = lshr <2 x i16> %z, <i16 4, i16 8>
174 %r = and <2 x i16> %b, %z
175 ret <2 x i16> %r
176}
177
178; Don't create poison by narrowing a shift below the shift amount.
179
180define <2 x i16> @zext_shl_vec_overshift(<2 x i8> %x) {
181; ALL-LABEL: @zext_shl_vec_overshift(
182; ALL-NEXT: [[Z:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
183; ALL-NEXT: [[B:%.*]] = shl <2 x i16> [[Z]], <i16 8, i16 2>
184; ALL-NEXT: [[R:%.*]] = and <2 x i16> [[B]], [[Z]]
185; ALL-NEXT: ret <2 x i16> [[R]]
186;
187 %z = zext <2 x i8> %x to <2 x i16>
188 %b = shl <2 x i16> %z, <i16 8, i16 2>
189 %r = and <2 x i16> %b, %z
190 ret <2 x i16> %r
191}
192