@@ -2522,13 +2522,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2522
2522
default :
2523
2523
llvm_unreachable (" unexpected intrinsic ID" );
2524
2524
}
2525
- Value *V = Builder.CreateBinaryIntrinsic (
2526
- IID, X, ConstantFP::get (Arg0->getType (), Res), II);
2527
2525
// TODO: Conservatively intersecting FMF. If Res == C2, the transform
2528
2526
// was a simplification (so Arg0 and its original flags could
2529
2527
// 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));
2532
2531
return replaceInstUsesWith (*II, V);
2533
2532
}
2534
2533
}
@@ -2623,13 +2622,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2623
2622
}
2624
2623
case Intrinsic::fmuladd: {
2625
2624
// 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 ());
2633
2630
2634
2631
[[fallthrough]];
2635
2632
}
@@ -2656,11 +2653,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2656
2653
// Try to simplify the underlying FMul. We can only apply simplifications
2657
2654
// that do not require rounding.
2658
2655
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 ());
2664
2658
2665
2659
// fma x, y, 0 -> fmul x, y
2666
2660
// This is always valid for -0.0, but requires nsz for +0.0 as
@@ -2754,8 +2748,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2754
2748
m_CopySign (m_Value (Magnitude), m_Value (Sign)))) {
2755
2749
// fabs (copysign x, y) -> (fabs x)
2756
2750
CallInst *AbsSign =
2757
- Builder.CreateCall (II->getCalledFunction (), {Magnitude});
2758
- AbsSign->copyFastMathFlags (II);
2751
+ Builder.CreateUnaryIntrinsic (Intrinsic::fabs, Magnitude, II);
2759
2752
return replaceInstUsesWith (*II, AbsSign);
2760
2753
}
2761
2754
@@ -2862,16 +2855,15 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2862
2855
Value *NewLdexp = nullptr ;
2863
2856
Value *Select = nullptr ;
2864
2857
if (match (SelectRHS, m_ZeroInt ())) {
2865
- NewLdexp = Builder.CreateLdexp (Src, SelectLHS);
2858
+ NewLdexp = Builder.CreateLdexp (Src, SelectLHS, II );
2866
2859
Select = Builder.CreateSelect (SelectCond, NewLdexp, Src);
2867
2860
} else if (match (SelectLHS, m_ZeroInt ())) {
2868
- NewLdexp = Builder.CreateLdexp (Src, SelectRHS);
2861
+ NewLdexp = Builder.CreateLdexp (Src, SelectRHS, II );
2869
2862
Select = Builder.CreateSelect (SelectCond, Src, NewLdexp);
2870
2863
}
2871
2864
2872
2865
if (NewLdexp) {
2873
2866
Select->takeName (II);
2874
- cast<Instruction>(NewLdexp)->copyFastMathFlags (II);
2875
2867
return replaceInstUsesWith (*II, Select);
2876
2868
}
2877
2869
}
0 commit comments