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");
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)