@@ -2500,13 +2500,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
25002500 default :
25012501 llvm_unreachable (" unexpected intrinsic ID" );
25022502 }
2503- Value *V = Builder.CreateBinaryIntrinsic (
2504- IID, X, ConstantFP::get (Arg0->getType (), Res), II);
25052503 // TODO: Conservatively intersecting FMF. If Res == C2, the transform
25062504 // was a simplification (so Arg0 and its original flags could
25072505 // propagate?)
2508- if (auto *CI = dyn_cast<CallInst>(V))
2509- CI->andIRFlags (M);
2506+ Value *V = Builder.CreateBinaryIntrinsic (
2507+ IID, X, ConstantFP::get (Arg0->getType (), Res),
2508+ II->getFastMathFlags () & M->getFastMathFlags ());
25102509 return replaceInstUsesWith (*II, V);
25112510 }
25122511 }
@@ -2601,13 +2600,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
26012600 }
26022601 case Intrinsic::fmuladd: {
26032602 // Try to simplify the underlying FMul.
2604- if (Value *V = simplifyFMulInst (II->getArgOperand (0 ), II->getArgOperand (1 ),
2605- II->getFastMathFlags (),
2606- SQ.getWithInstruction (II))) {
2607- auto *FAdd = BinaryOperator::CreateFAdd (V, II->getArgOperand (2 ));
2608- FAdd->copyFastMathFlags (II);
2609- return FAdd;
2610- }
2603+ if (Value *V =
2604+ simplifyFMulInst (II->getArgOperand (0 ), II->getArgOperand (1 ),
2605+ II->getFastMathFlags (), SQ.getWithInstruction (II)))
2606+ return BinaryOperator::CreateFAddFMF (V, II->getArgOperand (2 ),
2607+ II->getFastMathFlags ());
26112608
26122609 [[fallthrough]];
26132610 }
@@ -2634,11 +2631,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
26342631 // Try to simplify the underlying FMul. We can only apply simplifications
26352632 // that do not require rounding.
26362633 if (Value *V = simplifyFMAFMul (Src0, Src1, II->getFastMathFlags (),
2637- SQ.getWithInstruction (II))) {
2638- auto *FAdd = BinaryOperator::CreateFAdd (V, Src2);
2639- FAdd->copyFastMathFlags (II);
2640- return FAdd;
2641- }
2634+ SQ.getWithInstruction (II)))
2635+ return BinaryOperator::CreateFAddFMF (V, Src2, II->getFastMathFlags ());
26422636
26432637 // fma x, y, 0 -> fmul x, y
26442638 // This is always valid for -0.0, but requires nsz for +0.0 as
@@ -2732,8 +2726,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
27322726 m_CopySign (m_Value (Magnitude), m_Value (Sign)))) {
27332727 // fabs (copysign x, y) -> (fabs x)
27342728 CallInst *AbsSign =
2735- Builder.CreateCall (II->getCalledFunction (), {Magnitude});
2736- AbsSign->copyFastMathFlags (II);
2729+ Builder.CreateUnaryIntrinsic (Intrinsic::fabs, Magnitude, II);
27372730 return replaceInstUsesWith (*II, AbsSign);
27382731 }
27392732
@@ -2840,16 +2833,15 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
28402833 Value *NewLdexp = nullptr ;
28412834 Value *Select = nullptr ;
28422835 if (match (SelectRHS, m_ZeroInt ())) {
2843- NewLdexp = Builder.CreateLdexp (Src, SelectLHS);
2836+ NewLdexp = Builder.CreateLdexp (Src, SelectLHS, II );
28442837 Select = Builder.CreateSelect (SelectCond, NewLdexp, Src);
28452838 } else if (match (SelectLHS, m_ZeroInt ())) {
2846- NewLdexp = Builder.CreateLdexp (Src, SelectRHS);
2839+ NewLdexp = Builder.CreateLdexp (Src, SelectRHS, II );
28472840 Select = Builder.CreateSelect (SelectCond, Src, NewLdexp);
28482841 }
28492842
28502843 if (NewLdexp) {
28512844 Select->takeName (II);
2852- cast<Instruction>(NewLdexp)->copyFastMathFlags (II);
28532845 return replaceInstUsesWith (*II, Select);
28542846 }
28552847 }
0 commit comments