From: Craig Topper Date: Tue, 26 Mar 2019 05:31:32 +0000 (+0000) Subject: [X86] In matchBitExtract, place all of the new nodes before Node's position in the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57810eb46e57496c1b2449af5e50e595f90e7660;p=llvm [X86] In matchBitExtract, place all of the new nodes before Node's position in the DAG for the topological sort. We were using OrigNBits, but that put all the nodes before the node we used to start the control computation. This caused some node earlier than the sequence we inserted to be selected before the sequence we created. We want our new sequence to be selected first since it depends on OrigNBits. I don't have a test case. Found by reviewing the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356979 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 38c1c6ba8d0..5e2b90ff881 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -3008,19 +3008,18 @@ bool X86DAGToDAGISel::matchBitExtract(SDNode *Node) { assert(XVT == MVT::i64 && "Expected truncation from i64"); } - SDValue OrigNBits = NBits; // Truncate the shift amount. NBits = CurDAG->getNode(ISD::TRUNCATE, DL, MVT::i8, NBits); - insertDAGNode(*CurDAG, OrigNBits, NBits); + insertDAGNode(*CurDAG, SDValue(Node, 0), NBits); // Insert 8-bit NBits into lowest 8 bits of 32-bit register. // All the other bits are undefined, we do not care about them. SDValue ImplDef = SDValue( CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, MVT::i32), 0); - insertDAGNode(*CurDAG, OrigNBits, ImplDef); + insertDAGNode(*CurDAG, SDValue(Node, 0), ImplDef); NBits = CurDAG->getTargetInsertSubreg(X86::sub_8bit, DL, MVT::i32, ImplDef, NBits); - insertDAGNode(*CurDAG, OrigNBits, NBits); + insertDAGNode(*CurDAG, SDValue(Node, 0), NBits); if (Subtarget->hasBMI2()) { // Great, just emit the the BZHI.. @@ -3028,10 +3027,10 @@ bool X86DAGToDAGISel::matchBitExtract(SDNode *Node) { // But have to place the bit count into the wide-enough register first. SDValue ImplDef = SDValue( CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, XVT), 0); - insertDAGNode(*CurDAG, OrigNBits, ImplDef); + insertDAGNode(*CurDAG, SDValue(Node, 0), ImplDef); NBits = CurDAG->getTargetInsertSubreg(X86::sub_32bit, DL, XVT, ImplDef, NBits); - insertDAGNode(*CurDAG, OrigNBits, NBits); + insertDAGNode(*CurDAG, SDValue(Node, 0), NBits); } SDValue Extract = CurDAG->getNode(X86ISD::BZHI, DL, XVT, X, NBits); @@ -3050,7 +3049,7 @@ bool X86DAGToDAGISel::matchBitExtract(SDNode *Node) { // This makes the low 8 bits to be zero. SDValue C8 = CurDAG->getConstant(8, DL, MVT::i8); SDValue Control = CurDAG->getNode(ISD::SHL, DL, MVT::i32, NBits, C8); - insertDAGNode(*CurDAG, OrigNBits, Control); + insertDAGNode(*CurDAG, SDValue(Node, 0), Control); // If the 'X' is *logically* shifted, we can fold that shift into 'control'. if (X.getOpcode() == ISD::SRL) { @@ -3068,17 +3067,17 @@ bool X86DAGToDAGISel::matchBitExtract(SDNode *Node) { // And now 'or' these low 8 bits of shift amount into the 'control'. Control = CurDAG->getNode(ISD::OR, DL, MVT::i32, Control, ShiftAmt); - insertDAGNode(*CurDAG, OrigNBits, Control); + insertDAGNode(*CurDAG, SDValue(Node, 0), Control); } // But have to place the 'control' into the wide-enough register first. if (XVT != MVT::i32) { SDValue ImplDef = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, XVT), 0); - insertDAGNode(*CurDAG, OrigNBits, ImplDef); + insertDAGNode(*CurDAG, SDValue(Node, 0), ImplDef); Control = CurDAG->getTargetInsertSubreg(X86::sub_32bit, DL, XVT, ImplDef, Control); - insertDAGNode(*CurDAG, OrigNBits, Control); + insertDAGNode(*CurDAG, SDValue(Node, 0), Control); } // And finally, form the BEXTR itself.