Commit 716b9dd0 authored by Valery N Dmitriev's avatar Valery N Dmitriev
Browse files

[InstCombine] Preserve FMF for powi simplifications.

Differential Revision: https://reviews.llvm.org/D95455
parent c8df2d1b
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -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;

+2 −2
Original line number Diff line number Diff line
@@ -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
;