1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -reassociate -S | FileCheck %s
3
4; Check that a*c+b*c is turned into (a+b)*c
5
6define <4 x float> @test1(<4 x float> %a, <4 x float> %b, <4 x float> %c) {
7; CHECK-LABEL: @test1(
8; CHECK-NEXT:    [[REASS_ADD:%.*]] = fadd fast <4 x float> [[B:%.*]], [[A:%.*]]
9; CHECK-NEXT:    [[REASS_MUL:%.*]] = fmul fast <4 x float> [[REASS_ADD]], [[C:%.*]]
10; CHECK-NEXT:    ret <4 x float> [[REASS_MUL]]
11;
12  %mul = fmul fast <4 x float> %a, %c
13  %mul1 = fmul fast <4 x float> %b, %c
14  %add = fadd fast <4 x float> %mul, %mul1
15  ret <4 x float> %add
16}
17
18; Check that a*c+b*c is turned into (a+b)*c - minimum FMF subset version
19
20define <4 x float> @test1_reassoc(<4 x float> %a, <4 x float> %b, <4 x float> %c) {
21; CHECK-LABEL: @test1_reassoc(
22; CHECK-NEXT:    [[MUL:%.*]] = fmul reassoc <4 x float> [[A:%.*]], [[C:%.*]]
23; CHECK-NEXT:    [[MUL1:%.*]] = fmul reassoc <4 x float> [[B:%.*]], [[C]]
24; CHECK-NEXT:    [[ADD:%.*]] = fadd reassoc <4 x float> [[MUL]], [[MUL1]]
25; CHECK-NEXT:    ret <4 x float> [[ADD]]
26;
27  %mul = fmul reassoc <4 x float> %a, %c
28  %mul1 = fmul reassoc <4 x float> %b, %c
29  %add = fadd reassoc <4 x float> %mul, %mul1
30  ret <4 x float> %add
31}
32
33; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
34
35define <2 x float> @test2(<2 x float> %a, <2 x float> %b, <2 x float> %c) {
36; CHECK-LABEL: @test2(
37; CHECK-NEXT:    [[REASS_ADD1:%.*]] = fadd fast <2 x float> [[C:%.*]], [[B:%.*]]
38; CHECK-NEXT:    [[REASS_MUL2:%.*]] = fmul fast <2 x float> [[A:%.*]], [[A]]
39; CHECK-NEXT:    [[REASS_MUL:%.*]] = fmul fast <2 x float> [[REASS_MUL2]], [[REASS_ADD1]]
40; CHECK-NEXT:    ret <2 x float> [[REASS_MUL]]
41;
42  %t0 = fmul fast <2 x float> %a, %b
43  %t1 = fmul fast <2 x float> %a, %t0
44  %t2 = fmul fast <2 x float> %a, %c
45  %t3 = fmul fast <2 x float> %a, %t2
46  %t4 = fadd fast <2 x float> %t1, %t3
47  ret <2 x float> %t4
48}
49
50; Check that a*a*b+a*a*c is turned into a*(a*(b+c)) - minimum FMF subset version
51
52define <2 x float> @test2_reassoc(<2 x float> %a, <2 x float> %b, <2 x float> %c) {
53; CHECK-LABEL: @test2_reassoc(
54; CHECK-NEXT:    [[T0:%.*]] = fmul reassoc <2 x float> [[A:%.*]], [[B:%.*]]
55; CHECK-NEXT:    [[T1:%.*]] = fmul reassoc <2 x float> [[A]], [[T0]]
56; CHECK-NEXT:    [[T2:%.*]] = fmul reassoc <2 x float> [[A]], [[C:%.*]]
57; CHECK-NEXT:    [[T3:%.*]] = fmul reassoc <2 x float> [[A]], [[T2]]
58; CHECK-NEXT:    [[T4:%.*]] = fadd reassoc <2 x float> [[T1]], [[T3]]
59; CHECK-NEXT:    ret <2 x float> [[T4]]
60;
61  %t0 = fmul reassoc <2 x float> %a, %b
62  %t1 = fmul reassoc <2 x float> %a, %t0
63  %t2 = fmul reassoc <2 x float> %a, %c
64  %t3 = fmul reassoc <2 x float> %a, %t2
65  %t4 = fadd reassoc <2 x float> %t1, %t3
66  ret <2 x float> %t4
67}
68
69; Check that a*b+a*c+d is turned into a*(b+c)+d.
70
71define <2 x double> @test3(<2 x double> %a, <2 x double> %b, <2 x double> %c, <2 x double> %d) {
72; CHECK-LABEL: @test3(
73; CHECK-NEXT:    [[REASS_ADD:%.*]] = fadd fast <2 x double> [[C:%.*]], [[B:%.*]]
74; CHECK-NEXT:    [[REASS_MUL:%.*]] = fmul fast <2 x double> [[REASS_ADD]], [[A:%.*]]
75; CHECK-NEXT:    [[T3:%.*]] = fadd fast <2 x double> [[REASS_MUL]], [[D:%.*]]
76; CHECK-NEXT:    ret <2 x double> [[T3]]
77;
78  %t0 = fmul fast <2 x double> %a, %b
79  %t1 = fmul fast <2 x double> %a, %c
80  %t2 = fadd fast <2 x double> %t1, %d
81  %t3 = fadd fast <2 x double> %t0, %t2
82  ret <2 x double> %t3
83}
84
85; Check that a*b+a*c+d is turned into a*(b+c)+d - minimum FMF subset version
86
87define <2 x double> @test3_reassoc(<2 x double> %a, <2 x double> %b, <2 x double> %c, <2 x double> %d) {
88; CHECK-LABEL: @test3_reassoc(
89; CHECK-NEXT:    [[T0:%.*]] = fmul reassoc <2 x double> [[A:%.*]], [[B:%.*]]
90; CHECK-NEXT:    [[T1:%.*]] = fmul reassoc <2 x double> [[A]], [[C:%.*]]
91; CHECK-NEXT:    [[T2:%.*]] = fadd reassoc <2 x double> [[T1]], [[D:%.*]]
92; CHECK-NEXT:    [[T3:%.*]] = fadd reassoc <2 x double> [[T0]], [[T2]]
93; CHECK-NEXT:    ret <2 x double> [[T3]]
94;
95  %t0 = fmul reassoc <2 x double> %a, %b
96  %t1 = fmul reassoc <2 x double> %a, %c
97  %t2 = fadd reassoc <2 x double> %t1, %d
98  %t3 = fadd reassoc <2 x double> %t0, %t2
99  ret <2 x double> %t3
100}
101
102; No fast-math.
103
104define <2 x float> @test4(<2 x float> %A) {
105; CHECK-LABEL: @test4(
106; CHECK-NEXT:    [[X:%.*]] = fadd <2 x float> [[A:%.*]], <float 1.000000e+00, float 1.000000e+00>
107; CHECK-NEXT:    [[Y:%.*]] = fadd <2 x float> [[A]], <float 1.000000e+00, float 1.000000e+00>
108; CHECK-NEXT:    [[R:%.*]] = fsub <2 x float> [[X]], [[Y]]
109; CHECK-NEXT:    ret <2 x float> [[R]]
110;
111  %X = fadd <2 x float> %A, < float 1.000000e+00, float 1.000000e+00 >
112  %Y = fadd <2 x float> %A, < float 1.000000e+00, float 1.000000e+00 >
113  %R = fsub <2 x float> %X, %Y
114  ret <2 x float> %R
115}
116
117; Check 47*X + 47*X -> 94*X.
118
119define <2 x float> @test5(<2 x float> %X) {
120; CHECK-LABEL: @test5(
121; CHECK-NEXT:    [[FACTOR:%.*]] = fmul fast <2 x float> [[X:%.*]], <float 9.400000e+01, float 9.400000e+01>
122; CHECK-NEXT:    ret <2 x float> [[FACTOR]]
123;
124  %Y = fmul fast <2 x float> %X, <float 4.700000e+01, float 4.700000e+01>
125  %Z = fadd fast <2 x float> %Y, %Y
126  ret <2 x float> %Z
127}
128
129; Check 47*X + 47*X -> 94*X - minimum FMF subset version
130
131define <2 x float> @test5_reassoc(<2 x float> %X) {
132; CHECK-LABEL: @test5_reassoc(
133; CHECK-NEXT:    [[Y:%.*]] = fmul reassoc <2 x float> [[X:%.*]], <float 4.700000e+01, float 4.700000e+01>
134; CHECK-NEXT:    [[Z:%.*]] = fadd reassoc <2 x float> [[Y]], [[Y]]
135; CHECK-NEXT:    ret <2 x float> [[Z]]
136;
137  %Y = fmul reassoc <2 x float> %X, <float 4.700000e+01, float 4.700000e+01>
138  %Z = fadd reassoc <2 x float> %Y, %Y
139  ret <2 x float> %Z
140}
141
142; Check X+X+X -> 3*X.
143
144define <2 x float> @test6(<2 x float> %X) {
145; CHECK-LABEL: @test6(
146; CHECK-NEXT:    [[FACTOR:%.*]] = fmul fast <2 x float> [[X:%.*]], <float 3.000000e+00, float 3.000000e+00>
147; CHECK-NEXT:    ret <2 x float> [[FACTOR]]
148;
149  %Y = fadd fast <2 x float> %X ,%X
150  %Z = fadd fast <2 x float> %Y, %X
151  ret <2 x float> %Z
152}
153
154; Check X+X+X -> 3*X - minimum FMF subset version
155
156define <2 x float> @test6_reassoc(<2 x float> %X) {
157; CHECK-LABEL: @test6_reassoc(
158; CHECK-NEXT:    [[Y:%.*]] = fadd reassoc <2 x float> [[X:%.*]], [[X]]
159; CHECK-NEXT:    [[Z:%.*]] = fadd reassoc <2 x float> [[X]], [[Y]]
160; CHECK-NEXT:    ret <2 x float> [[Z]]
161;
162  %Y = fadd reassoc <2 x float> %X ,%X
163  %Z = fadd reassoc <2 x float> %Y, %X
164  ret <2 x float> %Z
165}
166
167; Check 127*W+50*W -> 177*W.
168
169define <2 x double> @test7(<2 x double> %W) {
170; CHECK-LABEL: @test7(
171; CHECK-NEXT:    [[REASS_MUL:%.*]] = fmul fast <2 x double> [[W:%.*]], <double 1.770000e+02, double 1.770000e+02>
172; CHECK-NEXT:    ret <2 x double> [[REASS_MUL]]
173;
174  %X = fmul fast <2 x double> %W, <double 127.0, double 127.0>
175  %Y = fmul fast <2 x double> %W, <double 50.0, double 50.0>
176  %Z = fadd fast <2 x double> %Y, %X
177  ret <2 x double> %Z
178}
179
180; Check 127*W+50*W -> 177*W - minimum FMF subset version
181
182define <2 x double> @test7_reassoc(<2 x double> %W) {
183; CHECK-LABEL: @test7_reassoc(
184; CHECK-NEXT:    [[X:%.*]] = fmul reassoc <2 x double> [[W:%.*]], <double 1.270000e+02, double 1.270000e+02>
185; CHECK-NEXT:    [[Y:%.*]] = fmul reassoc <2 x double> [[W]], <double 5.000000e+01, double 5.000000e+01>
186; CHECK-NEXT:    [[Z:%.*]] = fadd reassoc <2 x double> [[Y]], [[X]]
187; CHECK-NEXT:    ret <2 x double> [[Z]]
188;
189  %X = fmul reassoc <2 x double> %W, <double 127.0, double 127.0>
190  %Y = fmul reassoc <2 x double> %W, <double 50.0, double 50.0>
191  %Z = fadd reassoc <2 x double> %Y, %X
192  ret <2 x double> %Z
193}
194
195; Check X*12*12 -> X*144.
196
197define <2 x float> @test8(<2 x float> %arg) {
198; CHECK-LABEL: @test8(
199; CHECK-NEXT:    [[TMP2:%.*]] = fmul fast <2 x float> [[ARG:%.*]], <float 1.440000e+02, float 1.440000e+02>
200; CHECK-NEXT:    ret <2 x float> [[TMP2]]
201;
202  %tmp1 = fmul fast <2 x float> <float 1.200000e+01, float 1.200000e+01>, %arg
203  %tmp2 = fmul fast <2 x float> %tmp1, <float 1.200000e+01, float 1.200000e+01>
204  ret <2 x float> %tmp2
205}
206
207; Check X*12*12 -> X*144 - minimum FMF subset version
208
209define <2 x float> @test8_reassoc(<2 x float> %arg) {
210; CHECK-LABEL: @test8_reassoc(
211; CHECK-NEXT:    [[TMP1:%.*]] = fmul reassoc <2 x float> [[ARG:%.*]], <float 1.200000e+01, float 1.200000e+01>
212; CHECK-NEXT:    [[TMP2:%.*]] = fmul reassoc <2 x float> [[TMP1]], <float 1.200000e+01, float 1.200000e+01>
213; CHECK-NEXT:    ret <2 x float> [[TMP2]]
214;
215  %tmp1 = fmul reassoc <2 x float> <float 1.200000e+01, float 1.200000e+01>, %arg
216  %tmp2 = fmul reassoc <2 x float> %tmp1, <float 1.200000e+01, float 1.200000e+01>
217  ret <2 x float> %tmp2
218}
219
220; Check (b+(a+1234))+-a -> b+1234.
221
222define <2 x double> @test9(<2 x double> %b, <2 x double> %a) {
223; CHECK-LABEL: @test9(
224; CHECK-NEXT:    [[TMP1:%.*]] = fsub fast <2 x double> zeroinitializer, [[A:%.*]]
225; CHECK-NEXT:    [[TMP2:%.*]] = fadd fast <2 x double> [[B:%.*]], <double 1.234000e+03, double 1.234000e+03>
226; CHECK-NEXT:    ret <2 x double> [[TMP2]]
227;
228  %1 = fadd fast <2 x double> %a, <double 1.234000e+03, double 1.234000e+03>
229  %2 = fadd fast <2 x double> %b, %1
230  %3 = fsub fast <2 x double> <double 0.000000e+00, double 0.000000e+00>, %a
231  %4 = fadd fast <2 x double> %2, %3
232  ret <2 x double> %4
233}
234
235define <2 x double> @test9_unary_fneg(<2 x double> %b, <2 x double> %a) {
236; CHECK-LABEL: @test9_unary_fneg(
237; CHECK-NEXT:    [[TMP1:%.*]] = fneg fast <2 x double> [[A:%.*]]
238; CHECK-NEXT:    [[TMP2:%.*]] = fadd fast <2 x double> [[B:%.*]], <double 1.234000e+03, double 1.234000e+03>
239; CHECK-NEXT:    ret <2 x double> [[TMP2]]
240;
241  %1 = fadd fast <2 x double> %a, <double 1.234000e+03, double 1.234000e+03>
242  %2 = fadd fast <2 x double> %b, %1
243  %3 = fneg fast <2 x double> %a
244  %4 = fadd fast <2 x double> %2, %3
245  ret <2 x double> %4
246}
247
248; Check (b+(a+1234))+-a -> b+1234 - minimum FMF subset version
249
250define <2 x double> @test9_reassoc(<2 x double> %b, <2 x double> %a) {
251; CHECK-LABEL: @test9_reassoc(
252; CHECK-NEXT:    [[TMP1:%.*]] = fadd reassoc <2 x double> [[A:%.*]], <double 1.234000e+03, double 1.234000e+03>
253; CHECK-NEXT:    [[TMP2:%.*]] = fadd reassoc <2 x double> [[B:%.*]], [[TMP1]]
254; CHECK-NEXT:    [[TMP3:%.*]] = fsub reassoc <2 x double> zeroinitializer, [[A]]
255; CHECK-NEXT:    [[TMP4:%.*]] = fadd reassoc <2 x double> [[TMP3]], [[TMP2]]
256; CHECK-NEXT:    ret <2 x double> [[TMP4]]
257;
258  %1 = fadd reassoc <2 x double> %a, <double 1.234000e+03, double 1.234000e+03>
259  %2 = fadd reassoc <2 x double> %b, %1
260  %3 = fsub reassoc <2 x double> <double 0.000000e+00, double 0.000000e+00>, %a
261  %4 = fadd reassoc <2 x double> %2, %3
262  ret <2 x double> %4
263}
264
265define <2 x double> @test9_reassoc_unary_fneg(<2 x double> %b, <2 x double> %a) {
266; CHECK-LABEL: @test9_reassoc_unary_fneg(
267; CHECK-NEXT:    [[TMP1:%.*]] = fadd reassoc <2 x double> [[A:%.*]], <double 1.234000e+03, double 1.234000e+03>
268; CHECK-NEXT:    [[TMP2:%.*]] = fadd reassoc <2 x double> [[B:%.*]], [[TMP1]]
269; CHECK-NEXT:    [[TMP3:%.*]] = fneg reassoc <2 x double> [[A]]
270; CHECK-NEXT:    [[TMP4:%.*]] = fadd reassoc <2 x double> [[TMP3]], [[TMP2]]
271; CHECK-NEXT:    ret <2 x double> [[TMP4]]
272;
273  %1 = fadd reassoc <2 x double> %a, <double 1.234000e+03, double 1.234000e+03>
274  %2 = fadd reassoc <2 x double> %b, %1
275  %3 = fneg reassoc <2 x double> %a
276  %4 = fadd reassoc <2 x double> %2, %3
277  ret <2 x double> %4
278}
279
280; Check -(-(z*40)*a) -> a*40*z.
281
282define <2 x float> @test10(<2 x float> %a, <2 x float> %b, <2 x float> %z) {
283; CHECK-LABEL: @test10(
284; CHECK-NEXT:    [[TMP1:%.*]] = fsub fast <2 x float> zeroinitializer, zeroinitializer
285; CHECK-NEXT:    [[E:%.*]] = fmul fast <2 x float> [[A:%.*]], <float 4.000000e+01, float 4.000000e+01>
286; CHECK-NEXT:    [[F:%.*]] = fmul fast <2 x float> [[E]], [[Z:%.*]]
287; CHECK-NEXT:    ret <2 x float> [[F]]
288;
289  %d = fmul fast <2 x float> %z, <float 4.000000e+01, float 4.000000e+01>
290  %c = fsub fast <2 x float> <float 0.000000e+00, float 0.000000e+00>, %d
291  %e = fmul fast <2 x float> %a, %c
292  %f = fsub fast <2 x float> <float 0.000000e+00, float 0.000000e+00>, %e
293  ret <2 x float> %f
294}
295
296define <2 x float> @test10_unary_fneg(<2 x float> %a, <2 x float> %b, <2 x float> %z) {
297; CHECK-LABEL: @test10_unary_fneg(
298; CHECK-NEXT:    [[TMP1:%.*]] = fneg fast <2 x float> zeroinitializer
299; CHECK-NEXT:    [[E:%.*]] = fmul fast <2 x float> [[A:%.*]], <float 4.000000e+01, float 4.000000e+01>
300; CHECK-NEXT:    [[F:%.*]] = fmul fast <2 x float> [[E]], [[Z:%.*]]
301; CHECK-NEXT:    ret <2 x float> [[F]]
302;
303  %d = fmul fast <2 x float> %z, <float 4.000000e+01, float 4.000000e+01>
304  %c = fneg fast <2 x float> %d
305  %e = fmul fast <2 x float> %a, %c
306  %f = fneg fast <2 x float> %e
307  ret <2 x float> %f
308}
309
310; Check -(-(z*40)*a) -> a*40*z - minimum FMF subset version
311
312define <2 x float> @test10_reassoc(<2 x float> %a, <2 x float> %b, <2 x float> %z) {
313; CHECK-LABEL: @test10_reassoc(
314; CHECK-NEXT:    [[D:%.*]] = fmul reassoc <2 x float> [[Z:%.*]], <float 4.000000e+01, float 4.000000e+01>
315; CHECK-NEXT:    [[C:%.*]] = fsub reassoc <2 x float> zeroinitializer, [[D]]
316; CHECK-NEXT:    [[E:%.*]] = fmul reassoc <2 x float> [[A:%.*]], [[C]]
317; CHECK-NEXT:    [[F:%.*]] = fsub reassoc <2 x float> zeroinitializer, [[E]]
318; CHECK-NEXT:    ret <2 x float> [[F]]
319;
320  %d = fmul reassoc <2 x float> %z, <float 4.000000e+01, float 4.000000e+01>
321  %c = fsub reassoc <2 x float> <float 0.000000e+00, float 0.000000e+00>, %d
322  %e = fmul reassoc <2 x float> %a, %c
323  %f = fsub reassoc <2 x float> <float 0.000000e+00, float 0.000000e+00>, %e
324  ret <2 x float> %f
325}
326
327define <2 x float> @test10_reassoc_unary_fneg(<2 x float> %a, <2 x float> %b, <2 x float> %z) {
328; CHECK-LABEL: @test10_reassoc_unary_fneg(
329; CHECK-NEXT:    [[D:%.*]] = fmul reassoc <2 x float> [[Z:%.*]], <float 4.000000e+01, float 4.000000e+01>
330; CHECK-NEXT:    [[C:%.*]] = fneg reassoc <2 x float> [[D]]
331; CHECK-NEXT:    [[E:%.*]] = fmul reassoc <2 x float> [[A:%.*]], [[C]]
332; CHECK-NEXT:    [[F:%.*]] = fneg reassoc <2 x float> [[E]]
333; CHECK-NEXT:    ret <2 x float> [[F]]
334;
335  %d = fmul reassoc <2 x float> %z, <float 4.000000e+01, float 4.000000e+01>
336  %c = fneg reassoc <2 x float> %d
337  %e = fmul reassoc <2 x float> %a, %c
338  %f = fneg reassoc <2 x float> %e
339  ret <2 x float> %f
340}
341
342; Check x*y+y*x -> x*y*2.
343
344define <2 x double> @test11(<2 x double> %x, <2 x double> %y) {
345; CHECK-LABEL: @test11(
346; CHECK-NEXT:    [[FACTOR:%.*]] = fmul fast <2 x double> [[X:%.*]], [[Y:%.*]]
347; CHECK-NEXT:    [[REASS_MUL:%.*]] = fmul fast <2 x double> [[FACTOR]], <double 2.000000e+00, double 2.000000e+00>
348; CHECK-NEXT:    ret <2 x double> [[REASS_MUL]]
349;
350  %1 = fmul fast <2 x double> %x, %y
351  %2 = fmul fast <2 x double> %y, %x
352  %3 = fadd fast <2 x double> %1, %2
353  ret <2 x double> %3
354}
355
356; Check x*y+y*x -> x*y*2 - minimum FMF subset version
357
358define <2 x double> @test11_reassoc(<2 x double> %x, <2 x double> %y) {
359; CHECK-LABEL: @test11_reassoc(
360; CHECK-NEXT:    [[TMP1:%.*]] = fmul reassoc <2 x double> [[X:%.*]], [[Y:%.*]]
361; CHECK-NEXT:    [[TMP2:%.*]] = fmul reassoc <2 x double> [[X]], [[Y]]
362; CHECK-NEXT:    [[TMP3:%.*]] = fadd reassoc <2 x double> [[TMP1]], [[TMP2]]
363; CHECK-NEXT:    ret <2 x double> [[TMP3]]
364;
365  %1 = fmul reassoc <2 x double> %x, %y
366  %2 = fmul reassoc <2 x double> %y, %x
367  %3 = fadd reassoc <2 x double> %1, %2
368  ret <2 x double> %3
369}
370
371; FIXME: shifts should be converted to mul to assist further reassociation.
372
373define <2 x i64> @test12(<2 x i64> %b, <2 x i64> %c) {
374; CHECK-LABEL: @test12(
375; CHECK-NEXT:    [[MUL:%.*]] = mul <2 x i64> [[C:%.*]], [[B:%.*]]
376; CHECK-NEXT:    [[SHL:%.*]] = shl <2 x i64> [[MUL]], <i64 5, i64 5>
377; CHECK-NEXT:    ret <2 x i64> [[SHL]]
378;
379  %mul = mul <2 x i64> %c, %b
380  %shl = shl <2 x i64> %mul, <i64 5, i64 5>
381  ret <2 x i64> %shl
382}
383
384; FIXME: expressions with a negative const should be canonicalized to assist
385; further reassociation.
386; We would expect (-5*b)+a -> a-(5*b) but only the constant operand is commuted.
387
388define <4 x float> @test13(<4 x float> %a, <4 x float> %b) {
389; CHECK-LABEL: @test13(
390; CHECK-NEXT:    [[MUL:%.*]] = fmul fast <4 x float> [[B:%.*]], <float -5.000000e+00, float -5.000000e+00, float -5.000000e+00, float -5.000000e+00>
391; CHECK-NEXT:    [[ADD:%.*]] = fadd fast <4 x float> [[MUL]], [[A:%.*]]
392; CHECK-NEXT:    ret <4 x float> [[ADD]]
393;
394  %mul = fmul fast <4 x float> <float -5.000000e+00, float -5.000000e+00, float -5.000000e+00, float -5.000000e+00>, %b
395  %add = fadd fast <4 x float> %mul, %a
396  ret <4 x float> %add
397}
398
399; Break up subtract to assist further reassociation.
400; Check a+b-c -> a+b+-c.
401
402define <2 x i64> @test14(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c) {
403; CHECK-LABEL: @test14(
404; CHECK-NEXT:    [[ADD:%.*]] = add <2 x i64> [[B:%.*]], [[A:%.*]]
405; CHECK-NEXT:    [[C_NEG:%.*]] = sub <2 x i64> zeroinitializer, [[C:%.*]]
406; CHECK-NEXT:    [[SUB:%.*]] = add <2 x i64> [[ADD]], [[C_NEG]]
407; CHECK-NEXT:    ret <2 x i64> [[SUB]]
408;
409  %add = add <2 x i64> %b, %a
410  %sub = sub <2 x i64> %add, %c
411  ret <2 x i64> %sub
412}
413
414define <2 x i32> @test15(<2 x i32> %x, <2 x i32> %y) {
415; CHECK-LABEL: @test15(
416; CHECK-NEXT:    [[TMP3:%.*]] = and <2 x i32> [[Y:%.*]], [[X:%.*]]
417; CHECK-NEXT:    ret <2 x i32> [[TMP3]]
418;
419  %tmp1 = and <2 x i32> %x, %y
420  %tmp2 = and <2 x i32> %y, %x
421  %tmp3 = and <2 x i32> %tmp1, %tmp2
422  ret <2 x i32> %tmp3
423}
424
425define <2 x i32> @test16(<2 x i32> %x, <2 x i32> %y) {
426; CHECK-LABEL: @test16(
427; CHECK-NEXT:    [[TMP3:%.*]] = or <2 x i32> [[Y:%.*]], [[X:%.*]]
428; CHECK-NEXT:    ret <2 x i32> [[TMP3]]
429;
430  %tmp1 = or <2 x i32> %x, %y
431  %tmp2 = or <2 x i32> %y, %x
432  %tmp3 = or <2 x i32> %tmp1, %tmp2
433  ret <2 x i32> %tmp3
434}
435
436define <2 x i32> @test17(<2 x i32> %x, <2 x i32> %y) {
437; CHECK-LABEL: @test17(
438; CHECK-NEXT:    ret <2 x i32> zeroinitializer
439;
440  %tmp1 = xor <2 x i32> %x, %y
441  %tmp2 = xor <2 x i32> %y, %x
442  %tmp3 = xor <2 x i32> %tmp1, %tmp2
443  ret <2 x i32> %tmp3
444}
445
446define <2 x i32> @test18(<2 x i32> %x, <2 x i32> %y) {
447; CHECK-LABEL: @test18(
448; CHECK-NEXT:    [[TMP5:%.*]] = xor <2 x i32> [[Y:%.*]], [[X:%.*]]
449; CHECK-NEXT:    ret <2 x i32> [[TMP5]]
450;
451  %tmp1 = xor <2 x i32> %x, %y
452  %tmp2 = xor <2 x i32> %y, %x
453  %tmp3 = xor <2 x i32> %x, %y
454  %tmp4 = xor <2 x i32> %tmp1, %tmp2
455  %tmp5 = xor <2 x i32> %tmp4, %tmp3
456  ret <2 x i32> %tmp5
457}
458