[clang] [llvm] [InstCombine] remove dead loads, such as memcpy from undef (PR #143958)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 13:12:12 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions c,cpp -- clang/test/Misc/loop-opt-setup.c llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 83ebf9e40..f75e76f80 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3217,8 +3217,7 @@ static bool isRemovableWrite(CallBase &CB, Value *UsedV,
static bool isAllocSiteRemovable(Instruction *AI,
SmallVectorImpl<WeakTrackingVH> &Users,
- const TargetLibraryInfo &TLI,
- bool KnowInit) {
+ const TargetLibraryInfo &TLI, bool KnowInit) {
SmallVector<Instruction*, 4> Worklist;
const std::optional<StringRef> Family = getAllocationFamily(AI, &TLI);
Worklist.push_back(AI);
@@ -3287,12 +3286,14 @@ static bool isAllocSiteRemovable(Instruction *AI,
MemIntrinsic *MI = cast<MemIntrinsic>(II);
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;
+ // 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;
Access |= NewAccess;
- }
+ }
[[fallthrough]];
case Intrinsic::assume:
case Intrinsic::invariant_start:
@@ -3323,7 +3324,8 @@ static bool isAllocSiteRemovable(Instruction *AI,
continue;
}
- if (!isRefSet(Access) && isRemovableWrite(*cast<CallBase>(I), PI, TLI)) {
+ if (!isRefSet(Access) &&
+ isRemovableWrite(*cast<CallBase>(I), PI, TLI)) {
Access |= ModRefInfo::Mod;
Users.emplace_back(I);
continue;
@@ -3385,11 +3387,13 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false));
}
- // Determine what getInitialValueOfAllocation would return without actually allocating the result.
+ // Determine what getInitialValueOfAllocation would return without actually
+ // allocating the result.
bool KnowInitUndef = isa<AllocaInst>(MI);
bool KnowInitZero = false;
if (!KnowInitUndef) {
- Constant *Init = getInitialValueOfAllocation(&MI, &TLI, Type::getInt8Ty(MI.getContext()));
+ Constant *Init = getInitialValueOfAllocation(
+ &MI, &TLI, Type::getInt8Ty(MI.getContext()));
if (Init) {
if (isa<UndefValue>(Init))
KnowInitUndef = true;
@@ -3422,10 +3426,10 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
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());
+ auto *M = Builder.CreateMemSet(
+ MTI->getRawDest(),
+ ConstantInt::get(Type::getInt8Ty(MI.getContext()), 0),
+ MTI->getLength(), MTI->getDestAlign());
M->copyMetadata(*MTI, LLVMContext::MD_DIAssignID);
}
}
@@ -3454,7 +3458,8 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
Constant *Replace;
if (isa<LoadInst>(I)) {
assert(KnowInitZero || KnowInitUndef);
- Replace = KnowInitUndef ? UndefValue::get(I->getType()) : Constant::getNullValue(I->getType());
+ Replace = KnowInitUndef ? UndefValue::get(I->getType())
+ : Constant::getNullValue(I->getType());
} else
Replace = PoisonValue::get(I->getType());
replaceInstUsesWith(*I, Replace);
``````````
</details>
https://github.com/llvm/llvm-project/pull/143958
More information about the llvm-commits
mailing list