diff options
author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2020-01-14 14:04:53 +0100 |
---|---|---|
committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2020-01-14 14:10:57 +0100 |
commit | 81ee484484a0be59da8f749a9b4cf56bb8d37402 (patch) | |
tree | 3077a1a8f617e560e41a0dc867070a4ecd31dac3 /llvm/lib/CodeGen | |
parent | df186507e1d07c3ddba091a076ba7a33dbdc5867 (diff) | |
download | bcm5719-llvm-81ee484484a0be59da8f749a9b4cf56bb8d37402.tar.gz bcm5719-llvm-81ee484484a0be59da8f749a9b4cf56bb8d37402.zip |
[FPEnv] Fix chain handling regression after 04a8696
Code in getRoot made the assumption that every node in PendingLoads
must always itself have a dependency on the current DAG root node.
After the changes in 04a8696, it turns out that this assumption no
longer holds true, causing wrong codegen in some cases (e.g. stores
after constrained FP intrinsics might get deleted).
To fix this, we now need to make sure that the TokenFactor created
by getRoot always includes the previous root, if there is no implicit
dependency already present.
The original getControlRoot code already has exactly this check,
so this patch simply reuses that code now for getRoot as well.
This fixes the regression.
NFC if no constrained FP intrinsic is present.
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 62 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h | 3 |
2 files changed, 31 insertions, 34 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index c3fbdf0d763..728d963a916 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1037,24 +1037,41 @@ void SelectionDAGBuilder::clearDanglingDebugInfo() { DanglingDebugInfoMap.clear(); } -SDValue SelectionDAGBuilder::getMemoryRoot() { - if (PendingLoads.empty()) - return DAG.getRoot(); +// Update DAG root to include dependencies on Pending chains. +SDValue SelectionDAGBuilder::updateRoot(SmallVectorImpl<SDValue> &Pending) { + SDValue Root = DAG.getRoot(); - if (PendingLoads.size() == 1) { - SDValue Root = PendingLoads[0]; - DAG.setRoot(Root); - PendingLoads.clear(); + if (Pending.empty()) return Root; + + // Add current root to PendingChains, unless we already indirectly + // depend on it. + if (Root.getOpcode() != ISD::EntryToken) { + unsigned i = 0, e = Pending.size(); + for (; i != e; ++i) { + assert(Pending[i].getNode()->getNumOperands() > 1); + if (Pending[i].getNode()->getOperand(0) == Root) + break; // Don't add the root if we already indirectly depend on it. + } + + if (i == e) + Pending.push_back(Root); } - // Otherwise, we have to make a token factor node. - SDValue Root = DAG.getTokenFactor(getCurSDLoc(), PendingLoads); - PendingLoads.clear(); + if (Pending.size() == 1) + Root = Pending[0]; + else + Root = DAG.getTokenFactor(getCurSDLoc(), Pending); + DAG.setRoot(Root); + Pending.clear(); return Root; } +SDValue SelectionDAGBuilder::getMemoryRoot() { + return updateRoot(PendingLoads); +} + SDValue SelectionDAGBuilder::getRoot() { // Chain up all pending constrained intrinsics together with all // pending loads, by simply appending them to PendingLoads and @@ -1072,35 +1089,12 @@ SDValue SelectionDAGBuilder::getRoot() { } SDValue SelectionDAGBuilder::getControlRoot() { - SDValue Root = DAG.getRoot(); - // We need to emit pending fpexcept.strict constrained intrinsics, // so append them to the PendingExports list. PendingExports.append(PendingConstrainedFPStrict.begin(), PendingConstrainedFPStrict.end()); PendingConstrainedFPStrict.clear(); - - if (PendingExports.empty()) - return Root; - - // Turn all of the CopyToReg chains into one factored node. - if (Root.getOpcode() != ISD::EntryToken) { - unsigned i = 0, e = PendingExports.size(); - for (; i != e; ++i) { - assert(PendingExports[i].getNode()->getNumOperands() > 1); - if (PendingExports[i].getNode()->getOperand(0) == Root) - break; // Don't add the root if we already indirectly depend on it. - } - - if (i == e) - PendingExports.push_back(Root); - } - - Root = DAG.getNode(ISD::TokenFactor, getCurSDLoc(), MVT::Other, - PendingExports); - PendingExports.clear(); - DAG.setRoot(Root); - return Root; + return updateRoot(PendingExports); } void SelectionDAGBuilder::visit(const Instruction &I) { diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h index 12770c8fb2d..18e0edf7fc0 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -154,6 +154,9 @@ private: SmallVector<SDValue, 8> PendingConstrainedFP; SmallVector<SDValue, 8> PendingConstrainedFPStrict; + /// Update root to include all chains from the Pending list. + SDValue updateRoot(SmallVectorImpl<SDValue> &Pending); + /// A unique monotonically increasing number used to order the SDNodes we /// create. unsigned SDNodeOrder; |