1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 define float @test1(float %x) nounwind readnone ssp {
6 ; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X:%.*]]) #[[ATTR4:[0-9]+]]
7 ; CHECK-NEXT: ret float [[SQRTF]]
9 %conv = fpext float %x to double
10 %call = tail call double @sqrt(double %conv) readnone nounwind
11 %conv1 = fptrunc double %call to float
17 define float @test2(float %x) nounwind readnone ssp {
18 ; CHECK-LABEL: @test2(
19 ; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X:%.*]]) #[[ATTR4]]
20 ; CHECK-NEXT: ret float [[SQRTF]]
22 %conv = fpext float %x to double
23 %call = tail call double @sqrt(double %conv) nounwind
24 %conv1 = fptrunc double %call to float
29 ; Can't fold (fptrunc (sqrt (fpext x))) -> (sqrtf x) since there is another
32 define float @test3(ptr %v) nounwind uwtable ssp {
33 ; CHECK-LABEL: @test3(
34 ; CHECK-NEXT: [[CALL34:%.*]] = call double @sqrt(double 0x7FF8000000000000) #[[ATTR4]]
35 ; CHECK-NEXT: [[CALL36:%.*]] = call i32 @foo(double [[CALL34]]) #[[ATTR5:[0-9]+]]
36 ; CHECK-NEXT: [[CONV38:%.*]] = fptrunc double [[CALL34]] to float
37 ; CHECK-NEXT: ret float [[CONV38]]
39 %arrayidx13 = getelementptr inbounds float, ptr %v, i64 2
40 %tmp14 = load float, ptr %arrayidx13
41 %mul18 = fmul float %tmp14, %tmp14
42 %add19 = fadd float undef, %mul18
43 %conv = fpext float %add19 to double
44 %call34 = call double @sqrt(double %conv) readnone
45 %call36 = call i32 (double) @foo(double %call34) nounwind
46 %conv38 = fptrunc double %call34 to float
50 ; PR43347 - https://bugs.llvm.org/show_bug.cgi?id=43347
52 define void @0(float %f) {
54 ; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[F:%.*]]) #[[ATTR2:[0-9]+]]
55 ; CHECK-NEXT: ret void
57 %d = fpext float %f to double
58 %r = call double @sqrt(double %d)
62 define float @sqrt_call_nnan_f32(float %x) {
63 ; CHECK-LABEL: @sqrt_call_nnan_f32(
64 ; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @sqrtf(float [[X:%.*]])
65 ; CHECK-NEXT: ret float [[SQRT]]
67 %sqrt = call nnan float @sqrtf(float %x)
71 define double @sqrt_call_nnan_f64(double %x) {
72 ; CHECK-LABEL: @sqrt_call_nnan_f64(
73 ; CHECK-NEXT: [[SQRT:%.*]] = tail call nnan ninf double @sqrt(double [[X:%.*]])
74 ; CHECK-NEXT: ret double [[SQRT]]
76 %sqrt = tail call nnan ninf double @sqrt(double %x)
80 define float @sqrt_call_fabs_f32(float %x) {
81 ; CHECK-LABEL: @sqrt_call_fabs_f32(
82 ; CHECK-NEXT: [[A:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
83 ; CHECK-NEXT: [[SQRT:%.*]] = tail call float @sqrtf(float [[A]])
84 ; CHECK-NEXT: ret float [[SQRT]]
86 %a = call float @llvm.fabs.f32(float %x)
87 %sqrt = tail call float @sqrtf(float %a)
91 define double @sqrt_exp(double %x) {
92 ; CHECK-LABEL: @sqrt_exp(
93 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc double [[X:%.*]], 5.000000e-01
94 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @llvm.exp.f64(double [[MERGED_SQRT]])
95 ; CHECK-NEXT: ret double [[E]]
97 %e = call reassoc double @llvm.exp.f64(double %x)
98 %res = call reassoc double @llvm.sqrt.f64(double %e)
102 define double @sqrt_exp_2(double %x) {
103 ; CHECK-LABEL: @sqrt_exp_2(
104 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc double [[X:%.*]], 5.000000e-01
105 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @exp(double [[MERGED_SQRT]])
106 ; CHECK-NEXT: ret double [[E]]
108 %e = call reassoc double @exp(double %x)
109 %res = call reassoc double @sqrt(double %e)
113 define double @sqrt_exp2(double %x) {
114 ; CHECK-LABEL: @sqrt_exp2(
115 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc double [[X:%.*]], 5.000000e-01
116 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @exp2(double [[MERGED_SQRT]])
117 ; CHECK-NEXT: ret double [[E]]
119 %e = call reassoc double @exp2(double %x)
120 %res = call reassoc double @sqrt(double %e)
124 define double @sqrt_exp10(double %x) {
125 ; CHECK-LABEL: @sqrt_exp10(
126 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc double [[X:%.*]], 5.000000e-01
127 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @exp10(double [[MERGED_SQRT]])
128 ; CHECK-NEXT: ret double [[E]]
130 %e = call reassoc double @exp10(double %x)
131 %res = call reassoc double @sqrt(double %e)
136 define double @sqrt_exp_nofast_1(double %x) {
137 ; CHECK-LABEL: @sqrt_exp_nofast_1(
138 ; CHECK-NEXT: [[E:%.*]] = call double @llvm.exp.f64(double [[X:%.*]])
139 ; CHECK-NEXT: [[RES:%.*]] = call reassoc double @llvm.sqrt.f64(double [[E]])
140 ; CHECK-NEXT: ret double [[RES]]
142 %e = call double @llvm.exp.f64(double %x)
143 %res = call reassoc double @llvm.sqrt.f64(double %e)
148 define double @sqrt_exp_nofast_2(double %x) {
149 ; CHECK-LABEL: @sqrt_exp_nofast_2(
150 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @llvm.exp.f64(double [[X:%.*]])
151 ; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sqrt.f64(double [[E]])
152 ; CHECK-NEXT: ret double [[RES]]
154 %e = call reassoc double @llvm.exp.f64(double %x)
155 %res = call double @llvm.sqrt.f64(double %e)
159 define double @sqrt_exp_merge_constant(double %x, double %y) {
160 ; CHECK-LABEL: @sqrt_exp_merge_constant(
161 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc nsz double [[X:%.*]], 5.000000e+00
162 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @llvm.exp.f64(double [[MERGED_SQRT]])
163 ; CHECK-NEXT: ret double [[E]]
165 %mul = fmul reassoc nsz double %x, 10.0
166 %e = call reassoc double @llvm.exp.f64(double %mul)
167 %res = call reassoc nsz double @llvm.sqrt.f64(double %e)
171 define double @sqrt_exp_intr_and_libcall(double %x) {
172 ; CHECK-LABEL: @sqrt_exp_intr_and_libcall(
173 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc double [[X:%.*]], 5.000000e-01
174 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @exp(double [[MERGED_SQRT]])
175 ; CHECK-NEXT: ret double [[E]]
177 %e = call reassoc double @exp(double %x)
178 %res = call reassoc double @llvm.sqrt.f64(double %e)
182 define double @sqrt_exp_intr_and_libcall_2(double %x) {
183 ; CHECK-LABEL: @sqrt_exp_intr_and_libcall_2(
184 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc double [[X:%.*]], 5.000000e-01
185 ; CHECK-NEXT: [[E:%.*]] = call reassoc double @llvm.exp.f64(double [[MERGED_SQRT]])
186 ; CHECK-NEXT: ret double [[E]]
188 %e = call reassoc double @llvm.exp.f64(double %x)
189 %res = call reassoc double @sqrt(double %e)
193 define <2 x float> @sqrt_exp_vec(<2 x float> %x) {
194 ; CHECK-LABEL: @sqrt_exp_vec(
195 ; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul reassoc <2 x float> [[X:%.*]], <float 5.000000e-01, float 5.000000e-01>
196 ; CHECK-NEXT: [[E:%.*]] = call reassoc <2 x float> @llvm.exp.v2f32(<2 x float> [[MERGED_SQRT]])
197 ; CHECK-NEXT: ret <2 x float> [[E]]
199 %e = call reassoc <2 x float> @llvm.exp.v2f32(<2 x float> %x)
200 %res = call reassoc <2 x float> @llvm.sqrt.v2f32(<2 x float> %e)
204 declare i32 @foo(double)
205 declare double @sqrt(double) readnone
206 declare float @sqrtf(float)
207 declare float @llvm.fabs.f32(float)
208 declare double @llvm.exp.f64(double)
209 declare double @llvm.sqrt.f64(double)
210 declare double @exp(double)
211 declare double @exp2(double)
212 declare double @exp10(double)
213 declare <2 x float> @llvm.exp.v2f32(<2 x float>)
214 declare <2 x float> @llvm.sqrt.v2f32(<2 x float>)