From 4837daf8836c66b7b28f58d412173dd7a51f0fdd Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 25 Jun 2020 13:31:11 +0100 Subject: [PATCH] [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. --- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 7 ++++--- llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 336b966..f55278d 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(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 603b971..64b6611 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 ; -- 2.7.4