[PATCH] D123846: [RS4GC] Prune inputs of BDV if they are BDV themselves

Dmitry Makogon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 01:42:59 PDT 2022


dmakogon created this revision.
dmakogon added reviewers: nikic, reames, mkazantsev, lebedev.ri.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dmakogon requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There's a stage in RS4GC when we remove all nodes from the state list if all of their inputs are base pointers.
Consider the following PHI:

  loop:
    %ph = phi i8* [ %ph, %loop ], [ %b, %block ]

Say %b is a base value. Then we should remove the %ph from the states list, because it's equal to %b.
This patch just skips all the input values if they are equal to the value currently being processed.

If in the example above we had a user of %ph for which we were asked to find a base value,
we'd clone that user and replaced %ph uses with the %b base value.
With the patch %ph is treated as a base pointer, so no cloning happens.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123846

Files:
  llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  llvm/test/Transforms/RewriteStatepointsForGC/base-pointers-14.ll


Index: llvm/test/Transforms/RewriteStatepointsForGC/base-pointers-14.ll
===================================================================
--- llvm/test/Transforms/RewriteStatepointsForGC/base-pointers-14.ll
+++ llvm/test/Transforms/RewriteStatepointsForGC/base-pointers-14.ll
@@ -6,8 +6,6 @@
 
 declare void @foo() gc "statepoint-example"
 
-; FIXME: In this test case %b6.base, which is inserted by RS4GC, is identical
-; to %b6.
 define i8 addrspace(1)* @test1(i1 %c, i8 addrspace(1)* %b1, i8 addrspace(1)* %b2) gc "statepoint-example" {
 ; CHECK-LABEL: @test1(
 ; CHECK-NEXT:  left:
@@ -16,11 +14,9 @@
 ; CHECK-NEXT:    [[B5:%.*]] = phi i8 addrspace(1)* [ [[B2:%.*]], [[LEFT:%.*]] ], [ [[B5]], [[LOOP]] ]
 ; CHECK-NEXT:    br i1 [[C]], label [[LOOP]], label [[MERGE2]]
 ; CHECK:       merge2:
-; CHECK-NEXT:    [[B6_BASE:%.*]] = phi i8 addrspace(1)* [ [[B1:%.*]], [[LEFT]] ], [ [[B2]], [[LOOP]] ], !is_base_value !0
-; CHECK-NEXT:    [[B6:%.*]] = phi i8 addrspace(1)* [ [[B1]], [[LEFT]] ], [ [[B5]], [[LOOP]] ]
-; CHECK-NEXT:    [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(), "gc-live"(i8 addrspace(1)* [[B6]], i8 addrspace(1)* [[B6_BASE]]) ]
-; CHECK-NEXT:    [[B6_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
-; CHECK-NEXT:    [[B6_BASE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
+; CHECK-NEXT:    [[B6:%.*]] = phi i8 addrspace(1)* [ [[B1:%.*]], [[LEFT]] ], [ [[B5]], [[LOOP]] ]
+; CHECK-NEXT:    [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(), "gc-live"(i8 addrspace(1)* [[B6]]) ]
+; CHECK-NEXT:    [[B6_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
 ; CHECK-NEXT:    ret i8 addrspace(1)* [[B6_RELOCATED]]
 ;
 left:
Index: llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -934,12 +934,16 @@
     for (auto Pair : States) {
       Value *BDV = Pair.first;
       auto canPruneInput = [&](Value *V) {
-        Value *BDV = findBaseOrBDV(V, Cache);
-        if (V->stripPointerCasts() != BDV)
+        // BDV is present in the states map, so in case when the input is the
+        // BDV itself, we'd return false. So explicitly check this case.
+        if (V == BDV)
+          return true;
+        Value *VBDV = findBaseOrBDV(V, Cache);
+        if (V->stripPointerCasts() != VBDV)
           return false;
         // The assumption is that anything not in the state list is
         // propagates a base pointer.
-        return States.count(BDV) == 0;
+        return States.count(VBDV) == 0;
       };
 
       bool CanPrune = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123846.423042.patch
Type: text/x-patch
Size: 3225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220415/f6cff7e1/attachment.bin>


More information about the llvm-commits mailing list