llvm.org GIT mirror llvm / 884000e
[Tests] Autogen a bunch of Reassociate tests for ease of update git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367634 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames a month ago
18 changed file(s) with 385 addition(s) and 253 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s
12
23 define i32 @test1(i32 %A, i32 %B) {
3 ; CHECK-LABEL: test1
4 ; CHECK: %Z = add i32 %B, %A
5 ; CHECK: ret i32 %Z
6 %W = add i32 %B, -5
7 %Y = add i32 %A, 5
8 %Z = add i32 %W, %Y
9 ret i32 %Z
4 ; CHECK-LABEL: @test1(
5 ; CHECK-NEXT: [[Z:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
6 ; CHECK-NEXT: ret i32 [[Z]]
7 ;
8 %W = add i32 %B, -5
9 %Y = add i32 %A, 5
10 %Z = add i32 %W, %Y
11 ret i32 %Z
1012 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -constprop -instcombine -dce -S | FileCheck %s
12
23 ; With sub reassociation, constant folding can eliminate all of the constants.
34 define i32 @test1(i32 %A, i32 %B) {
45 ; CHECK-LABEL: @test1(
5 ; CHECK-NEXT: [[Z:%.*]] = sub i32 %A, %B
6 ; CHECK-NEXT: [[Z:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]
67 ; CHECK-NEXT: ret i32 [[Z]]
78 ;
89 %W = add i32 5, %B
1516 ; With sub reassociation, constant folding can eliminate the two 12 constants.
1617 define i32 @test2(i32 %A, i32 %B, i32 %C, i32 %D) {
1718 ; CHECK-LABEL: @test2(
18 ; CHECK-NEXT: [[SUM:%.*]] = add i32 %B, %A
19 ; CHECK-NEXT: [[SUM1:%.*]] = add i32 [[SUM]], %C
20 ; CHECK-NEXT: [[Q:%.*]] = sub i32 %D, [[SUM1]]
19 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
20 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], [[C:%.*]]
21 ; CHECK-NEXT: [[Q:%.*]] = sub i32 [[D:%.*]], [[TMP2]]
2122 ; CHECK-NEXT: ret i32 [[Q]]
2223 ;
2324 %M = add i32 %A, 12
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -reassociate -gvn -S < %s | FileCheck %s
12
23 ; (x + 0.1234 * y) * (x + -0.1234 * y) -> (x + 0.1234 * y) * (x - 0.1234 * y)
34 define double @test1(double %x, double %y) {
45 ; CHECK-LABEL: @test1(
5 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, 1.234000e-01
6 ; CHECK-NEXT: [[ADD:%.*]] = fadd double %x, [[MUL]]
7 ; CHECK-NEXT: [[ADD21:%.*]] = fsub double %x, [[MUL]]
6 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], 1.234000e-01
7 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[X:%.*]], [[MUL]]
8 ; CHECK-NEXT: [[ADD21:%.*]] = fsub double [[X]], [[MUL]]
89 ; CHECK-NEXT: [[MUL3:%.*]] = fmul double [[ADD]], [[ADD21]]
910 ; CHECK-NEXT: ret double [[MUL3]]
1011 ;
1920 ; (x + -0.1234 * y) * (x + -0.1234 * y) -> (x - 0.1234 * y) * (x - 0.1234 * y)
2021 define double @test2(double %x, double %y) {
2122 ; CHECK-LABEL: @test2(
22 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, 1.234000e-01
23 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double %x, [[MUL]]
23 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], 1.234000e-01
24 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double [[X:%.*]], [[MUL]]
2425 ; CHECK-NEXT: [[MUL3:%.*]] = fmul double [[ADD1]], [[ADD1]]
2526 ; CHECK-NEXT: ret double [[MUL3]]
2627 ;
3536 ; (x + 0.1234 * y) * (x - -0.1234 * y) -> (x + 0.1234 * y) * (x + 0.1234 * y)
3637 define double @test3(double %x, double %y) {
3738 ; CHECK-LABEL: @test3(
38 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, 1.234000e-01
39 ; CHECK-NEXT: [[ADD:%.*]] = fadd double %x, [[MUL]]
39 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], 1.234000e-01
40 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[X:%.*]], [[MUL]]
4041 ; CHECK-NEXT: [[MUL3:%.*]] = fmul double [[ADD]], [[ADD]]
4142 ; CHECK-NEXT: ret double [[MUL3]]
4243 ;
5152 ; Canonicalize (x - -0.1234 * y)
5253 define double @test5(double %x, double %y) {
5354 ; CHECK-LABEL: @test5(
54 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, 1.234000e-01
55 ; CHECK-NEXT: [[SUB1:%.*]] = fadd double %x, [[MUL]]
55 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], 1.234000e-01
56 ; CHECK-NEXT: [[SUB1:%.*]] = fadd double [[X:%.*]], [[MUL]]
5657 ; CHECK-NEXT: ret double [[SUB1]]
5758 ;
5859 %mul = fmul double -1.234000e-01, %y
6364 ; Don't modify (-0.1234 * y - x)
6465 define double @test6(double %x, double %y) {
6566 ; CHECK-LABEL: @test6(
66 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, -1.234000e-01
67 ; CHECK-NEXT: [[SUB:%.*]] = fsub double [[MUL]], %x
67 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], -1.234000e-01
68 ; CHECK-NEXT: [[SUB:%.*]] = fsub double [[MUL]], [[X:%.*]]
6869 ; CHECK-NEXT: ret double [[SUB]]
6970 ;
7071 %mul = fmul double -1.234000e-01, %y
7576 ; Canonicalize (-0.1234 * y + x) -> (x - 0.1234 * y)
7677 define double @test7(double %x, double %y) {
7778 ; CHECK-LABEL: @test7(
78 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, 1.234000e-01
79 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double %x, [[MUL]]
79 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], 1.234000e-01
80 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double [[X:%.*]], [[MUL]]
8081 ; CHECK-NEXT: ret double [[ADD1]]
8182 ;
8283 %mul = fmul double -1.234000e-01, %y
8788 ; Canonicalize (y * -0.1234 + x) -> (x - 0.1234 * y)
8889 define double @test8(double %x, double %y) {
8990 ; CHECK-LABEL: @test8(
90 ; CHECK-NEXT: [[MUL:%.*]] = fmul double %y, 1.234000e-01
91 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double %x, [[MUL]]
91 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[Y:%.*]], 1.234000e-01
92 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double [[X:%.*]], [[MUL]]
9293 ; CHECK-NEXT: ret double [[ADD1]]
9394 ;
9495 %mul = fmul double %y, -1.234000e-01
99100 ; Canonicalize (x - -0.1234 / y)
100101 define double @test9(double %x, double %y) {
101102 ; CHECK-LABEL: @test9(
102 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double 1.234000e-01, %y
103 ; CHECK-NEXT: [[SUB1:%.*]] = fadd double %x, [[DIV]]
103 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double 1.234000e-01, [[Y:%.*]]
104 ; CHECK-NEXT: [[SUB1:%.*]] = fadd double [[X:%.*]], [[DIV]]
104105 ; CHECK-NEXT: ret double [[SUB1]]
105106 ;
106107 %div = fdiv double -1.234000e-01, %y
111112 ; Don't modify (-0.1234 / y - x)
112113 define double @test10(double %x, double %y) {
113114 ; CHECK-LABEL: @test10(
114 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double -1.234000e-01, %y
115 ; CHECK-NEXT: [[SUB:%.*]] = fsub double [[DIV]], %x
115 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double -1.234000e-01, [[Y:%.*]]
116 ; CHECK-NEXT: [[SUB:%.*]] = fsub double [[DIV]], [[X:%.*]]
116117 ; CHECK-NEXT: ret double [[SUB]]
117118 ;
118119 %div = fdiv double -1.234000e-01, %y
123124 ; Canonicalize (-0.1234 / y + x) -> (x - 0.1234 / y)
124125 define double @test11(double %x, double %y) {
125126 ; CHECK-LABEL: @test11(
126 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double 1.234000e-01, %y
127 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double %x, [[DIV]]
127 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double 1.234000e-01, [[Y:%.*]]
128 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double [[X:%.*]], [[DIV]]
128129 ; CHECK-NEXT: ret double [[ADD1]]
129130 ;
130131 %div = fdiv double -1.234000e-01, %y
135136 ; Canonicalize (y / -0.1234 + x) -> (x - y / 0.1234)
136137 define double @test12(double %x, double %y) {
137138 ; CHECK-LABEL: @test12(
138 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double %y, 1.234000e-01
139 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double %x, [[DIV]]
139 ; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[Y:%.*]], 1.234000e-01
140 ; CHECK-NEXT: [[ADD1:%.*]] = fsub double [[X:%.*]], [[DIV]]
140141 ; CHECK-NEXT: ret double [[ADD1]]
141142 ;
142143 %div = fdiv double %y, -1.234000e-01
147148 ; Don't create an NSW violation
148149 define i4 @test13(i4 %x) {
149150 ; CHECK-LABEL: @test13(
150 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i4 %x, -2
151 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i4 [[X:%.*]], -2
151152 ; CHECK-NEXT: [[ADD:%.*]] = add i4 [[MUL]], 3
152153 ; CHECK-NEXT: ret i4 [[ADD]]
153154 ;
168169
169170 define double @pr34078(double %A) {
170171 ; CHECK-LABEL: @pr34078(
171 ; CHECK-NEXT: [[SUB:%.*]] = fsub fast double 1.000000e+00, %A
172 ; CHECK-NEXT: [[POW2:%.*]] = fmul double %A, %A
172 ; CHECK-NEXT: [[SUB:%.*]] = fsub fast double 1.000000e+00, [[A:%.*]]
173 ; CHECK-NEXT: [[POW2:%.*]] = fmul double [[A]], [[A]]
173174 ; CHECK-NEXT: [[MUL5_NEG:%.*]] = fmul fast double [[POW2]], -5.000000e-01
174175 ; CHECK-NEXT: [[SUB1:%.*]] = fadd fast double [[MUL5_NEG]], [[SUB]]
175176 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast double [[SUB1]], 2.000000e+00
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -reassociate -S < %s | FileCheck %s
12
23 declare void @use(i32)
34
45 define void @test1(i32 %x, i32 %y) {
5 ; CHECK-LABEL: test1
6 ; CHECK: mul i32 %y, %x
7 ; CHECK: mul i32 %y, %x
8 ; CHECK: sub i32 %1, %2
9 ; CHECK: call void @use(i32 %{{.*}})
10 ; CHECK: call void @use(i32 %{{.*}})
6 ; CHECK-LABEL: @test1(
7 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[Y:%.*]], [[X:%.*]]
8 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[Y]], [[X]]
9 ; CHECK-NEXT: [[TMP3:%.*]] = sub i32 [[TMP1]], [[TMP2]]
10 ; CHECK-NEXT: call void @use(i32 [[TMP1]])
11 ; CHECK-NEXT: call void @use(i32 [[TMP3]])
12 ; CHECK-NEXT: ret void
13 ;
1114
1215 %1 = mul i32 %x, %y
1316 %2 = mul i32 %y, %x
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -constprop -instcombine -S | FileCheck %s
12
23 define float @test1(float %A, float %B) {
34 ; CHECK-LABEL: @test1(
4 ; CHECK-NEXT: [[W:%.*]] = fadd float %B, 5.000000e+00
5 ; CHECK-NEXT: [[X:%.*]] = fadd float %A, -7.000000e+00
5 ; CHECK-NEXT: [[W:%.*]] = fadd float [[B:%.*]], 5.000000e+00
6 ; CHECK-NEXT: [[X:%.*]] = fadd float [[A:%.*]], -7.000000e+00
67 ; CHECK-NEXT: [[Y:%.*]] = fsub float [[X]], [[W]]
78 ; CHECK-NEXT: [[Z:%.*]] = fadd float [[Y]], 1.200000e+01
89 ; CHECK-NEXT: ret float [[Z]]
1718 ; With sub reassociation, constant folding can eliminate all of the constants.
1819 define float @test2(float %A, float %B) {
1920 ; CHECK-LABEL: @test2(
20 ; CHECK-NEXT: [[Z:%.*]] = fsub fast float %A, %B
21 ; CHECK-NEXT: [[Z:%.*]] = fsub fast float [[A:%.*]], [[B:%.*]]
2122 ; CHECK-NEXT: ret float [[Z]]
2223 ;
2324 %W = fadd fast float %B, 5.000000e+00
3132 ; Both 'reassoc' and 'nsz' are required.
3233 define float @test2_minimal(float %A, float %B) {
3334 ; CHECK-LABEL: @test2_minimal(
34 ; CHECK-NEXT: [[Z:%.*]] = fsub reassoc nsz float %A, %B
35 ; CHECK-NEXT: ret float [[Z]]
35 ; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[A:%.*]], [[B:%.*]]
36 ; CHECK-NEXT: ret float [[TMP1]]
3637 ;
3738 %W = fadd reassoc nsz float %B, 5.000000e+00
3839 %X = fadd reassoc nsz float %A, -7.000000e+00
4445 ; Verify the fold is not done with only 'reassoc' ('nsz' is required).
4546 define float @test2_reassoc(float %A, float %B) {
4647 ; CHECK-LABEL: @test2_reassoc(
47 ; CHECK-NEXT: [[W:%.*]] = fadd reassoc float %B, 5.000000e+00
48 ; CHECK-NEXT: [[X:%.*]] = fadd reassoc float %A, -7.000000e+00
48 ; CHECK-NEXT: [[W:%.*]] = fadd reassoc float [[B:%.*]], 5.000000e+00
49 ; CHECK-NEXT: [[X:%.*]] = fadd reassoc float [[A:%.*]], -7.000000e+00
4950 ; CHECK-NEXT: [[Y:%.*]] = fsub reassoc float [[X]], [[W]]
5051 ; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[Y]], 1.200000e+01
5152 ; CHECK-NEXT: ret float [[Z]]
5960
6061 define float @test3(float %A, float %B, float %C, float %D) {
6162 ; CHECK-LABEL: @test3(
62 ; CHECK-NEXT: [[M:%.*]] = fadd float %A, 1.200000e+01
63 ; CHECK-NEXT: [[N:%.*]] = fadd float [[M]], %B
64 ; CHECK-NEXT: [[O:%.*]] = fadd float [[N]], %C
65 ; CHECK-NEXT: [[P:%.*]] = fsub float %D, [[O]]
63 ; CHECK-NEXT: [[M:%.*]] = fadd float [[A:%.*]], 1.200000e+01
64 ; CHECK-NEXT: [[N:%.*]] = fadd float [[M]], [[B:%.*]]
65 ; CHECK-NEXT: [[O:%.*]] = fadd float [[N]], [[C:%.*]]
66 ; CHECK-NEXT: [[P:%.*]] = fsub float [[D:%.*]], [[O]]
6667 ; CHECK-NEXT: [[Q:%.*]] = fadd float [[P]], 1.200000e+01
6768 ; CHECK-NEXT: ret float [[Q]]
6869 ;
8384 ; %Q = fsub fast float %D, %sum1
8485 ; ret i32 %Q
8586 ; CHECK-LABEL: @test4(
86 ; CHECK-NEXT: [[B_NEG:%.*]] = fsub fast float -0.000000e+00, %B
87 ; CHECK-NEXT: [[O_NEG:%.*]] = fsub fast float [[B_NEG]], %A
88 ; CHECK-NEXT: [[P:%.*]] = fsub fast float [[O_NEG]], %C
89 ; CHECK-NEXT: [[Q:%.*]] = fadd fast float [[P]], %D
87 ; CHECK-NEXT: [[B_NEG:%.*]] = fsub fast float -0.000000e+00, [[B:%.*]]
88 ; CHECK-NEXT: [[O_NEG:%.*]] = fsub fast float [[B_NEG]], [[A:%.*]]
89 ; CHECK-NEXT: [[P:%.*]] = fsub fast float [[O_NEG]], [[C:%.*]]
90 ; CHECK-NEXT: [[Q:%.*]] = fadd fast float [[P]], [[D:%.*]]
9091 ; CHECK-NEXT: ret float [[Q]]
9192 ;
9293 %M = fadd fast float 1.200000e+01, %A
101102
102103 define float @test4_reassoc(float %A, float %B, float %C, float %D) {
103104 ; CHECK-LABEL: @test4_reassoc(
104 ; CHECK-NEXT: [[M:%.*]] = fadd reassoc float %A, 1.200000e+01
105 ; CHECK-NEXT: [[N:%.*]] = fadd reassoc float [[M]], %B
106 ; CHECK-NEXT: [[O:%.*]] = fadd reassoc float [[N]], %C
107 ; CHECK-NEXT: [[P:%.*]] = fsub reassoc float %D, [[O]]
105 ; CHECK-NEXT: [[M:%.*]] = fadd reassoc float [[A:%.*]], 1.200000e+01
106 ; CHECK-NEXT: [[N:%.*]] = fadd reassoc float [[M]], [[B:%.*]]
107 ; CHECK-NEXT: [[O:%.*]] = fadd reassoc float [[N]], [[C:%.*]]
108 ; CHECK-NEXT: [[P:%.*]] = fsub reassoc float [[D:%.*]], [[O]]
108109 ; CHECK-NEXT: [[Q:%.*]] = fadd reassoc float [[P]], 1.200000e+01
109110 ; CHECK-NEXT: ret float [[Q]]
110111 ;
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -reassociate -S < %s | FileCheck %s
12
23 declare void @use(float)
34
45 define void @test1(float %x, float %y) {
56 ; CHECK-LABEL: @test1(
6 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float %y, %x
7 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float %y, %x
7 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[Y:%.*]], [[X:%.*]]
8 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[Y]], [[X]]
89 ; CHECK-NEXT: [[TMP3:%.*]] = fsub fast float [[TMP1]], [[TMP2]]
910 ; CHECK-NEXT: call void @use(float [[TMP1]])
1011 ; CHECK-NEXT: call void @use(float [[TMP3]])
2021
2122 define float @test2(float %x, float %y) {
2223 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float %y, %x
24 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float %y, %x
24 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[Y:%.*]], [[X:%.*]]
25 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[Y]], [[X]]
2526 ; CHECK-NEXT: [[TMP3:%.*]] = fsub fast float [[TMP1]], [[TMP2]]
2627 ; CHECK-NEXT: ret float [[TMP3]]
2728 ;
3334
3435 define float @test3(float %x, float %y) {
3536 ; CHECK-LABEL: @test3(
36 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %y, %x
37 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float [[Y:%.*]], [[X:%.*]]
3738 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[FACTOR]], 2.000000e+00
3839 ; CHECK-NEXT: ret float [[REASS_MUL]]
3940 ;
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -S | FileCheck %s
12
23 ; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
34
45 define float @fmultistep1(float %a, float %b, float %c) {
56 ; CHECK-LABEL: @fmultistep1(
6 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float %c, %b
7 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float %a, %a
8 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL:%.*]]2, [[REASS_ADD1]]
7 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float [[C:%.*]], [[B:%.*]]
8 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float [[A:%.*]], [[A]]
9 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL2]], [[REASS_ADD1]]
910 ; CHECK-NEXT: ret float [[REASS_MUL]]
1011 ;
1112 %t0 = fmul fast float %a, %b
2021
2122 define float @fmultistep2(float %a, float %b, float %c, float %d) {
2223 ; CHECK-LABEL: @fmultistep2(
23 ; CHECK-NEXT: [[REASS_ADD:%.*]] = fadd fast float %c, %b
24 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], %a
25 ; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[REASS_MUL]], %d
24 ; CHECK-NEXT: [[REASS_ADD:%.*]] = fadd fast float [[C:%.*]], [[B:%.*]]
25 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], [[A:%.*]]
26 ; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[REASS_MUL]], [[D:%.*]]
2627 ; CHECK-NEXT: ret float [[T3]]
2728 ;
2829 %t0 = fmul fast float %a, %b
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; This testcase comes from this C fragment:
12 ;
23 ; void test(unsigned Num, int *Array) {
1819 declare i32 @printf(i8*, ...)
1920
2021 ; Check that (i+j) has been reassociated (i=reg115, j=reg116)
21 ; CHECK: %reg113 = add i32 %reg116, %reg115
2222 define void @test(i32 %Num, i32* %Array) {
23 ; CHECK-LABEL: @test(
24 ; CHECK-NEXT: bb0:
25 ; CHECK-NEXT: [[COND221:%.*]] = icmp eq i32 0, [[NUM:%.*]]
26 ; CHECK-NEXT: br i1 [[COND221]], label [[BB7:%.*]], label [[BB2:%.*]]
27 ; CHECK: bb2:
28 ; CHECK-NEXT: [[REG115:%.*]] = phi i32 [ [[REG120:%.*]], [[BB6:%.*]] ], [ 0, [[BB0:%.*]] ]
29 ; CHECK-NEXT: br i1 [[COND221]], label [[BB6]], label [[BB3:%.*]]
30 ; CHECK: bb3:
31 ; CHECK-NEXT: [[REG116:%.*]] = phi i32 [ [[REG119:%.*]], [[BB5:%.*]] ], [ 0, [[BB2]] ]
32 ; CHECK-NEXT: br i1 [[COND221]], label [[BB5]], label [[BB4:%.*]]
33 ; CHECK: bb4:
34 ; CHECK-NEXT: [[REG117:%.*]] = phi i32 [ [[REG118:%.*]], [[BB4]] ], [ 0, [[BB3]] ]
35 ; CHECK-NEXT: [[REG113:%.*]] = add i32 [[REG116]], [[REG115]]
36 ; CHECK-NEXT: [[REG114:%.*]] = add i32 [[REG113]], [[REG117]]
37 ; CHECK-NEXT: [[CAST227:%.*]] = getelementptr [4 x i8], [4 x i8]* @.LC0, i64 0, i64 0
38 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 (i8*, ...) @printf(i8* [[CAST227]], i32 [[REG114]])
39 ; CHECK-NEXT: [[REG118]] = add i32 [[REG117]], 1
40 ; CHECK-NEXT: [[COND224:%.*]] = icmp ne i32 [[REG118]], [[NUM]]
41 ; CHECK-NEXT: br i1 [[COND224]], label [[BB4]], label [[BB5]]
42 ; CHECK: bb5:
43 ; CHECK-NEXT: [[REG119]] = add i32 [[REG116]], 1
44 ; CHECK-NEXT: [[COND225:%.*]] = icmp ne i32 [[REG119]], [[NUM]]
45 ; CHECK-NEXT: br i1 [[COND225]], label [[BB3]], label [[BB6]]
46 ; CHECK: bb6:
47 ; CHECK-NEXT: [[REG120]] = add i32 [[REG115]], 1
48 ; CHECK-NEXT: [[COND226:%.*]] = icmp ne i32 [[REG120]], [[NUM]]
49 ; CHECK-NEXT: br i1 [[COND226]], label [[BB2]], label [[BB7]]
50 ; CHECK: bb7:
51 ; CHECK-NEXT: ret void
52 ;
2353 bb0:
24 %cond221 = icmp eq i32 0, %Num ; [#uses=3]
25 br i1 %cond221, label %bb7, label %bb2
54 %cond221 = icmp eq i32 0, %Num ; [#uses=3]
55 br i1 %cond221, label %bb7, label %bb2
2656 bb2: ; preds = %bb6, %bb0
27 %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; [#uses=2]
28 br i1 %cond221, label %bb6, label %bb3
57 %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; [#uses=2]
58 br i1 %cond221, label %bb6, label %bb3
2959 bb3: ; preds = %bb5, %bb2
30 %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; [#uses=2]
31 br i1 %cond221, label %bb5, label %bb4
60 %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; [#uses=2]
61 br i1 %cond221, label %bb5, label %bb4
3262 bb4: ; preds = %bb4, %bb3
33 %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; [#uses=2]
34 %reg113 = add i32 %reg115, %reg117 ; [#uses=1]
35 %reg114 = add i32 %reg113, %reg116 ; [#uses=1]
36 %cast227 = getelementptr [4 x i8], [4 x i8]* @.LC0, i64 0, i64 0 ; [#uses=1]
37 call i32 (i8*, ...) @printf( i8* %cast227, i32 %reg114 ) ; :0 [#uses=0]
38 %reg118 = add i32 %reg117, 1 ; [#uses=2]
39 %cond224 = icmp ne i32 %reg118, %Num ; [#uses=1]
40 br i1 %cond224, label %bb4, label %bb5
63 %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; [#uses=2]
64 %reg113 = add i32 %reg115, %reg117 ; [#uses=1]
65 %reg114 = add i32 %reg113, %reg116 ; [#uses=1]
66 %cast227 = getelementptr [4 x i8], [4 x i8]* @.LC0, i64 0, i64 0 ; [#uses=1]
67 call i32 (i8*, ...) @printf( i8* %cast227, i32 %reg114 ) ; :0 [#uses=0]
68 %reg118 = add i32 %reg117, 1 ; [#uses=2]
69 %cond224 = icmp ne i32 %reg118, %Num ; [#uses=1]
70 br i1 %cond224, label %bb4, label %bb5
4171 bb5: ; preds = %bb4, %bb3
42 %reg119 = add i32 %reg116, 1 ; [#uses=2]
43 %cond225 = icmp ne i32 %reg119, %Num ; [#uses=1]
44 br i1 %cond225, label %bb3, label %bb6
72 %reg119 = add i32 %reg116, 1 ; [#uses=2]
73 %cond225 = icmp ne i32 %reg119, %Num ; [#uses=1]
74 br i1 %cond225, label %bb3, label %bb6
4575 bb6: ; preds = %bb5, %bb2
46 %reg120 = add i32 %reg115, 1 ; [#uses=2]
47 %cond226 = icmp ne i32 %reg120, %Num ; [#uses=1]
48 br i1 %cond226, label %bb2, label %bb7
76 %reg120 = add i32 %reg115, 1 ; [#uses=2]
77 %cond226 = icmp ne i32 %reg120, %Num ; [#uses=1]
78 br i1 %cond226, label %bb2, label %bb7
4979 bb7: ; preds = %bb6, %bb0
50 ret void
80 ret void
5181 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -reassociate %s -S | FileCheck %s
12
23 define float @foo(float %a,float %b, float %c) {
34 ; CHECK-LABEL: @foo(
4 ; CHECK-NEXT: [[MUL3:%.*]] = fmul float %a, %b
5 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float %c, 2.000000e+00
6 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float [[FACTOR]], %b
7 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD1]], %a
5 ; CHECK-NEXT: [[MUL3:%.*]] = fmul float [[A:%.*]], [[B:%.*]]
6 ; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float [[C:%.*]], 2.000000e+00
7 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float [[FACTOR]], [[B]]
8 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD1]], [[A]]
89 ; CHECK-NEXT: [[ADD3:%.*]] = fadd fast float [[REASS_MUL]], [[MUL3]]
910 ; CHECK-NEXT: ret float [[ADD3]]
1011 ;
2021
2122 define float @foo_reassoc(float %a,float %b, float %c) {
2223 ; CHECK-LABEL: @foo_reassoc(
23 ; CHECK-NEXT: [[MUL1:%.*]] = fmul reassoc float %a, %c
24 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float %b, %a
25 ; CHECK-NEXT: [[MUL3:%.*]] = fmul float %a, %b
26 ; CHECK-NEXT: [[MUL4:%.*]] = fmul reassoc float %a, %c
24 ; CHECK-NEXT: [[MUL1:%.*]] = fmul reassoc float [[A:%.*]], [[C:%.*]]
25 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[B:%.*]], [[A]]
26 ; CHECK-NEXT: [[MUL3:%.*]] = fmul float [[A]], [[B]]
27 ; CHECK-NEXT: [[MUL4:%.*]] = fmul reassoc float [[A]], [[C]]
2728 ; CHECK-NEXT: [[ADD1:%.*]] = fadd fast float [[MUL1]], [[MUL3]]
2829 ; CHECK-NEXT: [[ADD2:%.*]] = fadd reassoc float [[MUL2]], [[MUL4]]
2930 ; CHECK-NEXT: [[ADD3:%.*]] = fadd fast float [[ADD1]], [[ADD2]]
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -S | FileCheck %s
12
23 define i32 @test1(i32 %a, i32 %b) {
34 ; CHECK-LABEL: @test1(
4 ; CHECK-NEXT: [[T2:%.*]] = mul i32 %a, %a
5 ; CHECK-NEXT: [[T6:%.*]] = mul i32 %a, 2
6 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 [[T6]], %b
7 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], %b
5 ; CHECK-NEXT: [[T2:%.*]] = mul i32 [[A:%.*]], [[A]]
6 ; CHECK-NEXT: [[T6:%.*]] = mul i32 [[A]], 2
7 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 [[T6]], [[B:%.*]]
8 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], [[B]]
89 ; CHECK-NEXT: [[T11:%.*]] = add i32 [[REASS_MUL]], [[T2]]
910 ; CHECK-NEXT: ret i32 [[T11]]
1011 ;
1920
2021 define i32 @test2(i32 %t) {
2122 ; CHECK-LABEL: @test2(
22 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 %t, 42
23 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[T:%.*]], 42
2324 ; CHECK-NEXT: [[D:%.*]] = add i32 [[REASS_MUL]], 15
2425 ; CHECK-NEXT: ret i32 [[D]]
2526 ;
3334 ; (x^8)
3435 define i32 @test3(i32 %x) {
3536 ; CHECK-LABEL: @test3(
36 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
37 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
3738 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
3839 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
3940 ; CHECK-NEXT: ret i32 [[TMP3]]
5152 ; (x^7)
5253 define i32 @test4(i32 %x) {
5354 ; CHECK-LABEL: @test4(
54 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
55 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %x
56 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], %x
55 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
56 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[X]]
57 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[X]]
5758 ; CHECK-NEXT: [[F:%.*]] = mul i32 [[TMP3]], [[TMP2]]
5859 ; CHECK-NEXT: ret i32 [[F]]
5960 ;
6970 ; (x^4) * (y^2)
7071 define i32 @test5(i32 %x, i32 %y) {
7172 ; CHECK-LABEL: @test5(
72 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
73 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
73 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
74 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[Y:%.*]]
7475 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
7576 ; CHECK-NEXT: ret i32 [[TMP3]]
7677 ;
8586 ; (x^5) * (y^3) * z
8687 define i32 @test6(i32 %x, i32 %y, i32 %z) {
8788 ; CHECK-LABEL: @test6(
88 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
89 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
90 ; CHECK-NEXT: [[F:%.*]] = mul i32 %y, %x
89 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
90 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[Y:%.*]]
91 ; CHECK-NEXT: [[F:%.*]] = mul i32 [[Y]], [[X]]
9192 ; CHECK-NEXT: [[G:%.*]] = mul i32 [[F]], [[TMP2]]
9293 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[G]], [[TMP2]]
93 ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP3]], %z
94 ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP3]], [[Z:%.*]]
9495 ; CHECK-NEXT: ret i32 [[H]]
9596 ;
9697 %a = mul i32 %x, %y
107108 ; (x^4) * (y^3) * (z^2)
108109 define i32 @test7(i32 %x, i32 %y, i32 %z) {
109110 ; CHECK-LABEL: @test7(
110 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
111 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
112 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], %z
113 ; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], %y
111 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
112 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[Y:%.*]]
113 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[Z:%.*]]
114 ; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], [[Y]]
114115 ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP4]], [[TMP3]]
115116 ; CHECK-NEXT: ret i32 [[H]]
116117 ;
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -S | FileCheck %s
12
23 ; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
34
45 define i64 @multistep1(i64 %a, i64 %b, i64 %c) {
56 ; CHECK-LABEL: @multistep1(
6 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = add i64 %c, %b
7 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = mul i64 %a, %a
8 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_MUL:%.*]]2, [[REASS_ADD1]]
7 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = add i64 [[C:%.*]], [[B:%.*]]
8 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = mul i64 [[A:%.*]], [[A]]
9 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_MUL2]], [[REASS_ADD1]]
910 ; CHECK-NEXT: ret i64 [[REASS_MUL]]
1011 ;
1112 %t0 = mul i64 %a, %b
2021
2122 define i64 @multistep2(i64 %a, i64 %b, i64 %c, i64 %d) {
2223 ; CHECK-LABEL: @multistep2(
23 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i64 %c, %b
24 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_ADD]], %a
25 ; CHECK-NEXT: [[T3:%.*]] = add i64 [[REASS_MUL]], %d
24 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i64 [[C:%.*]], [[B:%.*]]
25 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i64 [[REASS_ADD]], [[A:%.*]]
26 ; CHECK-NEXT: [[T3:%.*]] = add i64 [[REASS_MUL]], [[D:%.*]]
2627 ; CHECK-NEXT: ret i64 [[T3]]
2728 ;
2829 %t0 = mul i64 %a, %b
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -S | FileCheck %s
12
23 ; When there is nothing to do, or not much to do, check that reassociate leaves
89 ; Shouldn't change or move any of the add instructions. Should commute but
910 ; otherwise not change or move any of the mul instructions.
1011 ; CHECK-LABEL: @test1(
12 ; CHECK-NEXT: [[A0:%.*]] = add nsw i32 [[A:%.*]], 1
13 ; CHECK-NEXT: [[M0:%.*]] = mul nsw i32 [[A]], 3
14 ; CHECK-NEXT: [[A1:%.*]] = add nsw i32 [[A0]], [[B:%.*]]
15 ; CHECK-NEXT: [[M1:%.*]] = mul nsw i32 [[M0]], [[B]]
16 ; CHECK-NEXT: call void @use(i32 [[A1]])
17 ; CHECK-NEXT: call void @use(i32 [[M1]])
18 ; CHECK-NEXT: ret void
19 ;
1120 %a0 = add nsw i32 %a, 1
12 ; CHECK-NEXT: %a0 = add nsw i32 %a, 1
1321 %m0 = mul nsw i32 3, %a
14 ; CHECK-NEXT: %m0 = mul nsw i32 %a, 3
1522 %a1 = add nsw i32 %a0, %b
16 ; CHECK-NEXT: %a1 = add nsw i32 %a0, %b
1723 %m1 = mul nsw i32 %b, %m0
18 ; CHECK-NEXT: %m1 = mul nsw i32 %m0, %b
1924 call void @use(i32 %a1)
20 ; CHECK-NEXT: call void @use
2125 call void @use(i32 %m1)
2226 ret void
2327 }
2529 define void @test2(i32 %a, i32 %b, i32 %c, i32 %d) {
2630 ; The initial add doesn't change so should not lose the nsw flag.
2731 ; CHECK-LABEL: @test2(
32 ; CHECK-NEXT: [[A0:%.*]] = add nsw i32 [[B:%.*]], [[A:%.*]]
33 ; CHECK-NEXT: [[A1:%.*]] = add i32 [[A0]], [[C:%.*]]
34 ; CHECK-NEXT: [[A2:%.*]] = add i32 [[A1]], [[D:%.*]]
35 ; CHECK-NEXT: call void @use(i32 [[A2]])
36 ; CHECK-NEXT: ret void
37 ;
2838 %a0 = add nsw i32 %b, %a
29 ; CHECK-NEXT: %a0 = add nsw i32 %b, %a
3039 %a1 = add nsw i32 %a0, %d
31 ; CHECK-NEXT: %a1 = add i32 %a0, %c
3240 %a2 = add nsw i32 %a1, %c
33 ; CHECK-NEXT: %a2 = add i32 %a1, %d
3441 call void @use(i32 %a2)
35 ; CHECK-NEXT: call void @use
3642 ret void
3743 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -S -reassociate < %s | FileCheck %s
12 ; rdar://8944681
23
34 ; Reassociate should clear optional flags like nsw when reassociating.
45
6 define i64 @test0(i64 %a, i64 %b, i64 %c) {
7 ;
58 ; CHECK-LABEL: @test0(
6 ; CHECK: %y = add i64 %b, %a
7 ; CHECK: %z = add i64 %y, %c
8 define i64 @test0(i64 %a, i64 %b, i64 %c) {
9 ; CHECK-NEXT: [[Y:%.*]] = add i64 [[B:%.*]], [[A:%.*]]
10 ; CHECK-NEXT: [[Z:%.*]] = add i64 [[Y]], [[C:%.*]]
11 ; CHECK-NEXT: ret i64 [[Z]]
12 ;
913 %y = add nsw i64 %c, %b
1014 %z = add i64 %y, %a
1115 ret i64 %z
1216 }
1317
18 define i64 @test1(i64 %a, i64 %b, i64 %c) {
19 ;
1420 ; CHECK-LABEL: @test1(
15 ; CHECK: %y = add i64 %b, %a
16 ; CHECK: %z = add i64 %y, %c
17 define i64 @test1(i64 %a, i64 %b, i64 %c) {
21 ; CHECK-NEXT: [[Y:%.*]] = add i64 [[B:%.*]], [[A:%.*]]
22 ; CHECK-NEXT: [[Z:%.*]] = add i64 [[Y]], [[C:%.*]]
23 ; CHECK-NEXT: ret i64 [[Z]]
24 ;
1825 %y = add i64 %c, %b
1926 %z = add nsw i64 %y, %a
2027 ret i64 %z
2128 }
2229
2330 ; PR9215
24 ; CHECK: %s = add nsw i32 %y, %x
2531 define i32 @test2(i32 %x, i32 %y) {
32 ;
33 ; CHECK-LABEL: @test2(
34 ; CHECK-NEXT: [[S:%.*]] = add nsw i32 [[Y:%.*]], [[X:%.*]]
35 ; CHECK-NEXT: ret i32 [[S]]
36 ;
2637 %s = add nsw i32 %x, %y
2738 ret i32 %s
2839 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -S | FileCheck %s
12
23 define double @func(double %a, double %b) {
34 ; CHECK-LABEL: @func(
4 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double %b, %a
5 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double [[B:%.*]], [[A:%.*]]
56 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
67 ; CHECK-NEXT: ret double [[TMP2]]
78 ;
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s
12
23 ; There should be exactly one shift and one add left.
34
45 define i32 @test1(i32 %X, i32 %Y) {
56 ; CHECK-LABEL: @test1(
6 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 %Y, %X
7 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 [[Y:%.*]], [[X:%.*]]
78 ; CHECK-NEXT: [[REASS_MUL:%.*]] = shl i32 [[REASS_ADD]], 1
89 ; CHECK-NEXT: ret i32 [[REASS_MUL]]
910 ;
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -S -reassociate -die < %s | FileCheck %s
12
23 ; The two va_arg instructions depend on the memory/context, are therfore not
34 ; identical and the sub should not be optimized to 0 by reassociate.
45 ;
6 ; ...
7 ; ...
8 define i32 @func(i32 %dummy, ...) {
9 ;
510 ; CHECK-LABEL: @func(
6 ; ...
7 ; CHECK: %v0 = va_arg i8** %varargs, i32
8 ; CHECK: %v1 = va_arg i8** %varargs, i32
9 ; CHECK: %v0.neg = sub i32 0, %v0
10 ; CHECK: %sub = add i32 %v0.neg, 1
11 ; CHECK: %add = add i32 %sub, %v1
12 ; ...
13 ; CHECK: ret i32 %add
14 define i32 @func(i32 %dummy, ...) {
11 ; CHECK-NEXT: [[VARARGS:%.*]] = alloca i8*, align 8
12 ; CHECK-NEXT: [[VARARGS1:%.*]] = bitcast i8** [[VARARGS]] to i8*
13 ; CHECK-NEXT: call void @llvm.va_start(i8* [[VARARGS1]])
14 ; CHECK-NEXT: [[V0:%.*]] = va_arg i8** [[VARARGS]], i32
15 ; CHECK-NEXT: [[V1:%.*]] = va_arg i8** [[VARARGS]], i32
16 ; CHECK-NEXT: [[V0_NEG:%.*]] = sub i32 0, [[V0]]
17 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[V0_NEG]], 1
18 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SUB]], [[V1]]
19 ; CHECK-NEXT: call void @llvm.va_end(i8* [[VARARGS1]])
20 ; CHECK-NEXT: ret i32 [[ADD]]
21 ;
1522 %varargs = alloca i8*, align 8
1623 %varargs1 = bitcast i8** %varargs to i8*
1724 call void @llvm.va_start(i8* %varargs1)
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -dce -S | FileCheck %s
12 ; PR12985
23
34 ; Verify the nsw flags are preserved when converting shl to mul.
45
6 define i32 @shl_to_mul_nsw(i32 %i) {
7 ;
58 ; CHECK-LABEL: @shl_to_mul_nsw(
6 ; CHECK: %mul = mul i32 %i, -2147483648
7 ; CHECK: add i32 %mul, 1
8 define i32 @shl_to_mul_nsw(i32 %i) {
9 ; CHECK-NEXT: entry:
10 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[I:%.*]], -2147483648
11 ; CHECK-NEXT: [[MUL2:%.*]] = add i32 [[MUL]], 1
12 ; CHECK-NEXT: ret i32 [[MUL2]]
13 ;
914 entry:
1015 %mul = shl nsw i32 %i, 31
1116 %mul2 = add i32 %mul, 1
1217 ret i32 %mul2
1318 }
1419
20 define i32 @shl_to_mul_nuw(i32 %i) {
21 ;
1522 ; CHECK-LABEL: @shl_to_mul_nuw(
16 ; CHECK: %mul = mul nuw i32 %i, 4
17 ; CHECK: add i32 %mul, 1
18 define i32 @shl_to_mul_nuw(i32 %i) {
23 ; CHECK-NEXT: entry:
24 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[I:%.*]], 4
25 ; CHECK-NEXT: [[MUL2:%.*]] = add i32 [[MUL]], 1
26 ; CHECK-NEXT: ret i32 [[MUL2]]
27 ;
1928 entry:
2029 %mul = shl nuw i32 %i, 2
2130 %mul2 = add i32 %mul, 1
2231 ret i32 %mul2
2332 }
2433
34 define i32 @shl_to_mul_nuw_nsw(i32 %i) {
35 ;
2536 ; CHECK-LABEL: @shl_to_mul_nuw_nsw(
26 ; CHECK: %mul = mul nuw nsw i32 %i, 4
27 ; CHECK: add i32 %mul, 1
28 define i32 @shl_to_mul_nuw_nsw(i32 %i) {
37 ; CHECK-NEXT: entry:
38 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[I:%.*]], 4
39 ; CHECK-NEXT: [[MUL2:%.*]] = add i32 [[MUL]], 1
40 ; CHECK-NEXT: ret i32 [[MUL2]]
41 ;
2942 entry:
3043 %mul = shl nuw nsw i32 %i, 2
3144 %mul2 = add i32 %mul, 1
3245 ret i32 %mul2
3346 }
3447
48 define i2 @pr23926(i2 %X1, i2 %X2) {
49 ;
3550 ; CHECK-LABEL: @pr23926(
36 ; CHECK: %[[X1_neg:.*]] = sub i2 0, %X1
37 ; CHECK-NEXT: %[[sub_one:.*]] = add i2 %[[X1_neg]], -1
38 ; CHECK-NEXT: %[[add:.*]] = add i2 %[[sub_one]], %X2
39 ; CHECK-NEXT: ret i2 %[[add]]
40 define i2 @pr23926(i2 %X1, i2 %X2) {
51 ; CHECK-NEXT: [[X1_NEG:%.*]] = sub i2 0, [[X1:%.*]]
52 ; CHECK-NEXT: [[ADD_NEG:%.*]] = add i2 [[X1_NEG]], -1
53 ; CHECK-NEXT: [[SUB:%.*]] = add i2 [[ADD_NEG]], [[X2:%.*]]
54 ; CHECK-NEXT: ret i2 [[SUB]]
55 ;
4156 %add = add nuw i2 %X1, 1
4257 %sub = sub nuw nsw i2 %X2, %add
4358 ret i2 %sub
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ;RUN: opt -S -reassociate < %s | FileCheck %s
12
23 ; ==========================================================================
34 ;
45 ; Xor reassociation general cases
5 ;
6 ;
67 ; ==========================================================================
78
89 ; (x | c1) ^ (x | c2) => (x & c3) ^ c3, where c3 = c1^c2
9 ;
10 ;
1011 define i32 @xor1(i32 %x) {
12 ; CHECK-LABEL: @xor1(
13 ; CHECK-NEXT: [[AND_RA:%.*]] = and i32 [[X:%.*]], 435
14 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND_RA]], 435
15 ; CHECK-NEXT: ret i32 [[XOR]]
16 ;
1117 %or = or i32 %x, 123
1218 %or1 = or i32 %x, 456
1319 %xor = xor i32 %or, %or1
1420 ret i32 %xor
15
16 ;CHECK-LABEL: @xor1(
17 ;CHECK: %and.ra = and i32 %x, 435
18 ;CHECK: %xor = xor i32 %and.ra, 435
1921 }
2022
2123 ; (x | c1) ^ (x | c2) => (x & c3) ^ c3, where c3 = c1^c2
22 ;
24 ;
2325 define <2 x i32> @xor1_vec(<2 x i32> %x) {
26 ; CHECK-LABEL: @xor1_vec(
27 ; CHECK-NEXT: [[AND_RA:%.*]] = and <2 x i32> [[X:%.*]],
28 ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i32> [[AND_RA]],
29 ; CHECK-NEXT: ret <2 x i32> [[XOR]]
30 ;
2431 %or = or <2 x i32> %x,
2532 %or1 = or <2 x i32> %x,
2633 %xor = xor <2 x i32> %or, %or1
2734 ret <2 x i32> %xor
28
29 ;CHECK-LABEL: @xor1_vec(
30 ;CHECK: %and.ra = and <2 x i32> %x,
31 ;CHECK: %xor = xor <2 x i32> %and.ra,
3235 }
3336
3437 ; Test rule : (x & c1) ^ (x & c2) = (x & (c1^c2))
3538 ; Real testing case : (x & 123) ^ y ^ (x & 345) => (x & 435) ^ y
3639 define i32 @xor2(i32 %x, i32 %y) {
40 ; CHECK-LABEL: @xor2(
41 ; CHECK-NEXT: [[AND_RA:%.*]] = and i32 [[X:%.*]], 435
42 ; CHECK-NEXT: [[XOR2:%.*]] = xor i32 [[AND_RA]], [[Y:%.*]]
43 ; CHECK-NEXT: ret i32 [[XOR2]]
44 ;
3745 %and = and i32 %x, 123
3846 %xor = xor i32 %and, %y
3947 %and1 = and i32 %x, 456
4048 %xor2 = xor i32 %xor, %and1
4149 ret i32 %xor2
42
43 ;CHECK-LABEL: @xor2(
44 ;CHECK: %and.ra = and i32 %x, 435
45 ;CHECK: %xor2 = xor i32 %and.ra, %y
4650 }
4751
4852 ; Test rule : (x & c1) ^ (x & c2) = (x & (c1^c2))
4953 ; Real testing case : (x & 123) ^ y ^ (x & 345) => (x & 435) ^ y
5054 define <2 x i32> @xor2_vec(<2 x i32> %x, <2 x i32> %y) {
55 ; CHECK-LABEL: @xor2_vec(
56 ; CHECK-NEXT: [[AND_RA:%.*]] = and <2 x i32> [[X:%.*]],
57 ; CHECK-NEXT: [[XOR2:%.*]] = xor <2 x i32> [[AND_RA]], [[Y:%.*]]
58 ; CHECK-NEXT: ret <2 x i32> [[XOR2]]
59 ;
5160 %and = and <2 x i32> %x,
5261 %xor = xor <2 x i32> %and, %y
5362 %and1 = and <2 x i32> %x,
5463 %xor2 = xor <2 x i32> %xor, %and1
5564 ret <2 x i32> %xor2
56
57 ;CHECK-LABEL: @xor2_vec(
58 ;CHECK: %and.ra = and <2 x i32> %x,
59 ;CHECK: %xor2 = xor <2 x i32> %and.ra, %y
6065 }
6166
6267 ; Test rule: (x | c1) ^ (x & c2) = (x & c3) ^ c1, where c3 = ~c1 ^ c2
6368 ; c3 = ~c1 ^ c2
6469 define i32 @xor3(i32 %x, i32 %y) {
70 ; CHECK-LABEL: @xor3(
71 ; CHECK-NEXT: [[AND_RA:%.*]] = and i32 [[X:%.*]], -436
72 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 123
73 ; CHECK-NEXT: [[XOR1:%.*]] = xor i32 [[XOR]], [[AND_RA]]
74 ; CHECK-NEXT: ret i32 [[XOR1]]
75 ;
6576 %or = or i32 %x, 123
6677 %xor = xor i32 %or, %y
6778 %and = and i32 %x, 456
6879 %xor1 = xor i32 %xor, %and
6980 ret i32 %xor1
70
71 ;CHECK-LABEL: @xor3(
72 ;CHECK: %and.ra = and i32 %x, -436
73 ;CHECK: %xor = xor i32 %y, 123
74 ;CHECK: %xor1 = xor i32 %xor, %and.ra
7581 }
7682
7783 ; Test rule: (x | c1) ^ (x & c2) = (x & c3) ^ c1, where c3 = ~c1 ^ c2
7884 ; c3 = ~c1 ^ c2
7985 define <2 x i32> @xor3_vec(<2 x i32> %x, <2 x i32> %y) {
86 ; CHECK-LABEL: @xor3_vec(
87 ; CHECK-NEXT: [[AND_RA:%.*]] = and <2 x i32> [[X:%.*]],
88 ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i32> [[Y:%.*]],
89 ; CHECK-NEXT: [[XOR1:%.*]] = xor <2 x i32> [[XOR]], [[AND_RA]]
90 ; CHECK-NEXT: ret <2 x i32> [[XOR1]]
91 ;
8092 %or = or <2 x i32> %x,
8193 %xor = xor <2 x i32> %or, %y
8294 %and = and <2 x i32> %x,
8395 %xor1 = xor <2 x i32> %xor, %and
8496 ret <2 x i32> %xor1
85
86 ;CHECK-LABEL: @xor3_vec(
87 ;CHECK: %and.ra = and <2 x i32> %x,
88 ;CHECK: %xor = xor <2 x i32> %y,
89 ;CHECK: %xor1 = xor <2 x i32> %xor, %and.ra
9097 }
9198
9299 ; Test rule: (x | c1) ^ c2 = (x & ~c1) ^ (c1 ^ c2)
93100 define i32 @xor4(i32 %x, i32 %y) {
101 ; CHECK-LABEL: @xor4(
102 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], -124
103 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 435
104 ; CHECK-NEXT: [[XOR1:%.*]] = xor i32 [[XOR]], [[AND]]
105 ; CHECK-NEXT: ret i32 [[XOR1]]
106 ;
94107 %and = and i32 %x, -124
95108 %xor = xor i32 %y, 435
96109 %xor1 = xor i32 %xor, %and
97110 ret i32 %xor1
98 ; CHECK-LABEL: @xor4(
99 ; CHECK: %and = and i32 %x, -124
100 ; CHECK: %xor = xor i32 %y, 435
101 ; CHECK: %xor1 = xor i32 %xor, %and
102111 }
103112
104113 ; Test rule: (x | c1) ^ c2 = (x & ~c1) ^ (c1 ^ c2)
105114 define <2 x i32> @xor4_vec(<2 x i32> %x, <2 x i32> %y) {
115 ; CHECK-LABEL: @xor4_vec(
116 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]],
117 ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i32> [[Y:%.*]],
118 ; CHECK-NEXT: [[XOR1:%.*]] = xor <2 x i32> [[XOR]], [[AND]]
119 ; CHECK-NEXT: ret <2 x i32> [[XOR1]]
120 ;
106121 %and = and <2 x i32> %x,
107122 %xor = xor <2 x i32> %y,
108123 %xor1 = xor <2 x i32> %xor, %and
109124 ret <2 x i32> %xor1
110 ; CHECK-LABEL: @xor4_vec(
111 ; CHECK: %and = and <2 x i32> %x,
112 ; CHECK: %xor = xor <2 x i32> %y,
113 ; CHECK: %xor1 = xor <2 x i32> %xor, %and
114125 }
115126
116127 ; ==========================================================================
117128 ;
118129 ; Xor reassociation special cases
119 ;
120 ; ==========================================================================
121
122 ; Special case1:
130 ;
131 ; ==========================================================================
132
133 ; Special case1:
123134 ; (x | c1) ^ (x & ~c1) = c1
124135 define i32 @xor_special1(i32 %x, i32 %y) {
136 ; CHECK-LABEL: @xor_special1(
137 ; CHECK-NEXT: [[XOR1:%.*]] = xor i32 [[Y:%.*]], 123
138 ; CHECK-NEXT: ret i32 [[XOR1]]
139 ;
125140 %or = or i32 %x, 123
126141 %xor = xor i32 %or, %y
127142 %and = and i32 %x, -124
128143 %xor1 = xor i32 %xor, %and
129144 ret i32 %xor1
130 ; CHECK-LABEL: @xor_special1(
131 ; CHECK: %xor1 = xor i32 %y, 123
132 ; CHECK: ret i32 %xor1
133 }
134
135 ; Special case1:
145 }
146
147 ; Special case1:
136148 ; (x | c1) ^ (x & ~c1) = c1
137149 define <2 x i32> @xor_special1_vec(<2 x i32> %x, <2 x i32> %y) {
150 ; CHECK-LABEL: @xor_special1_vec(
151 ; CHECK-NEXT: [[XOR1:%.*]] = xor <2 x i32> [[Y:%.*]],
152 ; CHECK-NEXT: ret <2 x i32> [[XOR1]]
153 ;
138154 %or = or <2 x i32> %x,
139155 %xor = xor <2 x i32> %or, %y
140156 %and = and <2 x i32> %x,
141157 %xor1 = xor <2 x i32> %xor, %and
142158 ret <2 x i32> %xor1
143 ; CHECK-LABEL: @xor_special1_vec(
144 ; CHECK: %xor1 = xor <2 x i32> %y,
145 ; CHECK: ret <2 x i32> %xor1
146 }
147
148 ; Special case1:
159 }
160
161 ; Special case1:
149162 ; (x | c1) ^ (x & c1) = x ^ c1
150163 define i32 @xor_special2(i32 %x, i32 %y) {
164 ; CHECK-LABEL: @xor_special2(
165 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], 123
166 ; CHECK-NEXT: [[XOR1:%.*]] = xor i32 [[XOR]], [[Y:%.*]]
167 ; CHECK-NEXT: ret i32 [[XOR1]]
168 ;
151169 %or = or i32 %x, 123
152170 %xor = xor i32 %or, %y
153171 %and = and i32 %x, 123
154172 %xor1 = xor i32 %xor, %and
155173 ret i32 %xor1
156 ; CHECK-LABEL: @xor_special2(
157 ; CHECK: %xor = xor i32 %x, 123
158 ; CHECK: %xor1 = xor i32 %xor, %y
159 ; CHECK: ret i32 %xor1
160 }
161
162 ; Special case1:
174 }
175
176 ; Special case1:
163177 ; (x | c1) ^ (x & c1) = x ^ c1
164178 define <2 x i32> @xor_special2_vec(<2 x i32> %x, <2 x i32> %y) {
179 ; CHECK-LABEL: @xor_special2_vec(
180 ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i32> [[X:%.*]],
181 ; CHECK-NEXT: [[XOR1:%.*]] = xor <2 x i32> [[XOR]], [[Y:%.*]]
182 ; CHECK-NEXT: ret <2 x i32> [[XOR1]]
183 ;
165184 %or = or <2 x i32> %x,
166185 %xor = xor <2 x i32> %or, %y
167186 %and = and <2 x i32> %x,
168187 %xor1 = xor <2 x i32> %xor, %and
169188 ret <2 x i32> %xor1
170 ; CHECK-LABEL: @xor_special2_vec(
171 ; CHECK: %xor = xor <2 x i32> %x,
172 ; CHECK: %xor1 = xor <2 x i32> %xor, %y
173 ; CHECK: ret <2 x i32> %xor1
174189 }
175190
176191 ; (x | c1) ^ (x | c1) => 0
177192 define i32 @xor_special3(i32 %x) {
193 ; CHECK-LABEL: @xor_special3(
194 ; CHECK-NEXT: ret i32 0
195 ;
178196 %or = or i32 %x, 123
179197 %or1 = or i32 %x, 123
180198 %xor = xor i32 %or, %or1
181199 ret i32 %xor
182 ;CHECK-LABEL: @xor_special3(
183 ;CHECK: ret i32 0
184200 }
185201
186202 ; (x | c1) ^ (x | c1) => 0
187203 define <2 x i32> @xor_special3_vec(<2 x i32> %x) {
204 ; CHECK-LABEL: @xor_special3_vec(
205 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
206 ;
188207 %or = or <2 x i32> %x,
189208 %or1 = or <2 x i32> %x,
190209 %xor = xor <2 x i32> %or, %or1
191210 ret <2 x i32> %xor
192 ;CHECK-LABEL: @xor_special3_vec(
193 ;CHECK: ret <2 x i32> zeroinitializer
194211 }
195212
196213 ; (x & c1) ^ (x & c1) => 0
197214 define i32 @xor_special4(i32 %x) {
215 ; CHECK-LABEL: @xor_special4(
216 ; CHECK-NEXT: ret i32 0
217 ;
198218 %or = and i32 %x, 123
199219 %or1 = and i32 123, %x
200220 %xor = xor i32 %or, %or1
201221 ret i32 %xor
202 ;CHECK-LABEL: @xor_special4(
203 ;CHECK: ret i32 0
204222 }
205223
206224 ; (x & c1) ^ (x & c1) => 0
207225 define <2 x i32> @xor_special4_vec(<2 x i32> %x) {
226 ; CHECK-LABEL: @xor_special4_vec(
227 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
228 ;
208229 %or = and <2 x i32> %x,
209230 %or1 = and <2 x i32> , %x
210231 %xor = xor <2 x i32> %or, %or1
211232 ret <2 x i32> %xor
212 ;CHECK-LABEL: @xor_special4_vec(
213 ;CHECK: ret <2 x i32> zeroinitializer
214233 }
215234
216235 ; ==========================================================================
217236 ;
218237 ; Xor reassociation curtail code size
219 ;
238 ;
220239 ; ==========================================================================
221240
222241 ; (x | c1) ^ (x | c2) => (x & c3) ^ c3
223242 ; is enabled if one of operands has multiple uses
224 ;
243 ;
225244 define i32 @xor_ra_size1(i32 %x) {
245 ; CHECK-LABEL: @xor_ra_size1(
246 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], 123
247 ; CHECK-NEXT: [[AND_RA:%.*]] = and i32 [[X]], 435
248 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND_RA]], 435
249 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[XOR]], [[OR]]
250 ; CHECK-NEXT: ret i32 [[ADD]]
251 ;
226252 %or = or i32 %x, 123
227253 %or1 = or i32 %x, 456
228254 %xor = xor i32 %or, %or1
229255
230256 %add = add i32 %xor, %or
231257 ret i32 %add
232 ;CHECK-LABEL: @xor_ra_size1(
233 ;CHECK: %xor = xor i32 %and.ra, 435
234258 }
235259
236260 ; (x | c1) ^ (x | c2) => (x & c3) ^ c3
237261 ; is disenabled if bothf operands has multiple uses.
238 ;
262 ;
239263 define i32 @xor_ra_size2(i32 %x) {
264 ; CHECK-LABEL: @xor_ra_size2(
265 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], 123
266 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[X]], 456
267 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[OR]], [[OR1]]
268 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[OR1]], [[OR]]
269 ; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[ADD]], [[XOR]]
270 ; CHECK-NEXT: ret i32 [[ADD2]]
271 ;
240272 %or = or i32 %x, 123
241273 %or1 = or i32 %x, 456
242274 %xor = xor i32 %or, %or1
245277 %add2 = add i32 %add, %or1
246278 ret i32 %add2
247279
248 ;CHECK-LABEL: @xor_ra_size2(
249 ;CHECK: %or1 = or i32 %x, 456
250 ;CHECK: %xor = xor i32 %or, %or1
251280 }
252281
253282
254283 ; ==========================================================================
255284 ;
256285 ; Xor reassociation bugs
257 ;
286 ;
258287 ; ==========================================================================
259288
260289 @xor_bug1_data = external global <{}>, align 4
261290 define void @xor_bug1() {
291 ; CHECK-LABEL: @xor_bug1(
292 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint i32* undef to i64
293 ; CHECK-NEXT: [[TMP2:%.*]] = xor i64 [[TMP1]], ptrtoint (<{}>* @xor_bug1_data to i64)
294 ; CHECK-NEXT: ret void
295 ;
262296 %1 = ptrtoint i32* undef to i64
263297 %2 = xor i64 %1, ptrtoint (<{}>* @xor_bug1_data to i64)
264298 %3 = and i64 undef, %2
271305 ; of c1 and c2 accordingly, hence cause the problem.
272306 ;
273307 define i32 @xor_bug2(i32, i32, i32, i32) {
308 ; CHECK-LABEL: @xor_bug2(
309 ; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[TMP0:%.*]], 123
310 ; CHECK-NEXT: [[TMP6:%.*]] = and i32 [[TMP1:%.*]], 3456789
311 ; CHECK-NEXT: [[TMP7:%.*]] = or i32 [[TMP6]], 4567890
312 ; CHECK-NEXT: [[TMP8:%.*]] = and i32 [[TMP2:%.*]], 255
313 ; CHECK-NEXT: [[AND_RA:%.*]] = and i32 [[TMP1]], -360490541
314 ; CHECK-NEXT: [[TMP9:%.*]] = xor i32 [[TMP5]], 891034567
315 ; CHECK-NEXT: [[TMP10:%.*]] = xor i32 [[TMP9]], [[AND_RA]]
316 ; CHECK-NEXT: [[TMP11:%.*]] = xor i32 [[TMP10]], [[TMP7]]
317 ; CHECK-NEXT: [[TMP12:%.*]] = and i32 [[TMP3:%.*]], 255
318 ; CHECK-NEXT: [[TMP13:%.*]] = add i32 [[TMP1]], 32
319 ; CHECK-NEXT: [[TMP14:%.*]] = add i32 [[TMP13]], [[TMP2]]
320 ; CHECK-NEXT: [[TMP15:%.*]] = add i32 [[TMP14]], [[TMP8]]
321 ; CHECK-NEXT: [[TMP16:%.*]] = add i32 [[TMP15]], [[TMP11]]
322 ; CHECK-NEXT: ret i32 [[TMP16]]
323 ;
274324 %5 = mul i32 %0, 123
275325 %6 = add i32 %2, 24
276326 %7 = add i32 %1, 8
288338 %19 = add i32 %18, %12
289339 %20 = add i32 %19, %15
290340 ret i32 %20
291 ;CHECK-LABEL: @xor_bug2(
292 ;CHECK: xor i32 %5, 891034567
293 }
341 }