[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:51:23 PDT 2025
================
@@ -3283,10 +3285,15 @@ static bool isAllocSiteRemovable(Instruction *AI,
case Intrinsic::memcpy:
case Intrinsic::memset: {
MemIntrinsic *MI = cast<MemIntrinsic>(II);
- if (MI->isVolatile() || MI->getRawDest() != PI)
+ if (MI->isVolatile())
return false;
+ // Note: this could also be ModRef, but we can still interpret that as just Mod in that case.
+ ModRefInfo NewAccess = MI->getRawDest() == PI ? ModRefInfo::Mod : ModRefInfo::Ref;
+ if ((Access & ~NewAccess) != ModRefInfo::NoModRef)
+ return false;
----------------
vtjnash wrote:
I originally was going to have it use AA to compute ModRef at the top, but that seemed potentially slower (since we already know PI aliases). I wasn't sure how else to centralize the test and also preserve exit early unless I just duplicate it at the top and after the loop (`if (Access == ModRefInfo::ModRef) return false`)?
https://github.com/llvm/llvm-project/pull/143958
More information about the llvm-commits
mailing list