@@ -2522,13 +2522,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
25222522 default :
25232523 llvm_unreachable (" unexpected intrinsic ID" );
25242524 }
2525- Value *V = Builder.CreateBinaryIntrinsic (
2526- IID, X, ConstantFP::get (Arg0->getType (), Res), II);
25272525 // TODO: Conservatively intersecting FMF. If Res == C2, the transform
25282526 // was a simplification (so Arg0 and its original flags could
25292527 // propagate?)
2530- if (auto *CI = dyn_cast<CallInst>(V))
2531- CI->andIRFlags (M);
2528+ Value *V = Builder.CreateBinaryIntrinsic (
2529+ IID, X, ConstantFP::get (Arg0->getType (), Res),
2530+ FMFSource::intersect (II, M));
25322531 return replaceInstUsesWith (*II, V);
25332532 }
25342533 }
@@ -2623,13 +2622,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
26232622 }
26242623 case Intrinsic::fmuladd: {
26252624 // Try to simplify the underlying FMul.
2626- if (Value *V = simplifyFMulInst (II->getArgOperand (0 ), II->getArgOperand (1 ),
2627- II->getFastMathFlags (),
2628- SQ.getWithInstruction (II))) {
2629- auto *FAdd = BinaryOperator::CreateFAdd (V, II->getArgOperand (2 ));
2630- FAdd->copyFastMathFlags (II);
2631- return FAdd;
2632- }
2625+ if (Value *V =
2626+ simplifyFMulInst (II->getArgOperand (0 ), II->getArgOperand (1 ),
2627+ II->getFastMathFlags (), SQ.getWithInstruction (II)))
2628+ return BinaryOperator::CreateFAddFMF (V, II->getArgOperand (2 ),
2629+ II->getFastMathFlags ());
26332630
26342631 [[fallthrough]];
26352632 }
@@ -2656,11 +2653,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
26562653 // Try to simplify the underlying FMul. We can only apply simplifications
26572654 // that do not require rounding.
26582655 if (Value *V = simplifyFMAFMul (Src0, Src1, II->getFastMathFlags (),
2659- SQ.getWithInstruction (II))) {
2660- auto *FAdd = BinaryOperator::CreateFAdd (V, Src2);
2661- FAdd->copyFastMathFlags (II);
2662- return FAdd;
2663- }
2656+ SQ.getWithInstruction (II)))
2657+ return BinaryOperator::CreateFAddFMF (V, Src2, II->getFastMathFlags ());
26642658
26652659 // fma x, y, 0 -> fmul x, y
26662660 // This is always valid for -0.0, but requires nsz for +0.0 as
@@ -2754,8 +2748,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
27542748 m_CopySign (m_Value (Magnitude), m_Value (Sign)))) {
27552749 // fabs (copysign x, y) -> (fabs x)
27562750 CallInst *AbsSign =
2757- Builder.CreateCall (II->getCalledFunction (), {Magnitude});
2758- AbsSign->copyFastMathFlags (II);
2751+ Builder.CreateUnaryIntrinsic (Intrinsic::fabs, Magnitude, II);
27592752 return replaceInstUsesWith (*II, AbsSign);
27602753 }
27612754
@@ -2862,16 +2855,15 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
28622855 Value *NewLdexp = nullptr ;
28632856 Value *Select = nullptr ;
28642857 if (match (SelectRHS, m_ZeroInt ())) {
2865- NewLdexp = Builder.CreateLdexp (Src, SelectLHS);
2858+ NewLdexp = Builder.CreateLdexp (Src, SelectLHS, II );
28662859 Select = Builder.CreateSelect (SelectCond, NewLdexp, Src);
28672860 } else if (match (SelectLHS, m_ZeroInt ())) {
2868- NewLdexp = Builder.CreateLdexp (Src, SelectRHS);
2861+ NewLdexp = Builder.CreateLdexp (Src, SelectRHS, II );
28692862 Select = Builder.CreateSelect (SelectCond, Src, NewLdexp);
28702863 }
28712864
28722865 if (NewLdexp) {
28732866 Select->takeName (II);
2874- cast<Instruction>(NewLdexp)->copyFastMathFlags (II);
28752867 return replaceInstUsesWith (*II, Select);
28762868 }
28772869 }
0 commit comments