1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; (A&B)^(A&C) -> A&(B^C) etc
6 define <4 x i32> @test_v4i32_xor_repeated_and_0(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
7 ; CHECK-LABEL: @test_v4i32_xor_repeated_and_0(
8 ; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[B:%.*]], [[C:%.*]]
9 ; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i32> [[TMP1]], [[A:%.*]]
10 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
12 %1 = and <4 x i32> %a, %b
13 %2 = and <4 x i32> %a, %c
14 %3 = xor <4 x i32> %1, %2
18 define <4 x i32> @test_v4i32_xor_repeated_and_1(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
19 ; CHECK-LABEL: @test_v4i32_xor_repeated_and_1(
20 ; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[B:%.*]], [[C:%.*]]
21 ; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i32> [[TMP1]], [[A:%.*]]
22 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
24 %1 = and <4 x i32> %a, %b
25 %2 = and <4 x i32> %c, %a
26 %3 = xor <4 x i32> %1, %2
30 ; xor(bswap(a), c) to bswap(xor(a, bswap(c)))
32 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>)
34 define <4 x i32> @test_v4i32_xor_bswap_splatconst(<4 x i32> %a0) {
35 ; CHECK-LABEL: @test_v4i32_xor_bswap_splatconst(
36 ; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[A0:%.*]], <i32 -16777216, i32 -16777216, i32 -16777216, i32 -16777216>
37 ; CHECK-NEXT: [[TMP2:%.*]] = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> [[TMP1]])
38 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
40 %1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a0)
41 %2 = xor <4 x i32> %1, <i32 255, i32 255, i32 255, i32 255>
45 define <4 x i32> @test_v4i32_xor_bswap_const(<4 x i32> %a0) {
46 ; CHECK-LABEL: @test_v4i32_xor_bswap_const(
47 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> [[A0:%.*]])
48 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 0, i32 -16777216, i32 2, i32 3>
49 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
51 %1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a0)
52 %2 = xor <4 x i32> %1, <i32 0, i32 -16777216, i32 2, i32 3>
56 define <4 x i32> @test_v4i32_xor_bswap_const_undef(<4 x i32> %a0) {
57 ; CHECK-LABEL: @test_v4i32_xor_bswap_const_undef(
58 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> [[A0:%.*]])
59 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 undef, i32 0, i32 2, i32 3>
60 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
62 %1 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a0)
63 %2 = xor <4 x i32> %1, <i32 undef, i32 0, i32 2, i32 3>
67 ; DeMorgan's Law: ~(~X & Y) --> (X | ~Y)
69 define <4 x i32> @test_v4i32_demorgan_and(<4 x i32> %x, <4 x i32> %y) {
70 ; CHECK-LABEL: @test_v4i32_demorgan_and(
71 ; CHECK-NEXT: [[Y_NOT:%.*]] = xor <4 x i32> [[Y:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
72 ; CHECK-NEXT: [[TMP1:%.*]] = or <4 x i32> [[Y_NOT]], [[X:%.*]]
73 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
75 %1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
76 %2 = and <4 x i32> %1, %y
77 %3 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %2
81 ; DeMorgan's Law: ~(~X | Y) --> (X & ~Y)
83 define <4 x i32> @test_v4i32_demorgan_or(<4 x i32> %x, <4 x i32> %y) {
84 ; CHECK-LABEL: @test_v4i32_demorgan_or(
85 ; CHECK-NEXT: [[Y_NOT:%.*]] = xor <4 x i32> [[Y:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
86 ; CHECK-NEXT: [[TMP1:%.*]] = and <4 x i32> [[Y_NOT]], [[X:%.*]]
87 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
89 %1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
90 %2 = or <4 x i32> %1, %y
91 %3 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %2
95 ; ~(~X >>s Y) --> (X >>s Y)
97 define <4 x i32> @test_v4i32_not_ashr_not(<4 x i32> %x, <4 x i32> %y) {
98 ; CHECK-LABEL: @test_v4i32_not_ashr_not(
99 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> [[X:%.*]], [[Y:%.*]]
100 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
102 %1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
103 %2 = ashr <4 x i32> %1, %y
104 %3 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %2
108 define <4 x i32> @test_v4i32_not_ashr_not_undef(<4 x i32> %x, <4 x i32> %y) {
109 ; CHECK-LABEL: @test_v4i32_not_ashr_not_undef(
110 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> [[X:%.*]], [[Y:%.*]]
111 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
113 %1 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %x
114 %2 = ashr <4 x i32> %1, %y
115 %3 = xor <4 x i32> <i32 -1, i32 -1, i32 undef, i32 -1>, %2
119 ; ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits)
121 define <4 x i32> @test_v4i32_not_ashr_negative_splatconst(<4 x i32> %a0) {
122 ; CHECK-LABEL: @test_v4i32_not_ashr_negative_splatconst(
123 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 2, i32 2, i32 2>, [[A0:%.*]]
124 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
126 %1 = ashr <4 x i32> <i32 -3, i32 -3, i32 -3, i32 -3>, %a0
127 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
131 define <4 x i32> @test_v4i32_not_ashr_negative_const(<4 x i32> %a0) {
132 ; CHECK-LABEL: @test_v4i32_not_ashr_negative_const(
133 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 4, i32 6, i32 8>, [[A0:%.*]]
134 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
136 %1 = ashr <4 x i32> <i32 -3, i32 -5, i32 -7, i32 -9>, %a0
137 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
141 define <4 x i32> @test_v4i32_not_ashr_negative_const_undef(<4 x i32> %a0) {
142 ; CHECK-LABEL: @test_v4i32_not_ashr_negative_const_undef(
143 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 2, i32 4, i32 undef, i32 8>, [[A0:%.*]]
144 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
146 %1 = ashr <4 x i32> <i32 -3, i32 -5, i32 undef, i32 -9>, %a0
147 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %1
151 ; ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits)
153 define <4 x i32> @test_v4i32_not_lshr_nonnegative_splatconst(<4 x i32> %a0) {
154 ; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_splatconst(
155 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -4, i32 -4, i32 -4>, [[A0:%.*]]
156 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
158 %1 = lshr <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
159 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
163 define <4 x i32> @test_v4i32_not_lshr_nonnegative_const(<4 x i32> %a0) {
164 ; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const(
165 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -6, i32 -8, i32 -10>, [[A0:%.*]]
166 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
168 %1 = lshr <4 x i32> <i32 3, i32 5, i32 7, i32 9>, %a0
169 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
173 define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_undef(<4 x i32> %a0) {
174 ; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const_undef(
175 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> <i32 -4, i32 -6, i32 undef, i32 -10>, [[A0:%.*]]
176 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
178 %1 = lshr <4 x i32> <i32 3, i32 5, i32 undef, i32 9>, %a0
179 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %1
183 ; ~(C-X) == X-C-1 == X+(-C-1)
185 define <4 x i32> @test_v4i32_not_sub_splatconst(<4 x i32> %a0) {
186 ; CHECK-LABEL: @test_v4i32_not_sub_splatconst(
187 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -4, i32 -4, i32 -4, i32 -4>
188 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
190 %1 = sub <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
191 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
195 define <4 x i32> @test_v4i32_not_sub_const(<4 x i32> %a0) {
196 ; CHECK-LABEL: @test_v4i32_not_sub_const(
197 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -4, i32 -6, i32 0, i32 -16>
198 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
200 %1 = sub <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, %a0
201 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %1
205 define <4 x i32> @test_v4i32_not_sub_const_undef(<4 x i32> %a0) {
206 ; CHECK-LABEL: @test_v4i32_not_sub_const_undef(
207 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -4, i32 undef, i32 0, i32 -16>
208 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
210 %1 = sub <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, %a0
211 %2 = xor <4 x i32> <i32 -1, i32 -1, i32 -1, i32 undef>, %1
215 ; (C - X) ^ signmask -> (C + signmask - X)
217 define <4 x i32> @test_v4i32_xor_signmask_sub_splatconst(<4 x i32> %a0) {
218 ; CHECK-LABEL: @test_v4i32_xor_signmask_sub_splatconst(
219 ; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 -2147483645, i32 -2147483645, i32 -2147483645, i32 -2147483645>, [[A0:%.*]]
220 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
222 %1 = sub <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
223 %2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
227 define <4 x i32> @test_v4i32_xor_signmask_sub_const(<4 x i32> %a0) {
228 ; CHECK-LABEL: @test_v4i32_xor_signmask_sub_const(
229 ; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, [[A0:%.*]]
230 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
231 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
233 %1 = sub <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, %a0
234 %2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
238 define <4 x i32> @test_v4i32_xor_signmask_sub_const_undef(<4 x i32> %a0) {
239 ; CHECK-LABEL: @test_v4i32_xor_signmask_sub_const_undef(
240 ; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, [[A0:%.*]]
241 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>
242 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
244 %1 = sub <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, %a0
245 %2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>, %1
249 ; (X + C) ^ signmask -> (X + C + signmask)
251 define <4 x i32> @test_v4i32_xor_signmask_add_splatconst(<4 x i32> %a0) {
252 ; CHECK-LABEL: @test_v4i32_xor_signmask_add_splatconst(
253 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 -2147483645, i32 -2147483645, i32 -2147483645, i32 -2147483645>
254 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
256 %1 = add <4 x i32> <i32 3, i32 3, i32 3, i32 3>, %a0
257 %2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
261 define <4 x i32> @test_v4i32_xor_signmask_add_const(<4 x i32> %a0) {
262 ; CHECK-LABEL: @test_v4i32_xor_signmask_add_const(
263 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 3, i32 5, i32 -1, i32 15>
264 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
265 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
267 %1 = add <4 x i32> <i32 3, i32 5, i32 -1, i32 15>, %a0
268 %2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %1
272 define <4 x i32> @test_v4i32_xor_signmask_add_const_undef(<4 x i32> %a0) {
273 ; CHECK-LABEL: @test_v4i32_xor_signmask_add_const_undef(
274 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[A0:%.*]], <i32 3, i32 undef, i32 -1, i32 15>
275 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>
276 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
278 %1 = add <4 x i32> <i32 3, i32 undef, i32 -1, i32 15>, %a0
279 %2 = xor <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 undef>, %1