Skip to content

Commit

Permalink
[DSE] Make capture check more precise
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Sep 25, 2021
1 parent 1c3859f commit 327bbbb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Expand Up @@ -1318,10 +1318,10 @@ struct DSEState {
// before the load.
auto *ReadUO = getUnderlyingObject(LI->getPointerOperand());
auto *DefUO = getUnderlyingObject(DefLoc.Ptr);
if (DefUO && ReadUO && isa<LoadInst>(ReadUO) &&
notCapturedBeforeOrAt(DefUO, UseInst)) {
auto *ReadLI = dyn_cast<LoadInst>(ReadUO);
if (ReadLI && notCapturedBeforeOrAt(DefUO, ReadLI)) {
assert(
!PointerMayBeCapturedBefore(DefLoc.Ptr, false, true, UseInst, &DT,
!PointerMayBeCapturedBefore(DefLoc.Ptr, false, true, ReadLI, &DT,
false, 0, &this->LI) &&
"cached analysis disagrees with fresh PointerMayBeCapturedBefore");
return false;
Expand Down
Expand Up @@ -113,7 +113,6 @@ define i32 @test_captured_and_clobbered_before_load_same_bb_1(i32** %in.ptr) {
define i32 @test_captured_before_load_same_bb_1_clobbered_later(i32** %in.ptr) {
; CHECK-LABEL: @test_captured_before_load_same_bb_1_clobbered_later(
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
; CHECK-NEXT: store i32 55, i32* [[A]], align 4
; CHECK-NEXT: [[IN_LV_1:%.*]] = load i32*, i32** [[IN_PTR:%.*]], align 2
; CHECK-NEXT: call void @escape_writeonly(i32* [[A]])
; CHECK-NEXT: [[IN_LV_2:%.*]] = load i32, i32* [[IN_LV_1]], align 2
Expand Down

0 comments on commit 327bbbb

Please sign in to comment.