[llvm] r320310 - [SimplifyLibCalls] propagate FMF when folding pow(x, 2.0) call (PR35601)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 10 08:52:26 PST 2017
Author: spatel
Date: Sun Dec 10 08:52:26 2017
New Revision: 320310
URL: http://llvm.org/viewvc/llvm-project?rev=320310&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/pow-1.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=320310&r1=320309&r2=320310&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Sun Dec 10 08:52:26 2017
@@ -1206,8 +1206,13 @@ Value *LibCallSimplifier::optimizePow(Ca
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");
Modified: llvm/trunk/test/Transforms/InstCombine/pow-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pow-1.ll?rev=320310&r1=320309&r2=320310&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pow-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/pow-1.ll Sun Dec 10 08:52:26 2017
@@ -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)
More information about the llvm-commits
mailing list