Skip to content

Commit ebdd385

Browse files
committed
[SelectionDAG] also deduce nnan from users
1 parent c5f8d91 commit ebdd385

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,6 +6714,9 @@ static SDValue foldAndOrOfSETCC(SDNode *LogicOp, SelectionDAG &DAG) {
67146714
DAG, isFMAXNUMFMINNUM_IEEE, isFMAXNUMFMINNUM);
67156715

67166716
if (NewOpcode != ISD::DELETED_NODE) {
6717+
// Propagate fast-math flags from setcc.
6718+
SelectionDAG::FlagInserter FlagInserter(DAG, LHS->getFlags() &
6719+
RHS->getFlags());
67176720
SDValue MinMaxValue =
67186721
DAG.getNode(NewOpcode, DL, OpVT, Operand1, Operand2);
67196722
return DAG.getSetCC(DL, VT, MinMaxValue, CommonValue, CC);

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5869,6 +5869,12 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, bool SNaN,
58695869
? APInt::getAllOnes(VT.getVectorNumElements())
58705870
: APInt(1, 1);
58715871

5872+
// If all users of this operand is annotated with nnan, we can assume
5873+
// this operand is not NaN, since nnan also affects inputs.
5874+
if (llvm::all_of(Op->users(),
5875+
[](const SDNode *N) { return N->getFlags().hasNoNaNs(); }))
5876+
return true;
5877+
58725878
return isKnownNeverNaN(Op, DemandedElts, SNaN, Depth);
58735879
}
58745880

0 commit comments

Comments
 (0)