@@ -2836,9 +2836,9 @@ HandleMergeInputChains(SmallVectorImpl<SDNode*> &ChainNodesMatched,
28362836}
28372837
28382838// / MorphNode - Handle morphing a node in place for the selector.
2839- SDNode *SelectionDAGISel::
2840- MorphNode (SDNode *Node, unsigned TargetOpc, SDVTList VTList,
2841- ArrayRef<SDValue> Ops, unsigned EmitNodeInfo) {
2839+ SDNode *SelectionDAGISel::MorphNode (SDNode *Node, unsigned TargetOpc,
2840+ SDVTList VTList, ArrayRef<SDValue> Ops ,
2841+ unsigned EmitNodeInfo, bool OptionalChain ) {
28422842 // It is possible we're using MorphNodeTo to replace a node with no
28432843 // normal results with one that has a normal result (or we could be
28442844 // adding a chain) and the input could have glue and chains as well.
@@ -2880,7 +2880,7 @@ MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTList,
28802880 --ResNumResults;
28812881
28822882 // Move the chain reference if needed.
2883- if ((EmitNodeInfo & OPFL_Chain) && OldChainResultNo != -1 &&
2883+ if ((EmitNodeInfo & OPFL_Chain || OptionalChain ) && OldChainResultNo != -1 &&
28842884 static_cast <unsigned >(OldChainResultNo) != ResNumResults - 1 )
28852885 ReplaceUses (SDValue (Node, OldChainResultNo),
28862886 SDValue (Res, ResNumResults - 1 ));
@@ -3385,6 +3385,12 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
33853385 // update the chain results when the pattern is complete.
33863386 SmallVector<SDNode*, 3 > ChainNodesMatched;
33873387
3388+ bool HasNodesWithOptionalChain = false ;
3389+
3390+ // List of pattern matches nodes that may have input/output chains and
3391+ // actually have them.
3392+ SmallVector<SDNode *, 8 > OptionalChainNodes;
3393+
33883394 LLVM_DEBUG (dbgs () << " ISEL: Starting pattern match\n " );
33893395
33903396 // Determine where to start the interpreter. Normally we start at opcode #0,
@@ -3505,7 +3511,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
35053511 case OPC_RecordChild2: case OPC_RecordChild3:
35063512 case OPC_RecordChild4: case OPC_RecordChild5:
35073513 case OPC_RecordChild6: case OPC_RecordChild7: {
3508- unsigned ChildNo = Opcode-OPC_RecordChild0;
3514+ unsigned ChildNo =
3515+ Opcode - OPC_RecordChild0 + !OptionalChainNodes.empty ();
35093516 if (ChildNo >= N.getNumOperands ())
35103517 break ; // Match fails if out of range child #.
35113518
@@ -3523,6 +3530,17 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
35233530
35243531 continue ;
35253532
3533+ case OPC_RecordOptionalChain:
3534+ HasNodesWithOptionalChain = true ;
3535+ // If the current node has input chain, record it.
3536+ if (N->getNumOperands () != 0 ) {
3537+ SDValue FirstOperand = N->getOperand (0 );
3538+ if (FirstOperand.getValueType () == MVT::Other) {
3539+ OptionalChainNodes.push_back (N.getNode ());
3540+ }
3541+ }
3542+ continue ;
3543+
35263544 case OPC_CaptureGlueInput:
35273545 // If the current node has an input glue, capture it in InputGlue.
35283546 if (N->getNumOperands () != 0 &&
@@ -3531,7 +3549,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
35313549 continue ;
35323550
35333551 case OPC_MoveChild: {
3534- unsigned ChildNo = MatcherTable[MatcherIndex++];
3552+ unsigned ChildNo =
3553+ MatcherTable[MatcherIndex++] + !OptionalChainNodes.empty ();
35353554 if (ChildNo >= N.getNumOperands ())
35363555 break ; // Match fails if out of range child #.
35373556 N = N.getOperand (ChildNo);
@@ -3543,7 +3562,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
35433562 case OPC_MoveChild2: case OPC_MoveChild3:
35443563 case OPC_MoveChild4: case OPC_MoveChild5:
35453564 case OPC_MoveChild6: case OPC_MoveChild7: {
3546- unsigned ChildNo = Opcode- OPC_MoveChild0;
3565+ unsigned ChildNo = Opcode - OPC_MoveChild0 + !OptionalChainNodes. empty () ;
35473566 if (ChildNo >= N.getNumOperands ())
35483567 break ; // Match fails if out of range child #.
35493568 N = N.getOperand (ChildNo);
@@ -3568,6 +3587,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
35683587 unsigned SiblingNo = Opcode == OPC_MoveSibling
35693588 ? MatcherTable[MatcherIndex++]
35703589 : Opcode - OPC_MoveSibling0;
3590+ SiblingNo += !OptionalChainNodes.empty ();
35713591 if (SiblingNo >= N.getNumOperands ())
35723592 break ; // Match fails if out of range sibling #.
35733593 N = N.getOperand (SiblingNo);
@@ -3998,11 +4018,16 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
39984018 // Ignore these because the newly token factored chain should not refer to
39994019 // the old nodes.
40004020 unsigned NumChains = MatcherTable[MatcherIndex++];
4001- assert (NumChains != 0 && " Can't TF zero chains" );
4021+ assert ((NumChains != 0 || HasNodesWithOptionalChain) &&
4022+ " Can't TF zero chains" );
40024023
40034024 assert (ChainNodesMatched.empty () &&
40044025 " Should only have one EmitMergeInputChains per match" );
40054026
4027+ if (NumChains == 0 && HasNodesWithOptionalChain &&
4028+ OptionalChainNodes.empty ())
4029+ continue ;
4030+
40064031 // Read all of the chained nodes.
40074032 for (unsigned i = 0 ; i != NumChains; ++i) {
40084033 unsigned RecNo = MatcherTable[MatcherIndex++];
@@ -4020,6 +4045,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
40204045 }
40214046 }
40224047
4048+ ChainNodesMatched.append (OptionalChainNodes);
4049+
40234050 // If the inner loop broke out, the match fails.
40244051 if (ChainNodesMatched.empty ())
40254052 break ;
@@ -4164,7 +4191,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
41644191 VTs.push_back (VT);
41654192 }
41664193
4167- if (EmitNodeInfo & OPFL_Chain)
4194+ if (EmitNodeInfo & OPFL_Chain || !OptionalChainNodes. empty () )
41684195 VTs.push_back (MVT::Other);
41694196 if (EmitNodeInfo & OPFL_GlueOutput)
41704197 VTs.push_back (MVT::Glue);
@@ -4186,6 +4213,10 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
41864213 unsigned RecNo = MatcherTable[MatcherIndex++];
41874214 if (RecNo & 128 )
41884215 RecNo = GetVBR (RecNo, MatcherTable, MatcherIndex);
4216+ if (HasNodesWithOptionalChain) {
4217+ assert (RecNo > 0 );
4218+ RecNo--;
4219+ }
41894220
41904221 assert (RecNo < RecordedNodes.size () && " Invalid EmitNode" );
41914222 Ops.push_back (RecordedNodes[RecNo].first );
@@ -4209,7 +4240,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
42094240 }
42104241
42114242 // If this has chain/glue inputs, add them.
4212- if (EmitNodeInfo & OPFL_Chain)
4243+ if (EmitNodeInfo & OPFL_Chain || !OptionalChainNodes. empty () )
42134244 Ops.push_back (InputChain);
42144245 if ((EmitNodeInfo & OPFL_GlueInput) && InputGlue.getNode () != nullptr )
42154246 Ops.push_back (InputGlue);
@@ -4219,7 +4250,12 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
42194250 // We need to perform this check before potentially modifying one of the
42204251 // nodes via MorphNode.
42214252 bool MayRaiseFPException =
4222- llvm::any_of (ChainNodesMatched, [this ](SDNode *N) {
4253+ llvm::any_of (ChainNodesMatched,
4254+ [this ](SDNode *N) {
4255+ return mayRaiseFPException (N) &&
4256+ !N->getFlags ().hasNoFPExcept ();
4257+ }) ||
4258+ llvm::any_of (OptionalChainNodes, [this ](SDNode *N) {
42234259 return mayRaiseFPException (N) && !N->getFlags ().hasNoFPExcept ();
42244260 });
42254261
@@ -4251,8 +4287,9 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
42514287 " Chain node replaced during MorphNode" );
42524288 llvm::erase (Chain, N);
42534289 });
4254- Res = cast<MachineSDNode>(MorphNode (NodeToMatch, TargetOpc, VTList,
4255- Ops, EmitNodeInfo));
4290+ Res = cast<MachineSDNode>(MorphNode (NodeToMatch, TargetOpc, VTList, Ops,
4291+ EmitNodeInfo,
4292+ !OptionalChainNodes.empty ()));
42564293 }
42574294
42584295 // Set the NoFPExcept flag when no original matched node could
@@ -4264,9 +4301,9 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
42644301 // chain and glue.
42654302 if (EmitNodeInfo & OPFL_GlueOutput) {
42664303 InputGlue = SDValue (Res, VTs.size ()-1 );
4267- if (EmitNodeInfo & OPFL_Chain)
4304+ if (EmitNodeInfo & OPFL_Chain || !OptionalChainNodes. empty () )
42684305 InputChain = SDValue (Res, VTs.size ()-2 );
4269- } else if (EmitNodeInfo & OPFL_Chain)
4306+ } else if (EmitNodeInfo & OPFL_Chain || !OptionalChainNodes. empty () )
42704307 InputChain = SDValue (Res, VTs.size ()-1 );
42714308
42724309 // If the OPFL_MemRefs glue is set on this node, slap all of the
@@ -4430,7 +4467,7 @@ bool SelectionDAGISel::mayRaiseFPException(SDNode *N) const {
44304467 const SelectionDAGTargetInfo &TSI = CurDAG->getSelectionDAGInfo ();
44314468 return TSI.mayRaiseFPException (N->getOpcode ());
44324469 }
4433- return N->isStrictFPOpcode ();
4470+ return N->isStrictFPOpcode () || N-> isFPOperation () ;
44344471}
44354472
44364473bool SelectionDAGISel::isOrEquivalentToAdd (const SDNode *N) const {
0 commit comments