vector-xor.ll
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
; (A&B)^(A&C) -> A&(B^C) etc
define <4 x i32> @test_v4i32_xor_repeated_and_0(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
; CHECK-LABEL: @test_v4i32_xor_repeated_and_0(
; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[B:%.*]], [[C:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i32> [[TMP1]], [[A:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = and <4 x i32> %a, %b
%2 = and <4 x i32> %a, %c
%3 = xor <4 x i32> %1, %2
ret <4 x i32> %3
}
define <4 x i32> @test_v4i32_xor_repeated_and_1(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
; CHECK-LABEL: @test_v4i32_xor_repeated_and_1(
; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[B:%.*]], [[C:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i32> [[TMP1]], [[A:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = and <4 x i32> %a, %b
%2 = and <4 x i32> %c, %a
%3 = xor <4 x i32> %1, %2
ret <4 x i32> %3
}
; xor(bswap(a), c) to bswap(xor(a, bswap(c)))
declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>)
define <4 x i32> @test_v4i32_xor_bswap_splatconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_bswap_splatconst(
; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[A0:%.*]], <i32 -16777216, i32 -16777216, i32 -16777216, i32 -16777216>
; CHECK-NEXT: [[TMP2:%.*]] = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> [[TMP1]])
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a0)
%2 = xor <4 x i32> %1, <i32 255, i32 255, i32 255, i32 255>
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_xor_bswap_const(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_bswap_const(
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> [[A0:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 0, i32 -16777216, i32 2, i32 3>
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a0)
%2 = xor <4 x i32> %1, <i32 0, i32 -16777216, i32 2, i32 3>
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_xor_bswap_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_bswap_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> [[A0:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 undef, i32 0, i32 2, i32 3>
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a0)
%2 = xor <4 x i32> %1, <i32 undef, i32 0, i32 2, i32 3>
ret <4 x i32> %2
}
; DeMorgan's Law: ~(~X & Y) --> (X | ~Y)
define <4 x i32> @test_v4i32_demorgan_and(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @test_v4i32_demorgan_and(
; CHECK-NEXT: [[Y_NOT:%.*]] = xor <4 x i32> [[Y:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
; CHECK-NEXT: [[TMP1:%.*]] = or <4 x i32> [[Y_NOT]], [[X:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
%2 = and <4 x i32> %1, %y
%3 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %2
ret <4 x i32> %3
}
; DeMorgan's Law: ~(~X | Y) --> (X & ~Y)
define <4 x i32> @test_v4i32_demorgan_or(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @test_v4i32_demorgan_or(
; CHECK-NEXT: [[Y_NOT:%.*]] = xor <4 x i32> [[Y:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
; CHECK-NEXT: [[TMP1:%.*]] = and <4 x i32> [[Y_NOT]], [[X:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
%2 = or <4 x i32> %1, %y
%3 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %2
ret <4 x i32> %3
}
; ~(~X >>s Y) --> (X >>s Y)
define <4 x i32> @test_v4i32_not_ashr_not(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @test_v4i32_not_ashr_not(
; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
%2 = ashr <4 x i32> %1, %y
%3 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %2
ret <4 x i32> %3
}
define <4 x i32> @test_v4i32_not_ashr_not_undef(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @test_v4i32_not_ashr_not_undef(
; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %x
%2 = ashr <4 x i32> %1, %y
%3 = xor <4 x i32> <i32 -1, i32 -1, i32 undef, i32 -1>, %2
ret <4 x i32> %3
}
; ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits)
define <4 x i32> @test_v4i32_not_ashr_negative_splatconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_ashr_negative_splatconst(
; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 2, i32 2, i32 2>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = ashr <4 x i32> <i32 -3, i32 -3, i32 -3, i32 -3>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_not_ashr_negative_const(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_ashr_negative_const(
; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 4, i32 6, i32 8>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = ashr <4 x i32> <i32 -3, i32 -5, i32 -7, i32 -9>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_not_ashr_negative_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_ashr_negative_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 4, i32 undef, i32 8>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = ashr <4 x i32> <i32 -3, i32 -5, i32 undef, i32 -9>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %1
ret <4 x i32> %2
}
; ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits)
define <4 x i32> @test_v4i32_not_lshr_nonnegative_splatconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_splatconst(
; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -4, i32 -4, i32 -4>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = lshr <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_not_lshr_nonnegative_const(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const(
; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -6, i32 -8, i32 -10>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = lshr <4 x i32> <i32 3, i32 5, i32 7, i32 9>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -6, i32 undef, i32 -10>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = lshr <4 x i32> <i32 3, i32 5, i32 undef, i32 9>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %1
ret <4 x i32> %2
}
; ~(C-X) == X-C-1 == X+(-C-1)
define <4 x i32> @test_v4i32_not_sub_splatconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_sub_splatconst(
; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -4, i32 -4, i32 -4, i32 -4>
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = sub <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_not_sub_const(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_sub_const(
; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -4, i32 -6, i32 0, i32 -16>
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = sub <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_not_sub_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_not_sub_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -4, i32 undef, i32 0, i32 -16>
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = sub <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, %a0
%2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %1
ret <4 x i32> %2
}
; (C - X) ^ signmask -> (C + signmask - X)
define <4 x i32> @test_v4i32_xor_signmask_sub_splatconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_signmask_sub_splatconst(
; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 -2147483645, i32 -2147483645, i32 -2147483645, i32 -2147483645>, [[A0:%.*]]
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = sub <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
%2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_xor_signmask_sub_const(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_signmask_sub_const(
; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, [[A0:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = sub <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, %a0
%2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_xor_signmask_sub_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_signmask_sub_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, [[A0:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = sub <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, %a0
%2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>, %1
ret <4 x i32> %2
}
; (X + C) ^ signmask -> (X + C + signmask)
define <4 x i32> @test_v4i32_xor_signmask_add_splatconst(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_signmask_add_splatconst(
; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -2147483645, i32 -2147483645, i32 -2147483645, i32 -2147483645>
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
;
%1 = add <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
%2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_xor_signmask_add_const(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_signmask_add_const(
; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 3, i32 5, i32 -1, i32 15>
; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = add <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, %a0
%2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
ret <4 x i32> %2
}
define <4 x i32> @test_v4i32_xor_signmask_add_const_undef(<4 x i32> %a0) {
; CHECK-LABEL: @test_v4i32_xor_signmask_add_const_undef(
; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 3, i32 undef, i32 -1, i32 15>
; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = add <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, %a0
%2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>, %1
ret <4 x i32> %2
}