[clang] [llvm] [InstCombine] remove dead loads, such as memcpy from undef (PR #143958)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 13:54:25 PDT 2025
================
@@ -3339,16 +3340,23 @@ static bool isAllocSiteRemovable(Instruction *AI,
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
default:
- return false;
+ return std::nullopt;
case Intrinsic::memmove:
case Intrinsic::memcpy:
case Intrinsic::memset: {
MemIntrinsic *MI = cast<MemIntrinsic>(II);
- if (MI->isVolatile() || MI->getRawDest() != PI)
- return false;
- [[fallthrough]];
+ if (MI->isVolatile())
+ return std::nullopt;
+ // 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 std::nullopt;
+ Access |= NewAccess;
}
+ [[fallthrough]];
----------------
nikic wrote:
Weird formatting. Can keep the fallthrough in the braces?
https://github.com/llvm/llvm-project/pull/143958
More information about the llvm-commits
mailing list