diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/pow-1.ll | 4 |
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) |

