• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -reassociate -gvn -S < %s | FileCheck %s
2
3; (x + 0.1234 * y) * (x + -0.1234 * y) -> (x + 0.1234 * y) * (x - 0.1234 * y)
4define double @test1(double %x, double %y) {
5; CHECK-LABEL: @test1
6; CHECK-NEXT: fmul double %y, 1.234000e-01
7; CHECK-NEXT: fadd double %x, %mul
8; CHECK-NEXT: fsub double %x, %mul
9; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
10; CHECK-NEXT: ret double %mul
11
12  %mul = fmul double 1.234000e-01, %y
13  %add = fadd double %mul, %x
14  %mul1 = fmul double -1.234000e-01, %y
15  %add2 = fadd double %mul1, %x
16  %mul3 = fmul double %add, %add2
17  ret double %mul3
18}
19
20; (x + -0.1234 * y) * (x + -0.1234 * y) -> (x - 0.1234 * y) * (x - 0.1234 * y)
21define double @test2(double %x, double %y) {
22; CHECK-LABEL: @test2
23; CHECK-NEXT: fmul double %y, 1.234000e-01
24; CHECK-NEXT: fsub double %x, %mul
25; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
26; CHECK-NEXT: ret double %mul
27
28  %mul = fmul double %y, -1.234000e-01
29  %add = fadd double %mul, %x
30  %mul1 = fmul double %y, -1.234000e-01
31  %add2 = fadd double %mul1, %x
32  %mul3 = fmul double %add, %add2
33  ret double %mul3
34}
35
36; (x + 0.1234 * y) * (x - -0.1234 * y) -> (x + 0.1234 * y) * (x + 0.1234 * y)
37define double @test3(double %x, double %y) {
38; CHECK-LABEL: @test3
39; CHECK-NEXT: fmul double %y, 1.234000e-01
40; CHECK-NEXT: fadd double %x, %mul
41; CHECK-NEXT: fmul double %add{{.*}}, %add{{.*}}
42; CHECK-NEXT: ret double
43
44  %mul = fmul double %y, 1.234000e-01
45  %add = fadd double %mul, %x
46  %mul1 = fmul double %y, -1.234000e-01
47  %add2 = fsub double %x, %mul1
48  %mul3 = fmul double %add, %add2
49  ret double %mul3
50}
51
52; Canonicalize (x - -0.1234 * y)
53define double @test5(double %x, double %y) {
54; CHECK-LABEL: @test5
55; CHECK-NEXT: fmul double %y, 1.234000e-01
56; CHECK-NEXT: fadd double %x, %mul
57; CHECK-NEXT: ret double
58
59  %mul = fmul double -1.234000e-01, %y
60  %sub = fsub double %x, %mul
61  ret double %sub
62}
63
64; Don't modify (-0.1234 * y - x)
65define double @test6(double %x, double %y) {
66; CHECK-LABEL: @test6
67; CHECK-NEXT: fmul double %y, -1.234000e-01
68; CHECK-NEXT: fsub double %mul, %x
69; CHECK-NEXT: ret double %sub
70
71  %mul = fmul double -1.234000e-01, %y
72  %sub = fsub double %mul, %x
73  ret double %sub
74}
75
76; Canonicalize (-0.1234 * y + x) -> (x - 0.1234 * y)
77define double @test7(double %x, double %y) {
78; CHECK-LABEL: @test7
79; CHECK-NEXT: fmul double %y, 1.234000e-01
80; CHECK-NEXT: fsub double %x, %mul
81; CHECK-NEXT: ret double %add
82
83  %mul = fmul double -1.234000e-01, %y
84  %add = fadd double %mul, %x
85  ret double %add
86}
87
88; Canonicalize (y * -0.1234 + x) -> (x - 0.1234 * y)
89define double @test8(double %x, double %y) {
90; CHECK-LABEL: @test8
91; CHECK-NEXT: fmul double %y, 1.234000e-01
92; CHECK-NEXT: fsub double %x, %mul
93; CHECK-NEXT: ret double %add
94
95  %mul = fmul double %y, -1.234000e-01
96  %add = fadd double %mul, %x
97  ret double %add
98}
99
100; Canonicalize (x - -0.1234 / y)
101define double @test9(double %x, double %y) {
102; CHECK-LABEL: @test9
103; CHECK-NEXT: fdiv double 1.234000e-01, %y
104; CHECK-NEXT: fadd double %x, %div
105; CHECK-NEXT: ret double
106
107  %div = fdiv double -1.234000e-01, %y
108  %sub = fsub double %x, %div
109  ret double %sub
110}
111
112; Don't modify (-0.1234 / y - x)
113define double @test10(double %x, double %y) {
114; CHECK-LABEL: @test10
115; CHECK-NEXT: fdiv double -1.234000e-01, %y
116; CHECK-NEXT: fsub double %div, %x
117; CHECK-NEXT: ret double %sub
118
119  %div = fdiv double -1.234000e-01, %y
120  %sub = fsub double %div, %x
121  ret double %sub
122}
123
124; Canonicalize (-0.1234 / y + x) -> (x - 0.1234 / y)
125define double @test11(double %x, double %y) {
126; CHECK-LABEL: @test11
127; CHECK-NEXT: fdiv double 1.234000e-01, %y
128; CHECK-NEXT: fsub double %x, %div
129; CHECK-NEXT: ret double %add
130
131  %div = fdiv double -1.234000e-01, %y
132  %add = fadd double %div, %x
133  ret double %add
134}
135
136; Canonicalize (y / -0.1234 + x) -> (x - y / 0.1234)
137define double @test12(double %x, double %y) {
138; CHECK-LABEL: @test12
139; CHECK-NEXT: fdiv double %y, 1.234000e-01
140; CHECK-NEXT: fsub double %x, %div
141; CHECK-NEXT: ret double %add
142
143  %div = fdiv double %y, -1.234000e-01
144  %add = fadd double %div, %x
145  ret double %add
146}
147
148; Don't create an NSW violation
149define i4 @test13(i4 %x) {
150; CHECK-LABEL: @test13
151; CHECK-NEXT: %[[mul:.*]] = mul nsw i4 %x, -2
152; CHECK-NEXT: %[[add:.*]] = add i4 %[[mul]], 3
153  %mul = mul nsw i4 %x, -2
154  %add = add i4 %mul, 3
155  ret i4 %add
156}
157