@@ -3680,30 +3680,13 @@ static Value *foldSelectIntoAddConstant(SelectInst &SI,
3680
3680
Value *NewFAdd = Builder.CreateFAdd (NewSelect, C);
3681
3681
NewFAdd->takeName (FAdd);
3682
3682
3683
- // Propagate rewrite-based flags
3684
- auto SelectFMF = SI.getFastMathFlags ();
3685
- auto FAddFMF = FAdd->getFastMathFlags ();
3686
- FastMathFlags CommonFMF, NewFAddFMF, NewSelectFMF;
3687
-
3688
- CommonFMF.setAllowReassoc (SelectFMF.allowReassoc () &&
3689
- FAddFMF.allowReassoc ());
3690
- CommonFMF.setAllowReciprocal (SelectFMF.allowReciprocal () &&
3691
- FAddFMF.allowReciprocal ());
3692
- CommonFMF.setAllowContract (SelectFMF.allowContract () &&
3693
- FAddFMF.allowContract ());
3694
- CommonFMF.setApproxFunc (SelectFMF.approxFunc () && FAddFMF.approxFunc ());
3695
- NewSelectFMF = NewFAddFMF = CommonFMF;
3696
-
3697
3683
// Propagate FastMath flags
3698
- NewFAddFMF.setNoNaNs (FAddFMF.noNaNs ());
3699
- NewFAddFMF.setNoInfs (FAddFMF.noInfs ());
3700
- NewFAddFMF.setNoSignedZeros (FAddFMF.noSignedZeros ());
3701
- cast<Instruction>(NewFAdd)->setFastMathFlags (NewFAddFMF);
3702
-
3703
- NewSelectFMF.setNoNaNs (SelectFMF.noNaNs ());
3704
- NewSelectFMF.setNoInfs (SelectFMF.noInfs ());
3705
- NewSelectFMF.setNoSignedZeros (SelectFMF.noSignedZeros ());
3706
- cast<Instruction>(NewSelect)->setFastMathFlags (NewSelectFMF);
3684
+ FastMathFlags SelectFMF = SI.getFastMathFlags ();
3685
+ FastMathFlags FAddFMF = FAdd->getFastMathFlags ();
3686
+ FastMathFlags NewFMF = FastMathFlags::intersectRewrite (SelectFMF, FAddFMF) |
3687
+ FastMathFlags::unionValue (SelectFMF, FAddFMF);
3688
+ cast<Instruction>(NewFAdd)->setFastMathFlags (NewFMF);
3689
+ cast<Instruction>(NewSelect)->setFastMathFlags (NewFMF);
3707
3690
3708
3691
return NewFAdd;
3709
3692
}
0 commit comments