forked from OSchip/llvm-project
[InstCombine] Preserve FMF for powi simplifications.
Differential Revision: https://reviews.llvm.org/D95455
This commit is contained in:
parent
c8df2d1bde
commit
716b9dd0d8
|
@ -886,15 +886,14 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
|
|||
case Intrinsic::powi:
|
||||
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
|
||||
// 0 and 1 are handled in instsimplify
|
||||
|
||||
// powi(x, -1) -> 1/x
|
||||
if (Power->isMinusOne())
|
||||
return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0),
|
||||
II->getArgOperand(0));
|
||||
return BinaryOperator::CreateFDivFMF(ConstantFP::get(CI.getType(), 1.0),
|
||||
II->getArgOperand(0), II);
|
||||
// powi(x, 2) -> x*x
|
||||
if (Power->equalsInt(2))
|
||||
return BinaryOperator::CreateFMul(II->getArgOperand(0),
|
||||
II->getArgOperand(0));
|
||||
return BinaryOperator::CreateFMulFMF(II->getArgOperand(0),
|
||||
II->getArgOperand(0), II);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ declare double @llvm.nearbyint.f64(double %Val) nounwind readonly
|
|||
|
||||
define void @powi(double %V, double *%P) {
|
||||
; CHECK-LABEL: @powi(
|
||||
; CHECK-NEXT: [[A:%.*]] = fdiv double 1.000000e+00, [[V:%.*]]
|
||||
; CHECK-NEXT: [[A:%.*]] = fdiv fast double 1.000000e+00, [[V:%.*]]
|
||||
; CHECK-NEXT: store volatile double [[A]], double* [[P:%.*]], align 8
|
||||
; CHECK-NEXT: [[D:%.*]] = fmul double [[V]], [[V]]
|
||||
; CHECK-NEXT: [[D:%.*]] = fmul nnan double [[V]], [[V]]
|
||||
; CHECK-NEXT: store volatile double [[D]], double* [[P]], align 8
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue