-
-
Save nikic/83b3207c0581cbbcc7d95a5a20c23d93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | |
index 330d25c4dbc..d152e89d345 100644 | |
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | |
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | |
@@ -1941,6 +1941,7 @@ struct DSEState { | |
LLVM_DEBUG(dbgs() << " trying to get dominating access\n"); | |
// Find the next clobbering Mod access for DefLoc, starting at StartAccess. | |
+ Optional<MemoryLocation> CurrentLoc; | |
do { | |
StepAgain = false; | |
LLVM_DEBUG({ | |
@@ -2032,13 +2033,24 @@ struct DSEState { | |
} | |
// If Current does not have an analyzable write location, skip it | |
- auto CurrentLoc = getLocForWriteEx(CurrentI); | |
+ CurrentLoc = getLocForWriteEx(CurrentI); | |
if (!CurrentLoc) { | |
StepAgain = true; | |
Current = CurrentDef->getDefiningAccess(); | |
continue; | |
} | |
+ // AliasAnalysis does not account for loops. Limit elimination to | |
+ // candidates for which we can guarantee they always store to the same | |
+ // memory location and not multiple locations in a loop. | |
+ if (Current->getBlock() != KillingDef->getBlock() && | |
+ !IsGuaranteedLoopInvariant(const_cast<Value *>(CurrentLoc->Ptr))) { | |
+ StepAgain = true; | |
+ Current = CurrentDef->getDefiningAccess(); | |
+ WalkerStepLimit -= 1; | |
+ continue; | |
+ } | |
+ | |
if (IsMemTerm) { | |
// If the killing def is a memory terminator (e.g. lifetime.end), check | |
// the next candidate if the current Current does not write the same | |
@@ -2049,17 +2061,6 @@ struct DSEState { | |
} | |
continue; | |
} else { | |
- // AliasAnalysis does not account for loops. Limit elimination to | |
- // candidates for which we can guarantee they always store to the same | |
- // memory location and not multiple locations in a loop. | |
- if (Current->getBlock() != KillingDef->getBlock() && | |
- !IsGuaranteedLoopInvariant(const_cast<Value *>(CurrentLoc->Ptr))) { | |
- StepAgain = true; | |
- Current = CurrentDef->getDefiningAccess(); | |
- WalkerStepLimit -= 1; | |
- continue; | |
- } | |
- | |
int64_t InstWriteOffset, DepWriteOffset; | |
auto OR = isOverwrite(KillingI, CurrentI, DefLoc, *CurrentLoc, DL, TLI, | |
DepWriteOffset, InstWriteOffset, BatchAA, &F); | |
@@ -2182,7 +2183,7 @@ struct DSEState { | |
// Uses which may read the original MemoryDef mean we cannot eliminate the | |
// original MD. Stop walk. | |
- if (isReadClobber(DefLoc, UseInst)) { | |
+ if (isReadClobber(*CurrentLoc, UseInst)) { | |
LLVM_DEBUG(dbgs() << " ... found read clobber\n"); | |
Cache.KnownReads.insert(UseAccess); | |
Cache.KnownReads.insert(StartAccess); | |
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/out-of-bounds-stores.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/out-of-bounds-stores.ll | |
index 3a16a62dddd..925ab4e9959 100644 | |
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/out-of-bounds-stores.ll | |
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/out-of-bounds-stores.ll | |
@@ -36,6 +36,8 @@ define i32 @test_out_of_bounds_store_nonlocal(i1 %c) { | |
; CHECK-NEXT: [[D:%.*]] = alloca [1 x i32], align 4 | |
; CHECK-NEXT: br label [[FOR_BODY:%.*]] | |
; CHECK: for.body: | |
+; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0 | |
+; CHECK-NEXT: store i32 10, i32* [[ARRAYIDX]], align 4 | |
; CHECK-NEXT: br label [[FOR_INC:%.*]] | |
; CHECK: for.inc: | |
; CHECK-NEXT: br i1 [[C:%.*]], label [[FOR_BODY_1:%.*]], label [[FOR_END:%.*]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment