[llvm] 2b8a703 - [DSE] Avoid calling isRemovable() on non-analyzable location (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 24 01:19:12 PST 2021
Author: Nikita Popov
Date: 2021-12-24T10:18:15+01:00
New Revision: 2b8a703858ea994f6665fc35220f2ea56cabe39d
URL: https://github.com/llvm/llvm-project/commit/2b8a703858ea994f6665fc35220f2ea56cabe39d
DIFF: https://github.com/llvm/llvm-project/commit/2b8a703858ea994f6665fc35220f2ea56cabe39d.diff
LOG: [DSE] Avoid calling isRemovable() on non-analyzable location (NFC)
At this point the instruction may either have an analyzable
write or be a terminator. For terminators, isRemovable() is not
necessarily well-defined. Move the check until after we have ensured
that it is not a terminator.
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 016a59f8a069..19770c46b68c 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1704,13 +1704,19 @@ struct DSEState {
/// \returns true if \p Def is a no-op store, either because it
/// directly stores back a loaded value or stores zero to a calloced object.
bool storeIsNoop(MemoryDef *Def, const Value *DefUO) {
- StoreInst *Store = dyn_cast<StoreInst>(Def->getMemoryInst());
- MemSetInst *MemSet = dyn_cast<MemSetInst>(Def->getMemoryInst());
+ Instruction *DefI = Def->getMemoryInst();
+ StoreInst *Store = dyn_cast<StoreInst>(DefI);
+ MemSetInst *MemSet = dyn_cast<MemSetInst>(DefI);
Constant *StoredConstant = nullptr;
if (Store)
StoredConstant = dyn_cast<Constant>(Store->getOperand(0));
- if (MemSet)
+ else if (MemSet)
StoredConstant = dyn_cast<Constant>(MemSet->getValue());
+ else
+ return false;
+
+ if (!isRemovable(DefI))
+ return false;
if (StoredConstant && StoredConstant->isNullValue()) {
auto *DefUOInst = dyn_cast<Instruction>(DefUO);
@@ -2065,8 +2071,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
}
// Check if the store is a no-op.
- if (!Shortend && isRemovable(KillingI) &&
- State.storeIsNoop(KillingDef, KillingUndObj)) {
+ if (!Shortend && State.storeIsNoop(KillingDef, KillingUndObj)) {
LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *KillingI
<< '\n');
State.deleteDeadInstruction(KillingI);
More information about the llvm-commits
mailing list