Skip to content

Commit b33b291

Browse files
committed
[InstCombine] Propagate ninf/nnan from fcmp to select.
1 parent 244df79 commit b33b291

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/IR/ConstantRange.h"
2626
#include "llvm/IR/Constants.h"
2727
#include "llvm/IR/DerivedTypes.h"
28+
#include "llvm/IR/FMF.h"
2829
#include "llvm/IR/IRBuilder.h"
2930
#include "llvm/IR/InstrTypes.h"
3031
#include "llvm/IR/Instruction.h"
@@ -3881,8 +3882,14 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
38813882
FCmpInst::Predicate InvPred = FCmp->getInversePredicate();
38823883
Value *NewCond = Builder.CreateFCmpFMF(InvPred, Cmp0, Cmp1, FCmp,
38833884
FCmp->getName() + ".inv");
3885+
// Propagate ninf/nnan from fcmp to select.
3886+
FastMathFlags FMF = SI.getFastMathFlags();
3887+
if (FCmp->hasNoNaNs())
3888+
FMF.setNoNaNs(true);
3889+
if (FCmp->hasNoInfs())
3890+
FMF.setNoInfs(true);
38843891
Value *NewSel =
3885-
Builder.CreateSelectFMF(NewCond, FalseVal, TrueVal, &SI);
3892+
Builder.CreateSelectFMF(NewCond, FalseVal, TrueVal, FMF);
38863893
return replaceInstUsesWith(SI, NewSel);
38873894
}
38883895
}

0 commit comments

Comments
 (0)