Skip to content

Commit 0f3642f

Browse files
committed
[RLE-DSE]. Improve how RLE removes instructions with no use
Existing tests ensure correctness.
1 parent b219c9b commit 0f3642f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/SILPasses/Scalar/RedundantLoadElimination.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,16 +951,30 @@ bool RLEContext::run() {
951951
} while (ForwardSetChanged || LastIteration);
952952

953953
// Finally, perform the redundant load replacements.
954+
llvm::DenseSet<SILInstruction *> InstsToRemove;
954955
bool SILChanged = false;
955956
for (auto &X : BBToLocState) {
956957
for (auto &F : X.second.getRL()) {
957958
DEBUG(llvm::dbgs() << "Replacing " << SILValue(F.first) << "With "
958959
<< F.second);
959960
SILChanged = true;
960961
SILValue(F.first).replaceAllUsesWith(F.second);
962+
InstsToRemove.insert(F.first);
961963
++NumForwardedLoads;
962964
}
963965
}
966+
967+
// Erase the instructions recursively, this way, we get rid of pass
968+
// dependence on DCE.
969+
for (auto &X : InstsToRemove) {
970+
// It is possible that the instruction still has uses, because it could be
971+
// used as the replacement Value, i.e. F.second, for some other RLE pairs.
972+
//
973+
// TODO: we should fix this, otherwise we are missing RLE opportunities.
974+
if (!X->use_empty())
975+
continue;
976+
recursivelyDeleteTriviallyDeadInstructions(X, true);
977+
}
964978
return SILChanged;
965979
}
966980

0 commit comments

Comments
 (0)