Skip to content

Commit 716b9dd

Browse files
author
Valery N Dmitriev
committed
[InstCombine] Preserve FMF for powi simplifications.
Differential Revision: https://reviews.llvm.org/D95455
1 parent c8df2d1 commit 716b9dd

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,15 +886,14 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
886886
case Intrinsic::powi:
887887
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
888888
// 0 and 1 are handled in instsimplify
889-
890889
// powi(x, -1) -> 1/x
891890
if (Power->isMinusOne())
892-
return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0),
893-
II->getArgOperand(0));
891+
return BinaryOperator::CreateFDivFMF(ConstantFP::get(CI.getType(), 1.0),
892+
II->getArgOperand(0), II);
894893
// powi(x, 2) -> x*x
895894
if (Power->equalsInt(2))
896-
return BinaryOperator::CreateFMul(II->getArgOperand(0),
897-
II->getArgOperand(0));
895+
return BinaryOperator::CreateFMulFMF(II->getArgOperand(0),
896+
II->getArgOperand(0), II);
898897
}
899898
break;
900899

llvm/test/Transforms/InstCombine/intrinsics.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ declare double @llvm.nearbyint.f64(double %Val) nounwind readonly
2222

2323
define void @powi(double %V, double *%P) {
2424
; CHECK-LABEL: @powi(
25-
; CHECK-NEXT: [[A:%.*]] = fdiv double 1.000000e+00, [[V:%.*]]
25+
; CHECK-NEXT: [[A:%.*]] = fdiv fast double 1.000000e+00, [[V:%.*]]
2626
; CHECK-NEXT: store volatile double [[A]], double* [[P:%.*]], align 8
27-
; CHECK-NEXT: [[D:%.*]] = fmul double [[V]], [[V]]
27+
; CHECK-NEXT: [[D:%.*]] = fmul nnan double [[V]], [[V]]
2828
; CHECK-NEXT: store volatile double [[D]], double* [[P]], align 8
2929
; CHECK-NEXT: ret void
3030
;

0 commit comments

Comments
 (0)