[llvm] [DSE] Delay deleting non-memory-defs until end of DSE. (PR #83411)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 09:32:20 PST 2024
================
@@ -1730,13 +1736,21 @@ struct DSEState {
// Remove its operands
for (Use &O : DeadInst->operands())
if (Instruction *OpI = dyn_cast<Instruction>(O)) {
- O = nullptr;
+ O.set(PoisonValue::get(O->getType()));
if (isInstructionTriviallyDead(OpI, &TLI))
NowDeadInsts.push_back(OpI);
}
EI.removeInstruction(DeadInst);
- DeadInst->eraseFromParent();
+ // Remove memory defs directly, but only queue other dead instructions for
+ // later removal. They may have been used as memory locations that have
+ // been cached by BatchAA. Removing them here may lead to newly created
+ // instructions to be allocated at the same address, yielding stale cache
+ // entries.
+ if (IsMemDef)
+ DeadInst->eraseFromParent();
----------------
fhahn wrote:
Deleting a memcpy wouldn't be a problem, as long as its pointer operands aren't deleted.
But we might remove something like a `malloc` call, which is a memory def, and the result of the malloc could be used as address and be in the cache. Updated the code to remove memory-defs that do not produce a value (i.e. have type void)
https://github.com/llvm/llvm-project/pull/83411
More information about the llvm-commits
mailing list