[llvm] [GlobalOpt] Handle operators separately when removing GV users (PR #84694)
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 29 19:51:02 PDT 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))
----------------
gandhi56 wrote:
The purpose of `isSafeComputationToRemove(..)` at this point is only if we want to remove the computation chain in globalopt. You're right, we could let instcombine handle the removal of the computation chain as we should in my opinion to avoid redundancy. @nikic I would like to hear your thoughts on this.
https://github.com/llvm/llvm-project/pull/84694
More information about the llvm-commits
mailing list