[llvm] 0d674cf - [Mem2Reg] Extract code for converting !nonull to assume (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 12 07:41:53 PST 2023
Author: Nikita Popov
Date: 2023-01-12T16:41:31+01:00
New Revision: 0d674cf0eae84a7b83999d2122c1609a8ee2b16d
URL: https://github.com/llvm/llvm-project/commit/0d674cf0eae84a7b83999d2122c1609a8ee2b16d
DIFF: https://github.com/llvm/llvm-project/commit/0d674cf0eae84a7b83999d2122c1609a8ee2b16d.diff
LOG: [Mem2Reg] Extract code for converting !nonull to assume (NFC)
Added:
Modified:
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index f5a76458e0632..c71ad2782c050 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -383,6 +383,17 @@ static void addAssumeNonNull(AssumptionCache *AC, LoadInst *LI) {
AC->registerAssumption(cast<AssumeInst>(CI));
}
+static void convertMetadataToAssumes(LoadInst *LI, Value *Val,
+ const DataLayout &DL, AssumptionCache *AC,
+ const DominatorTree *DT) {
+ // If the load was marked as nonnull we don't want to lose
+ // that information when we erase this Load. So we preserve
+ // it with an assume.
+ if (AC && LI->getMetadata(LLVMContext::MD_nonnull) &&
+ !isKnownNonZero(Val, DL, 0, AC, LI, DT))
+ addAssumeNonNull(AC, LI);
+}
+
static void removeIntrinsicUsers(AllocaInst *AI) {
// Knowing that this alloca is promotable, we know that it's safe to kill all
// instructions except for load and store.
@@ -475,13 +486,7 @@ static bool rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info,
if (ReplVal == LI)
ReplVal = PoisonValue::get(LI->getType());
- // If the load was marked as nonnull we don't want to lose
- // that information when we erase this Load. So we preserve
- // it with an assume.
- if (AC && LI->getMetadata(LLVMContext::MD_nonnull) &&
- !isKnownNonZero(ReplVal, DL, 0, AC, LI, &DT))
- addAssumeNonNull(AC, LI);
-
+ convertMetadataToAssumes(LI, ReplVal, DL, AC, &DT);
LI->replaceAllUsesWith(ReplVal);
LI->eraseFromParent();
LBI.deleteValue(LI);
@@ -584,11 +589,7 @@ static bool promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
ReplVal = std::prev(I)->second->getOperand(0);
}
- // Note, if the load was marked as nonnull we don't want to lose that
- // information when we erase it. So we preserve it with an assume.
- if (AC && LI->getMetadata(LLVMContext::MD_nonnull) &&
- !isKnownNonZero(ReplVal, DL, 0, AC, LI, &DT))
- addAssumeNonNull(AC, LI);
+ convertMetadataToAssumes(LI, ReplVal, DL, AC, &DT);
// If the replacement value is the load, this must occur in unreachable
// code.
@@ -1047,13 +1048,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
continue;
Value *V = IncomingVals[AI->second];
-
- // If the load was marked as nonnull we don't want to lose
- // that information when we erase this Load. So we preserve
- // it with an assume.
- if (AC && LI->getMetadata(LLVMContext::MD_nonnull) &&
- !isKnownNonZero(V, SQ.DL, 0, AC, LI, &DT))
- addAssumeNonNull(AC, LI);
+ convertMetadataToAssumes(LI, V, SQ.DL, AC, &DT);
// Anything using the load now uses the current value.
LI->replaceAllUsesWith(V);
More information about the llvm-commits
mailing list