[llvm] 327bbbb - [DSE] Make capture check more precise

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 25 13:23:57 PDT 2021


Author: Nikita Popov
Date: 2021-09-25T22:23:19+02:00
New Revision: 327bbbb10bfd95db38ae3406c87d481a07f67633

URL: https://github.com/llvm/llvm-project/commit/327bbbb10bfd95db38ae3406c87d481a07f67633
DIFF: https://github.com/llvm/llvm-project/commit/327bbbb10bfd95db38ae3406c87d481a07f67633.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
    llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 1e933f3f9cf6..2fa5f4c366af 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -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;

diff  --git a/llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll b/llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll
index 9b02e4b2e159..5243bb335b78 100644
--- a/llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll
@@ -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


        


More information about the llvm-commits mailing list