@@ -5435,7 +5435,12 @@ bool SelectionDAG::isBaseWithConstantOffset(SDValue Op) const {
54355435
54365436bool SelectionDAG::isKnownNeverNaN (SDValue Op, bool SNaN, unsigned Depth) const {
54375437 // If we're told that NaNs won't happen, assume they won't.
5438- if (getTarget ().Options .NoNaNsFPMath || Op->getFlags ().hasNoNaNs ())
5438+ if (getTarget ().Options .NoNaNsFPMath )
5439+ return true ;
5440+ SDNodeFlags OpFlags = Op->getFlags ();
5441+ if (SNaN && OpFlags.hasNoSNaNs ())
5442+ return true ;
5443+ if (OpFlags.hasNoSNaNs () && OpFlags.hasNoQNaNs ())
54395444 return true ;
54405445
54415446 if (Depth >= MaxRecursionDepth)
@@ -5569,11 +5574,39 @@ bool SelectionDAG::isKnownNeverZeroFloat(SDValue Op) const {
55695574 assert (Op.getValueType ().isFloatingPoint () &&
55705575 " Floating point type expected" );
55715576
5577+ SDNodeFlags OpFlags = Op->getFlags ();
5578+ if (OpFlags.hasNoPosZeros () && OpFlags.hasNoNegZeros ())
5579+ return true ;
5580+
55725581 // If the value is a constant, we can obviously see if it is a zero or not.
55735582 return ISD::matchUnaryFpPredicate (
55745583 Op, [](ConstantFPSDNode *C) { return !C->isZero (); });
55755584}
55765585
5586+ bool SelectionDAG::isKnownNeverPosZeroFloat (SDValue Op) const {
5587+ assert (Op.getValueType ().isFloatingPoint () && " Floating point type expected" );
5588+
5589+ SDNodeFlags OpFlags = Op->getFlags ();
5590+ if (OpFlags.hasNoPosZeros ())
5591+ return true ;
5592+
5593+ // If the value is a constant, we can obviously see if it is a zero or not.
5594+ return ISD::matchUnaryFpPredicate (
5595+ Op, [](ConstantFPSDNode *C) { return !C->isZero () || C->isNegative (); });
5596+ }
5597+
5598+ bool SelectionDAG::isKnownNeverNegZeroFloat (SDValue Op) const {
5599+ assert (Op.getValueType ().isFloatingPoint () && " Floating point type expected" );
5600+
5601+ SDNodeFlags OpFlags = Op->getFlags ();
5602+ if (OpFlags.hasNoNegZeros ())
5603+ return true ;
5604+
5605+ // If the value is a constant, we can obviously see if it is a zero or not.
5606+ return ISD::matchUnaryFpPredicate (
5607+ Op, [](ConstantFPSDNode *C) { return !C->isZero () || !C->isNegative (); });
5608+ }
5609+
55775610bool SelectionDAG::isKnownNeverZero (SDValue Op, unsigned Depth) const {
55785611 if (Depth >= MaxRecursionDepth)
55795612 return false ; // Limit search depth.
@@ -7490,6 +7523,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
74907523 N2.getOpcode () != ISD::DELETED_NODE &&
74917524 N3.getOpcode () != ISD::DELETED_NODE &&
74927525 " Operand is DELETED_NODE!" );
7526+ SDNodeFlags NewFlags = Flags;
74937527 // Perform various simplifications.
74947528 switch (Opcode) {
74957529 case ISD::FMA:
@@ -7535,6 +7569,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
75357569 assert ((!VT.isVector () || VT.getVectorElementCount () ==
75367570 N1.getValueType ().getVectorElementCount ()) &&
75377571 " SETCC vector element counts must match!" );
7572+ if (N1->getFlags ().hasNoNaNs () && N2->getFlags ().hasNoNaNs ()) {
7573+ NewFlags.setNoQNaNs (true );
7574+ NewFlags.setNoSNaNs (true );
7575+ }
75387576 // Use FoldSetCC to simplify SETCC's.
75397577 if (SDValue V = FoldSetCC (VT, N1, N2, cast<CondCodeSDNode>(N3)->get (), DL))
75407578 return V;
@@ -7548,6 +7586,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
75487586 }
75497587 case ISD::SELECT:
75507588 case ISD::VSELECT:
7589+ if ((N1->getFlags ().hasNoNaNs () && N2->getFlags ().hasNoNaNs ()) ||
7590+ N3->getFlags ().hasNoNaNs ()) {
7591+ NewFlags.setNoQNaNs (true );
7592+ NewFlags.setNoSNaNs (true );
7593+ }
75517594 if (SDValue V = simplifySelect (N1, N2, N3))
75527595 return V;
75537596 break ;
@@ -7654,12 +7697,12 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
76547697 AddNodeIDNode (ID, Opcode, VTs, Ops);
76557698 void *IP = nullptr ;
76567699 if (SDNode *E = FindNodeOrInsertPos (ID, DL, IP)) {
7657- E->intersectFlagsWith (Flags );
7700+ E->intersectFlagsWith (NewFlags );
76587701 return SDValue (E, 0 );
76597702 }
76607703
76617704 N = newSDNode<SDNode>(Opcode, DL.getIROrder (), DL.getDebugLoc (), VTs);
7662- N->setFlags (Flags );
7705+ N->setFlags (NewFlags );
76637706 createOperands (N, Ops);
76647707 CSEMap.InsertNode (N, IP);
76657708 } else {
0 commit comments