1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s -mtriple unknown | FileCheck %s --check-prefixes=CHECK,CHECKI32,SQRT
3 ; RUN: opt -instcombine -S < %s -mtriple unknown -disable-builtin sqrt | FileCheck %s --check-prefixes=CHECK,CHECKI32,NOSQRT
4 ; RUN: opt -instcombine -S < %s -mtriple msp430 | FileCheck %s --check-prefixes=CHECK,CHECKI16,SQRT
5 ; RUN: opt -instcombine -S < %s -mtriple msp430 -disable-builtin sqrt | FileCheck %s --check-prefixes=CHECK,CHECKI16,NOSQRT
7 declare double @llvm.pow.f64(double, double)
8 declare float @llvm.pow.f32(float, float)
9 declare <2 x double> @llvm.pow.v2f64(<2 x double>, <2 x double>)
10 declare <2 x float> @llvm.pow.v2f32(<2 x float>, <2 x float>)
11 declare <4 x float> @llvm.pow.v4f32(<4 x float>, <4 x float>)
12 declare double @pow(double, double)
15 define double @test_simplify_3(double %x) {
16 ; CHECK-LABEL: @test_simplify_3(
17 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast double [[X:%.*]], [[X]]
18 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[X]]
19 ; CHECK-NEXT: ret double [[TMP1]]
21 %1 = call fast double @llvm.pow.f64(double %x, double 3.000000e+00)
26 define float @test_simplify_4f(float %x) {
27 ; CHECK-LABEL: @test_simplify_4f(
28 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast float [[X:%.*]], [[X]]
29 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[SQUARE]], [[SQUARE]]
30 ; CHECK-NEXT: ret float [[TMP1]]
32 %1 = call fast float @llvm.pow.f32(float %x, float 4.000000e+00)
37 define double @test_simplify_4(double %x) {
38 ; CHECK-LABEL: @test_simplify_4(
39 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast double [[X:%.*]], [[X]]
40 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
41 ; CHECK-NEXT: ret double [[TMP1]]
43 %1 = call fast double @llvm.pow.f64(double %x, double 4.000000e+00)
47 ; powf(x, <15.0, 15.0>)
48 define <2 x float> @test_simplify_15(<2 x float> %x) {
49 ; CHECK-LABEL: @test_simplify_15(
50 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast <2 x float> [[X:%.*]], [[X]]
51 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast <2 x float> [[SQUARE]], [[X]]
52 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast <2 x float> [[TMP1]], [[TMP1]]
53 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast <2 x float> [[TMP2]], [[TMP2]]
54 ; CHECK-NEXT: [[TMP4:%.*]] = fmul fast <2 x float> [[TMP1]], [[TMP3]]
55 ; CHECK-NEXT: ret <2 x float> [[TMP4]]
57 %1 = call fast <2 x float> @llvm.pow.v2f32(<2 x float> %x, <2 x float> <float 1.500000e+01, float 1.500000e+01>)
62 define <2 x double> @test_simplify_neg_7(<2 x double> %x) {
63 ; CHECK-LABEL: @test_simplify_neg_7(
64 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast <2 x double> [[X:%.*]], [[X]]
65 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast <2 x double> [[SQUARE]], [[SQUARE]]
66 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast <2 x double> [[TMP1]], [[X]]
67 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast <2 x double> [[SQUARE]], [[TMP2]]
68 ; CHECK-NEXT: [[RECIPROCAL:%.*]] = fdiv fast <2 x double> <double 1.000000e+00, double 1.000000e+00>, [[TMP3]]
69 ; CHECK-NEXT: ret <2 x double> [[RECIPROCAL]]
71 %1 = call fast <2 x double> @llvm.pow.v2f64(<2 x double> %x, <2 x double> <double -7.000000e+00, double -7.000000e+00>)
76 define float @test_simplify_neg_19(float %x) {
77 ; CHECK-LABEL: @test_simplify_neg_19(
78 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast float [[X:%.*]], [[X]]
79 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[SQUARE]], [[SQUARE]]
80 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[TMP1]]
81 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast float [[TMP2]], [[TMP2]]
82 ; CHECK-NEXT: [[TMP4:%.*]] = fmul fast float [[SQUARE]], [[TMP3]]
83 ; CHECK-NEXT: [[TMP5:%.*]] = fmul fast float [[TMP4]], [[X]]
84 ; CHECK-NEXT: [[RECIPROCAL:%.*]] = fdiv fast float 1.000000e+00, [[TMP5]]
85 ; CHECK-NEXT: ret float [[RECIPROCAL]]
87 %1 = call fast float @llvm.pow.f32(float %x, float -1.900000e+01)
92 define double @test_simplify_11_23(double %x) {
93 ; CHECK-LABEL: @test_simplify_11_23(
94 ; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.pow.f64(double [[X:%.*]], double 1.123000e+01)
95 ; CHECK-NEXT: ret double [[TMP1]]
97 %1 = call fast double @llvm.pow.f64(double %x, double 1.123000e+01)
102 define float @test_simplify_32(float %x) {
103 ; CHECK-LABEL: @test_simplify_32(
104 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast float [[X:%.*]], [[X]]
105 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[SQUARE]], [[SQUARE]]
106 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[TMP1]]
107 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast float [[TMP2]], [[TMP2]]
108 ; CHECK-NEXT: [[TMP4:%.*]] = fmul fast float [[TMP3]], [[TMP3]]
109 ; CHECK-NEXT: ret float [[TMP4]]
111 %1 = call fast float @llvm.pow.f32(float %x, float 3.200000e+01)
116 define double @test_simplify_33(double %x) {
117 ; CHECKI32-LABEL: @test_simplify_33(
118 ; CHECKI32-NEXT: [[TMP1:%.*]] = call fast double @llvm.powi.f64.i32(double [[X:%.*]], i32 33)
119 ; CHECKI32-NEXT: ret double [[TMP1]]
121 ; CHECKI16-LABEL: @test_simplify_33(
122 ; CHECKI16-NEXT: [[TMP1:%.*]] = call fast double @llvm.powi.f64.i16(double [[X:%.*]], i16 33)
123 ; CHECKI16-NEXT: ret double [[TMP1]]
125 %1 = call fast double @llvm.pow.f64(double %x, double 3.300000e+01)
129 ; pow(x, 16.5) with double
130 define double @test_simplify_16_5(double %x) {
131 ; CHECK-LABEL: @test_simplify_16_5(
132 ; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[X:%.*]])
133 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast double [[X]], [[X]]
134 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
135 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
136 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast double [[TMP2]], [[TMP2]]
137 ; CHECK-NEXT: [[TMP4:%.*]] = fmul fast double [[TMP3]], [[SQRT]]
138 ; CHECK-NEXT: ret double [[TMP4]]
140 %1 = call fast double @llvm.pow.f64(double %x, double 1.650000e+01)
144 ; pow(x, -16.5) with double
145 define double @test_simplify_neg_16_5(double %x) {
146 ; CHECK-LABEL: @test_simplify_neg_16_5(
147 ; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[X:%.*]])
148 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast double [[X]], [[X]]
149 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
150 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
151 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast double [[TMP2]], [[TMP2]]
152 ; CHECK-NEXT: [[TMP4:%.*]] = fmul fast double [[TMP3]], [[SQRT]]
153 ; CHECK-NEXT: [[RECIPROCAL:%.*]] = fdiv fast double 1.000000e+00, [[TMP4]]
154 ; CHECK-NEXT: ret double [[RECIPROCAL]]
156 %1 = call fast double @llvm.pow.f64(double %x, double -1.650000e+01)
160 ; pow(x, 16.5) with double
162 define double @test_simplify_16_5_libcall(double %x) {
163 ; SQRT-LABEL: @test_simplify_16_5_libcall(
164 ; SQRT-NEXT: [[SQRT:%.*]] = call fast double @sqrt(double [[X:%.*]])
165 ; SQRT-NEXT: [[SQUARE:%.*]] = fmul fast double [[X]], [[X]]
166 ; SQRT-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
167 ; SQRT-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
168 ; SQRT-NEXT: [[TMP3:%.*]] = fmul fast double [[TMP2]], [[TMP2]]
169 ; SQRT-NEXT: [[TMP4:%.*]] = fmul fast double [[TMP3]], [[SQRT]]
170 ; SQRT-NEXT: ret double [[TMP4]]
172 ; NOSQRT-LABEL: @test_simplify_16_5_libcall(
173 ; NOSQRT-NEXT: [[TMP1:%.*]] = call fast double @pow(double [[X:%.*]], double 1.650000e+01)
174 ; NOSQRT-NEXT: ret double [[TMP1]]
176 %1 = call fast double @pow(double %x, double 1.650000e+01)
180 ; pow(x, -16.5) with double
182 define double @test_simplify_neg_16_5_libcall(double %x) {
183 ; SQRT-LABEL: @test_simplify_neg_16_5_libcall(
184 ; SQRT-NEXT: [[SQRT:%.*]] = call fast double @sqrt(double [[X:%.*]])
185 ; SQRT-NEXT: [[SQUARE:%.*]] = fmul fast double [[X]], [[X]]
186 ; SQRT-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
187 ; SQRT-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
188 ; SQRT-NEXT: [[TMP3:%.*]] = fmul fast double [[TMP2]], [[TMP2]]
189 ; SQRT-NEXT: [[TMP4:%.*]] = fmul fast double [[TMP3]], [[SQRT]]
190 ; SQRT-NEXT: [[RECIPROCAL:%.*]] = fdiv fast double 1.000000e+00, [[TMP4]]
191 ; SQRT-NEXT: ret double [[RECIPROCAL]]
193 ; NOSQRT-LABEL: @test_simplify_neg_16_5_libcall(
194 ; NOSQRT-NEXT: [[TMP1:%.*]] = call fast double @pow(double [[X:%.*]], double -1.650000e+01)
195 ; NOSQRT-NEXT: ret double [[TMP1]]
197 %1 = call fast double @pow(double %x, double -1.650000e+01)
201 ; pow(x, -8.5) with float
202 define float @test_simplify_neg_8_5(float %x) {
203 ; CHECK-LABEL: @test_simplify_neg_8_5(
204 ; CHECK-NEXT: [[SQRT:%.*]] = call fast float @llvm.sqrt.f32(float [[X:%.*]])
205 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast float [[X]], [[X]]
206 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[SQUARE]], [[SQUARE]]
207 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[SQRT]]
208 ; CHECK-NEXT: [[RECIPROCAL:%.*]] = fdiv fast float 1.000000e+00, [[TMP2]]
209 ; CHECK-NEXT: ret float [[RECIPROCAL]]
211 %1 = call fast float @llvm.pow.f32(float %x, float -0.450000e+01)
215 ; pow(x, 7.5) with <2 x double>
216 define <2 x double> @test_simplify_7_5(<2 x double> %x) {
217 ; CHECK-LABEL: @test_simplify_7_5(
218 ; CHECK-NEXT: [[SQRT:%.*]] = call fast <2 x double> @llvm.sqrt.v2f64(<2 x double> [[X:%.*]])
219 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast <2 x double> [[X]], [[X]]
220 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast <2 x double> [[SQUARE]], [[SQUARE]]
221 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast <2 x double> [[TMP1]], [[X]]
222 ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast <2 x double> [[SQUARE]], [[TMP2]]
223 ; CHECK-NEXT: [[TMP4:%.*]] = fmul fast <2 x double> [[TMP3]], [[SQRT]]
224 ; CHECK-NEXT: ret <2 x double> [[TMP4]]
226 %1 = call fast <2 x double> @llvm.pow.v2f64(<2 x double> %x, <2 x double> <double 7.500000e+00, double 7.500000e+00>)
230 ; pow(x, 3.5) with <4 x float>
231 define <4 x float> @test_simplify_3_5(<4 x float> %x) {
232 ; CHECK-LABEL: @test_simplify_3_5(
233 ; CHECK-NEXT: [[SQRT:%.*]] = call fast <4 x float> @llvm.sqrt.v4f32(<4 x float> [[X:%.*]])
234 ; CHECK-NEXT: [[SQUARE:%.*]] = fmul fast <4 x float> [[X]], [[X]]
235 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast <4 x float> [[SQUARE]], [[X]]
236 ; CHECK-NEXT: [[TMP2:%.*]] = fmul fast <4 x float> [[TMP1]], [[SQRT]]
237 ; CHECK-NEXT: ret <4 x float> [[TMP2]]
239 %1 = call fast <4 x float> @llvm.pow.v4f32(<4 x float> %x, <4 x float> <float 3.500000e+00, float 3.500000e+00, float 3.500000e+00, float 3.500000e+00>)
243 ; (float)pow((double)(float)x, 0.5)
244 define float @shrink_pow_libcall_half(float %x) {
245 ; CHECK-LABEL: @shrink_pow_libcall_half(
246 ; CHECK-NEXT: [[SQRTF:%.*]] = call fast float @sqrtf(float [[X:%.*]])
247 ; CHECK-NEXT: ret float [[SQRTF]]
249 %dx = fpext float %x to double
250 %call = call fast double @pow(double %dx, double 0.5)
251 %fr = fptrunc double %call to float
255 ; Make sure that -0.0 exponent is always simplified.
257 define double @PR43233(double %x) {
258 ; CHECK-LABEL: @PR43233(
259 ; CHECK-NEXT: ret double 1.000000e+00
261 %r = call fast double @llvm.pow.f64(double %x, double -0.0)