Skip to content

Commit 1fab9d7

Browse files
committed
[SelectionDAG] also deduce nnan from users
1 parent b95b38e commit 1fab9d7

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
@@ -6715,6 +6715,9 @@ static SDValue foldAndOrOfSETCC(SDNode *LogicOp, SelectionDAG &DAG) {
67156715
DAG, isFMAXNUMFMINNUM_IEEE, isFMAXNUMFMINNUM);
67166716

67176717
if (NewOpcode != ISD::DELETED_NODE) {
6718+
// Propagate fast-math flags from setcc.
6719+
SelectionDAG::FlagInserter FlagInserter(DAG, LHS->getFlags() &
6720+
RHS->getFlags());
67186721
SDValue MinMaxValue =
67196722
DAG.getNode(NewOpcode, DL, OpVT, Operand1, Operand2);
67206723
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+
// it self 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)