[clang] [llvm] [InstCombine] remove dead loads, such as memcpy from undef (PR #143958)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 13:54:45 PDT 2025
================
@@ -3382,6 +3418,17 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
eraseInstFromFunction(*I);
Users[i] = nullptr; // Skip examining in the next loop.
}
+ if (auto *MTI = dyn_cast<MemTransferInst>(I)) {
+ if (KnowInitZero && getUnderlyingObject(MTI->getRawDest()) != &MI) {
+ IRBuilderBase::InsertPointGuard Guard(Builder);
+ Builder.SetInsertPoint(MTI);
+ auto *M = Builder.CreateMemSet(MTI->getRawDest(),
+ ConstantInt::get(Type::getInt8Ty(MI.getContext()), 0),
+ MTI->getLength(),
+ MTI->getDestAlign());
+ M->copyMetadata(*MTI, LLVMContext::MD_DIAssignID);
----------------
vtjnash wrote:
I was wondering about that too. The current MemCpyOptimizer pass usually drops all metadata information (which is where I copied this from to be consistent) but I couldn't really justify that to myself either.
https://github.com/llvm/llvm-project/pull/143958
More information about the llvm-commits
mailing list