[llvm] [GlobalOpt] Handle operators separately when removing GV users (PR #84694)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 13:53:20 PST 2024
================
@@ -318,11 +240,30 @@ static bool CleanupConstantGlobalUsers(GlobalVariable *GV,
}
}
} else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
- // Store must be unreachable or storing Init into the global.
- EraseFromParent(SI);
- } else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(U)) { // memset/cpy/mv
- if (getUnderlyingObject(MI->getRawDest()) == GV)
- EraseFromParent(MI);
+ auto *V = SI->getValueOperand();
+ if (isa<Constant>(V)) {
+ EraseFromParent(SI);
+ } else if (isa<Instruction>(V)) {
+ EraseFromParent(SI);
+ if (isSafeComputationToRemove(V, GetTLI))
+ RecursivelyDeleteTriviallyDeadInstructions(V);
+ } else if (isa<Argument>(V)) {
+ if (!V->getType()->isPointerTy())
+ EraseFromParent(SI);
+ }
+ } else if (auto *MSI = dyn_cast<MemSetInst>(U)) { // memset/cpy/mv
+ if (getUnderlyingObject(MSI->getRawDest()) == GV)
+ EraseFromParent(MSI);
+ } else if (auto *MTI = dyn_cast<MemTransferInst>(U)) {
+ auto *Src = MTI->getRawSource();
+ auto *Dst = MTI->getRawDest();
+ if (getUnderlyingObject(Dst) != GV)
+ continue;
+ if (isa<Instruction, Operator>(Src)) {
+ EraseFromParent(MTI);
+ if (isSafeComputationToRemove(Src, GetTLI))
----------------
efriedma-quic wrote:
I was trying to say that you can just call RecursivelyDeleteTriviallyDeadInstructions without checking if the instruction is dead; it internally checks if the instruction is dead.
But more importantly, it means isSafeComputationToRemove isn't actually doing anything useful, so the end result is that this behaves identically to D69428.
https://github.com/llvm/llvm-project/pull/84694
More information about the llvm-commits
mailing list