[llvm] 4837daf - [DSE, MSSA] Check if Def is removable only wen we try to remove it.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 25 06:04:16 PDT 2020
Author: Florian Hahn
Date: 2020-06-25T14:01:10+01:00
New Revision: 4837daf8836c66b7b28f58d412173dd7a51f0fdd
URL: https://github.com/llvm/llvm-project/commit/4837daf8836c66b7b28f58d412173dd7a51f0fdd
DIFF: https://github.com/llvm/llvm-project/commit/4837daf8836c66b7b28f58d412173dd7a51f0fdd.diff
LOG: [DSE,MSSA] Check if Def is removable only wen we try to remove it.
Non-removable MemoryDefs can still eliminate other defs. Update the
isRemovable checks to only candidates for removal.
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 336b96607faf..f55278d56790 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1535,7 +1535,7 @@ struct DSEState {
auto *MD = dyn_cast_or_null<MemoryDef>(MA);
if (MD && State.MemDefs.size() < MemorySSADefsPerBlockLimit &&
- State.getLocForWriteEx(&I) && isRemovable(&I))
+ State.getLocForWriteEx(&I))
State.MemDefs.push_back(MD);
// Track whether alloca and alloca-like objects are visible in the
@@ -1980,7 +1980,8 @@ struct DSEState {
<< "Trying to eliminate MemoryDefs at the end of the function\n");
for (int I = MemDefs.size() - 1; I >= 0; I--) {
MemoryDef *Def = MemDefs[I];
- if (SkipStores.find(Def) != SkipStores.end())
+ if (SkipStores.find(Def) != SkipStores.end() ||
+ !isRemovable(Def->getMemoryInst()))
continue;
// TODO: Consider doing the underlying object check first, if it is
@@ -2069,7 +2070,7 @@ bool eliminateDeadStoresMemorySSA(Function &F, AliasAnalysis &AA,
const Value *SILocUnd = GetUnderlyingObject(SILoc.Ptr, DL);
// Check if the store is a no-op.
- if (State.storeIsNoop(KillingDef, SILoc, SILocUnd)) {
+ if (isRemovable(SI) && State.storeIsNoop(KillingDef, SILoc, SILocUnd)) {
LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *SI << '\n');
State.deleteDeadInstruction(SI);
NumNoopStores++;
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll
index 603b971a6f4b..64b66114d5da 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll
@@ -700,7 +700,6 @@ define void @test44_volatile(i32* %P) {
define void @test45_volatile(i32* %P) {
; CHECK-LABEL: @test45_volatile(
-; CHECK-NEXT: store i32 1, i32* [[P:%.*]], align 4
; CHECK-NEXT: store volatile i32 2, i32* [[P]], align 4
; CHECK-NEXT: store volatile i32 3, i32* [[P]], align 4
; CHECK-NEXT: ret void
@@ -714,7 +713,6 @@ define void @test45_volatile(i32* %P) {
define void @test46_volatile(i32* %P) {
; CHECK-LABEL: @test46_volatile(
; CHECK-NEXT: store volatile i32 2, i32* [[P:%.*]], align 4
-; CHECK-NEXT: store i32 1, i32* [[P]], align 4
; CHECK-NEXT: store volatile i32 3, i32* [[P]], align 4
; CHECK-NEXT: ret void
;
More information about the llvm-commits
mailing list