From a58891ff1e6b5cc61cbb3cfe46be7f2eeddbfe98 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 5 Feb 2008 22:50:29 +0000 Subject: [PATCH] Fix PR1975: dag isel emitter produces patterns that isel wrong flag result. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46776 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 ---- test/CodeGen/X86/2008-02-05-ISelCrash.ll | 12 +++++++++++ utils/TableGen/DAGISelEmitter.cpp | 25 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 test/CodeGen/X86/2008-02-05-ISelCrash.ll diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 11b289bf8f3..4b68fb7e95f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3183,10 +3183,6 @@ SDNode *SelectionDAG::getTargetNode(unsigned Opcode, void SelectionDAG::ReplaceAllUsesWith(SDOperand FromN, SDOperand To, DAGUpdateListener *UpdateListener) { SDNode *From = FromN.Val; - // FIXME: This works around a dag isel emitter bug. - if (From->getNumValues() == 1 && FromN.ResNo != 0) - return; // FIXME: THIS IS BOGUS - assert(From->getNumValues() == 1 && FromN.ResNo == 0 && "Cannot replace with this method!"); assert(From != To.Val && "Cannot replace uses of with self"); diff --git a/test/CodeGen/X86/2008-02-05-ISelCrash.ll b/test/CodeGen/X86/2008-02-05-ISelCrash.ll new file mode 100644 index 00000000000..6885cf14cf1 --- /dev/null +++ b/test/CodeGen/X86/2008-02-05-ISelCrash.ll @@ -0,0 +1,12 @@ +; RUN: llvm-as < %s | llc -march=x86 +; PR1975 + +@nodes = external global i64 ; [#uses=2] + +define fastcc i32 @ab(i32 %alpha, i32 %beta) nounwind { +entry: + %tmp1 = load i64* @nodes, align 8 ; [#uses=1] + %tmp2 = add i64 %tmp1, 1 ; [#uses=1] + store i64 %tmp2, i64* @nodes, align 8 + ret i32 0 +} diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index dda56c09421..7a1920ceac7 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -305,6 +305,8 @@ private: std::map VariableMap; // Node to operator mapping std::map OperatorMap; + // Name of the folded node which produces a flag. + std::pair FoldedFlag; // Names of all the folded nodes which produce chains. std::vector > FoldedChains; // Original input chain(s). @@ -587,8 +589,17 @@ public: emitCheck(RootName + ".getOpcode() == " + CInfo.getEnumName()); EmitMatchCode(Child, Parent, RootName, ChainSuffix, FoundChain); - if (NodeHasProperty(Child, SDNPHasChain, CGP)) + bool HasChain = false; + if (NodeHasProperty(Child, SDNPHasChain, CGP)) { + HasChain = true; FoldedChains.push_back(std::make_pair(RootName, CInfo.getNumResults())); + } + if (NodeHasProperty(Child, SDNPOutFlag, CGP)) { + assert(FoldedFlag.first == "" && FoldedFlag.second == 0 && + "Pattern folded multiple nodes which produce flags?"); + FoldedFlag = std::make_pair(RootName, + CInfo.getNumResults() + (unsigned)HasChain); + } } else { // If this child has a name associated with it, capture it in VarMap. If // we already saw this in the pattern, emit code to verify dagness. @@ -1105,9 +1116,15 @@ public: } if (NodeHasOutFlag) { - emitCode("ReplaceUses(SDOperand(N.Val, " + - utostr(NumPatResults + (unsigned)InputHasChain) - +"), InFlag);"); + if (FoldedFlag.first != "") { + emitCode("ReplaceUses(SDOperand(" + FoldedFlag.first + ".Val, " + + utostr(FoldedFlag.second) + "), InFlag);"); + } else { + assert(NodeHasProperty(Pattern, SDNPOutFlag, CGP)); + emitCode("ReplaceUses(SDOperand(N.Val, " + + utostr(NumPatResults + (unsigned)InputHasChain) + +"), InFlag);"); + } NeedReplace = true; }