Skip to content

Commit 327bbbb

Browse files
committed
[DSE] Make capture check more precise
It is sufficient that the object has not been captured before the load that produces the pointer we're loading. A capture after that can not affect the already loaded pointer. This is small part of D110368 applied separately.
1 parent 1c3859f commit 327bbbb

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,10 @@ struct DSEState {
13181318
// before the load.
13191319
auto *ReadUO = getUnderlyingObject(LI->getPointerOperand());
13201320
auto *DefUO = getUnderlyingObject(DefLoc.Ptr);
1321-
if (DefUO && ReadUO && isa<LoadInst>(ReadUO) &&
1322-
notCapturedBeforeOrAt(DefUO, UseInst)) {
1321+
auto *ReadLI = dyn_cast<LoadInst>(ReadUO);
1322+
if (ReadLI && notCapturedBeforeOrAt(DefUO, ReadLI)) {
13231323
assert(
1324-
!PointerMayBeCapturedBefore(DefLoc.Ptr, false, true, UseInst, &DT,
1324+
!PointerMayBeCapturedBefore(DefLoc.Ptr, false, true, ReadLI, &DT,
13251325
false, 0, &this->LI) &&
13261326
"cached analysis disagrees with fresh PointerMayBeCapturedBefore");
13271327
return false;

llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ define i32 @test_captured_and_clobbered_before_load_same_bb_1(i32** %in.ptr) {
113113
define i32 @test_captured_before_load_same_bb_1_clobbered_later(i32** %in.ptr) {
114114
; CHECK-LABEL: @test_captured_before_load_same_bb_1_clobbered_later(
115115
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
116-
; CHECK-NEXT: store i32 55, i32* [[A]], align 4
117116
; CHECK-NEXT: [[IN_LV_1:%.*]] = load i32*, i32** [[IN_PTR:%.*]], align 2
118117
; CHECK-NEXT: call void @escape_writeonly(i32* [[A]])
119118
; CHECK-NEXT: [[IN_LV_2:%.*]] = load i32, i32* [[IN_LV_1]], align 2

0 commit comments

Comments
 (0)