summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-12-10 16:52:26 +0000
committerSanjay Patel <spatel@rotateright.com>2017-12-10 16:52:26 +0000
commit09ec34349a51b68dd5b6e5ab023f52230ec1c579 (patch)
tree860c58001a64d91d5420f0335362d2f0d30abf60
parent719bc64ba57b41935a49c7c7ea0f37c3c719c5e2 (diff)
downloadbcm5719-llvm-09ec34349a51b68dd5b6e5ab023f52230ec1c579.tar.gz
bcm5719-llvm-09ec34349a51b68dd5b6e5ab023f52230ec1c579.zip
[SimplifyLibCalls] propagate FMF when folding pow(x, 2.0) call (PR35601)
This should fix the larger problem with sqrt shown in: https://bugs.llvm.org/show_bug.cgi?id=35601 llvm-svn: 320310
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp7
-rw-r--r--llvm/test/Transforms/InstCombine/pow-1.ll4
2 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index c392492e331..273a5e79a7d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1206,8 +1206,13 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) {
if (Op2C->isExactlyValue(1.0)) // pow(x, 1.0) -> x
return Op1;
- if (Op2C->isExactlyValue(2.0)) // pow(x, 2.0) -> x*x
+ if (Op2C->isExactlyValue(2.0)) {
+ // pow(x, 2.0) --> x * x
+ IRBuilder<>::FastMathFlagGuard Guard(B);
+ B.setFastMathFlags(CI->getFastMathFlags());
return B.CreateFMul(Op1, Op1, "pow2");
+ }
+ // FIXME: This should propagate the FMF of the call to the fdiv.
if (Op2C->isExactlyValue(-1.0)) // pow(x, -1.0) -> 1.0/x
return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0), Op1, "powrecip");
diff --git a/llvm/test/Transforms/InstCombine/pow-1.ll b/llvm/test/Transforms/InstCombine/pow-1.ll
index 6c9f39fc0e0..c7ca3cf7547 100644
--- a/llvm/test/Transforms/InstCombine/pow-1.ll
+++ b/llvm/test/Transforms/InstCombine/pow-1.ll
@@ -133,11 +133,11 @@ define float @pow2_strict(float %x) {
ret float %r
}
-; FIXME: Don't drop the FMF - PR35601 ( https://bugs.llvm.org/show_bug.cgi?id=35601 )
+; Don't drop the FMF - PR35601 ( https://bugs.llvm.org/show_bug.cgi?id=35601 )
define float @pow2_fast(float %x) {
; CHECK-LABEL: @pow2_fast(
-; CHECK-NEXT: [[POW2:%.*]] = fmul float %x, %x
+; CHECK-NEXT: [[POW2:%.*]] = fmul fast float %x, %x
; CHECK-NEXT: ret float [[POW2]]
;
%r = call fast float @powf(float %x, float 2.0)
OpenPOWER on IntegriCloud