[clang] [llvm] [InstCombine] remove dead loads, such as memcpy from undef (PR #143958)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 12 13:24:55 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;
----------------
nikic wrote:

Rather than doing these individual checks, can we have a centralized check in the loop that does the early bailout for `Access == ModRef`?

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


More information about the llvm-commits mailing list