[llvm] r258153 - [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, [small integer]) calls
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 19 10:15:15 PST 2016
Author: spatel
Date: Tue Jan 19 12:15:12 2016
New Revision: 258153
URL: http://llvm.org/viewvc/llvm-project?rev=258153&view=rev
Log:
[LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, [small integer]) calls
This is a continuation of adding FMF to call instructions:
http://reviews.llvm.org/rL255555
As with D15937, the intent of the patch is to preserve the current behavior of the transform
except that we use the pow call's 'fast' attribute as a trigger rather than a function-level
attribute.
The TODO comment notes a potential follow-on patch that would propagate FMF to the new
instructions.
Differential Revision: http://reviews.llvm.org/D16122
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/pow-4.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=258153&r1=258152&r2=258153&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Jan 19 12:15:12 2016
@@ -1127,9 +1127,6 @@ Value *LibCallSimplifier::optimizePow(Ca
Callee->getAttributes());
}
- // FIXME: Use instruction-level FMF.
- bool UnsafeFPMath = canUseUnsafeFPMath(CI->getParent()->getParent());
-
// pow(exp(x), y) -> exp(x * y)
// pow(exp2(x), y) -> exp2(x * y)
// We enable these only with fast-math. Besides rounding differences, the
@@ -1193,7 +1190,7 @@ Value *LibCallSimplifier::optimizePow(Ca
return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0), Op1, "powrecip");
// In -ffast-math, generate repeated fmul instead of generating pow(x, n).
- if (UnsafeFPMath) {
+ if (CI->hasUnsafeAlgebra()) {
APFloat V = abs(Op2C->getValueAPF());
// We limit to a max of 7 fmul(s). Thus max exponent is 32.
// This transformation applies to integer exponents only.
@@ -1210,6 +1207,8 @@ Value *LibCallSimplifier::optimizePow(Ca
// So we first convert V to something which could be converted to double.
bool ignored;
V.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &ignored);
+
+ // TODO: Should the new instructions propagate the 'fast' flag of the pow()?
Value *FMul = getPow(InnerChain, V.convertToDouble(), B);
// For negative exponents simply compute the reciprocal.
if (Op2C->isNegative())
Modified: llvm/trunk/test/Transforms/InstCombine/pow-4.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pow-4.ll?rev=258153&r1=258152&r2=258153&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pow-4.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/pow-4.ll Tue Jan 19 12:15:12 2016
@@ -7,40 +7,40 @@ declare double @llvm.pow.f64(double, dou
declare float @llvm.pow.f32(float, float)
; pow(x, 4.0f)
-define float @test_simplify_4f(float %x) #0 {
+define float @test_simplify_4f(float %x) {
; CHECK-LABEL: @test_simplify_4f(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul float %x, %x
; CHECK-NEXT: %2 = fmul float %1, %1
; CHECK-NEXT: ret float %2
- %1 = call float @llvm.pow.f32(float %x, float 4.000000e+00)
+ %1 = call fast float @llvm.pow.f32(float %x, float 4.000000e+00)
ret float %1
}
; pow(x, 3.0)
-define double @test_simplify_3(double %x) #0 {
+define double @test_simplify_3(double %x) {
; CHECK-LABEL: @test_simplify_3(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul double %x, %x
; CHECK-NEXT: %2 = fmul double %1, %x
; CHECK-NEXT: ret double %2
- %1 = call double @llvm.pow.f64(double %x, double 3.000000e+00)
+ %1 = call fast double @llvm.pow.f64(double %x, double 3.000000e+00)
ret double %1
}
; pow(x, 4.0)
-define double @test_simplify_4(double %x) #0 {
+define double @test_simplify_4(double %x) {
; CHECK-LABEL: @test_simplify_4(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul double %x, %x
; CHECK-NEXT: %2 = fmul double %1, %1
; CHECK-NEXT: ret double %2
- %1 = call double @llvm.pow.f64(double %x, double 4.000000e+00)
+ %1 = call fast double @llvm.pow.f64(double %x, double 4.000000e+00)
ret double %1
}
; pow(x, 15.0)
-define double @test_simplify_15(double %x) #0 {
+define double @test_simplify_15(double %x) {
; CHECK-LABEL: @test_simplify_15(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul double %x, %x
@@ -49,12 +49,12 @@ define double @test_simplify_15(double %
; CHECK-NEXT: %4 = fmul double %3, %3
; CHECK-NEXT: %5 = fmul double %2, %4
; CHECK-NEXT: ret double %5
- %1 = call double @llvm.pow.f64(double %x, double 1.500000e+01)
+ %1 = call fast double @llvm.pow.f64(double %x, double 1.500000e+01)
ret double %1
}
; pow(x, -7.0)
-define double @test_simplify_neg_7(double %x) #0 {
+define double @test_simplify_neg_7(double %x) {
; CHECK-LABEL: @test_simplify_neg_7(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul double %x, %x
@@ -63,12 +63,12 @@ define double @test_simplify_neg_7(doubl
; CHECK-NEXT: %4 = fmul double %1, %3
; CHECK-NEXT: %5 = fdiv double 1.000000e+00, %4
; CHECK-NEXT: ret double %5
- %1 = call double @llvm.pow.f64(double %x, double -7.000000e+00)
+ %1 = call fast double @llvm.pow.f64(double %x, double -7.000000e+00)
ret double %1
}
; pow(x, -19.0)
-define double @test_simplify_neg_19(double %x) #0 {
+define double @test_simplify_neg_19(double %x) {
; CHECK-LABEL: @test_simplify_neg_19(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul double %x, %x
@@ -79,22 +79,22 @@ define double @test_simplify_neg_19(doub
; CHECK-NEXT: %6 = fmul double %5, %x
; CHECK-NEXT: %7 = fdiv double 1.000000e+00, %6
; CHECK-NEXT: ret double %7
- %1 = call double @llvm.pow.f64(double %x, double -1.900000e+01)
+ %1 = call fast double @llvm.pow.f64(double %x, double -1.900000e+01)
ret double %1
}
; pow(x, 11.23)
-define double @test_simplify_11_23(double %x) #0 {
+define double @test_simplify_11_23(double %x) {
; CHECK-LABEL: @test_simplify_11_23(
; CHECK-NOT: fmul
-; CHECK-NEXT: %1 = call double @llvm.pow.f64(double %x, double 1.123000e+01)
+; CHECK-NEXT: %1 = call fast double @llvm.pow.f64(double %x, double 1.123000e+01)
; CHECK-NEXT: ret double %1
- %1 = call double @llvm.pow.f64(double %x, double 1.123000e+01)
+ %1 = call fast double @llvm.pow.f64(double %x, double 1.123000e+01)
ret double %1
}
; pow(x, 32.0)
-define double @test_simplify_32(double %x) #0 {
+define double @test_simplify_32(double %x) {
; CHECK-LABEL: @test_simplify_32(
; CHECK-NOT: pow
; CHECK-NEXT: %1 = fmul double %x, %x
@@ -103,18 +103,17 @@ define double @test_simplify_32(double %
; CHECK-NEXT: %4 = fmul double %3, %3
; CHECK-NEXT: %5 = fmul double %4, %4
; CHECK-NEXT: ret double %5
- %1 = call double @llvm.pow.f64(double %x, double 3.200000e+01)
+ %1 = call fast double @llvm.pow.f64(double %x, double 3.200000e+01)
ret double %1
}
; pow(x, 33.0)
-define double @test_simplify_33(double %x) #0 {
+define double @test_simplify_33(double %x) {
; CHECK-LABEL: @test_simplify_33(
; CHECK-NOT: fmul
-; CHECK-NEXT: %1 = call double @llvm.pow.f64(double %x, double 3.300000e+01)
+; CHECK-NEXT: %1 = call fast double @llvm.pow.f64(double %x, double 3.300000e+01)
; CHECK-NEXT: ret double %1
- %1 = call double @llvm.pow.f64(double %x, double 3.300000e+01)
+ %1 = call fast double @llvm.pow.f64(double %x, double 3.300000e+01)
ret double %1
}
-attributes #0 = { nounwind readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "unsafe-fp-math"="true" "use-soft-float"="false" }
More information about the llvm-commits
mailing list