[llvm] [DSE] Delay deleting non-memory-defs until end of DSE. (PR #83411)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 03:30:15 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:

Not sure if there could be cases where a MemoryDef also loads a value that is then used as pointer of MemoryLocation

https://github.com/llvm/llvm-project/pull/83411


More information about the llvm-commits mailing list