From: Nikita Popov Date: Fri, 24 Dec 2021 09:14:55 +0000 (+0100) Subject: [DSE] Avoid calling isRemovable() on non-analyzable location (NFC) X-Git-Tag: upstream/15.0.7~22233 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b8a703858ea994f6665fc35220f2ea56cabe39d;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 016a59f..19770c4 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(Def->getMemoryInst()); - MemSetInst *MemSet = dyn_cast(Def->getMemoryInst()); + Instruction *DefI = Def->getMemoryInst(); + StoreInst *Store = dyn_cast(DefI); + MemSetInst *MemSet = dyn_cast(DefI); Constant *StoredConstant = nullptr; if (Store) StoredConstant = dyn_cast(Store->getOperand(0)); - if (MemSet) + else if (MemSet) StoredConstant = dyn_cast(MemSet->getValue()); + else + return false; + + if (!isRemovable(DefI)) + return false; if (StoredConstant && StoredConstant->isNullValue()) { auto *DefUOInst = dyn_cast(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);