[DAG] Cleanup unused nodes on failed store-to-load forward combine.

llvm-svn: 353416
This commit is contained in:
Nirav Dave 2019-02-07 15:38:14 +00:00
parent 8ebb854bc2
commit 724b81087d
1 changed files with 21 additions and 9 deletions

View File

@ -13123,30 +13123,42 @@ SDValue DAGCombiner::ForwardStoreValueToDirectLoad(LoadSDNode *LD) {
if (LD->getBasePtr().isUndef() || Offset != 0) if (LD->getBasePtr().isUndef() || Offset != 0)
return SDValue(); return SDValue();
// Model necessary truncations / extenstions. // Model necessary truncations / extenstions.
SDValue Val; SmallVector<SDNode *, 4> Vals; // Temporaries which may need to be deleted.
SDValue Val, RV;
// Truncate Value To Stored Memory Size. // Truncate Value To Stored Memory Size.
do { do {
if (!getTruncatedStoreValue(ST, Val)) if (!getTruncatedStoreValue(ST, Val))
continue; continue;
if (Vals.empty() || Vals.back() != Val.getNode())
Vals.push_back(Val.getNode());
if (!isTypeLegal(LDMemType)) if (!isTypeLegal(LDMemType))
continue; continue;
if (STMemType != LDMemType) { if (STMemType != LDMemType) {
// TODO: Support vectors? This requires extract_subvector/bitcast. // TODO: Support vectors? This requires extract_subvector/bitcast.
if (!STMemType.isVector() && !LDMemType.isVector() && if (!STMemType.isVector() && !LDMemType.isVector() &&
STMemType.isInteger() && LDMemType.isInteger()) STMemType.isInteger() && LDMemType.isInteger()) {
Vals.push_back(Val.getNode());
Val = DAG.getNode(ISD::TRUNCATE, SDLoc(LD), LDMemType, Val); Val = DAG.getNode(ISD::TRUNCATE, SDLoc(LD), LDMemType, Val);
else } else
continue; continue;
} }
if (!extendLoadedValueToExtension(LD, Val)) if (Vals.empty() || Vals.back() != Val.getNode())
continue; Vals.push_back(Val.getNode());
return ReplaceLd(LD, Val, Chain); if (extendLoadedValueToExtension(LD, Val))
RV = ReplaceLd(LD, Val, Chain);
else if (Vals.empty() || Vals.back() != Val.getNode())
Vals.push_back(Val.getNode());
} while (false); } while (false);
// On failure, cleanup dead nodes we may have created. // On failure, cleanup dead nodes we may have created.
if (Val->use_empty()) if (Vals.empty() || Vals.back() != Val.getNode())
deleteAndRecombine(Val.getNode()); Vals.push_back(Val.getNode());
return SDValue(); while (!Vals.empty()) {
SDNode *Val = Vals.pop_back_val();
if (Val->use_empty())
recursivelyDeleteUnusedNodes(Val);
}
return RV;
} }
SDValue DAGCombiner::visitLOAD(SDNode *N) { SDValue DAGCombiner::visitLOAD(SDNode *N) {