[PATCH] D24399: [RS4GC] Avoid usage of unrelocated values while rematerializing geps and casts

Anna Thomas via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 08:09:53 PDT 2016


anna created this revision.
anna added reviewers: sanjoy, reames, igor-laevsky.
anna added a subscriber: llvm-commits.
Herald added a subscriber: sanjoy.

When rematerializing for geps and casts in presence of phis, we need to make
sure that unrelocated values (the current Phi node) should never be used.
The relocation is only done for the base version of the phi, which is generated
by findBasePointers function.

This is a fix when IR verifier for safepoints identifies uses of unrelocated values,
which was generated due to commit rL279975.

https://reviews.llvm.org/D24399

Files:
  lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll

Index: test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll
===================================================================
--- test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll
+++ test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll
@@ -281,11 +281,11 @@
 merge:
   ; CHECK: %basephi.base = phi i32 addrspace(1)* [ %base1, %here ], [ %base2, %there ], !is_base_value !0
   ; CHECK: %basephi = phi i32 addrspace(1)* [ %base1, %here ], [ %base2, %there ]
-  ; CHECK: %ptr.gep = getelementptr i32, i32 addrspace(1)* %basephi, i32 15
+  ; CHECK: %ptr.gep = getelementptr i32, i32 addrspace(1)* %basephi.base, i32 15
   ; CHECK: %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint
   ; CHECK: %basephi.base.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 7, i32 7) ; (%basephi.base, %basephi.base)
   ; CHECK: %basephi.base.relocated.casted = bitcast i8 addrspace(1)* %basephi.base.relocated to i32 addrspace(1)*
-  ; CHECK: %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi, i32 15
+  ; CHECK: %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi.base.relocated.casted, i32 15
   ; CHECK: call void @use_obj32(i32 addrspace(1)* %ptr.gep.remat)
 
 
@@ -296,3 +296,44 @@
   call void @use_obj32(i32 addrspace(1)* %ptr.gep)
   ret void
 }
+
+define void @contains_basephi_test_too_long(i1 %cond) gc "statepoint-example" {
+; CHECK-LABEL: contains_basephi_test_too_long
+entry:
+  %base1 = call i32 addrspace(1)* @new_instance()
+  %base2 = call i32 addrspace(1)* @new_instance()
+  br i1 %cond, label %here, label %there
+
+here:
+  br label %merge
+
+there:
+  br label %merge
+
+merge:
+; CHECK: merge:
+; CHECK: getelementptr i32, i32 addrspace(1)* %basephi.base, i32 15
+; CHECK: getelementptr i32, i32 addrspace(1)* %ptr.gep, i32 15
+  %basephi = phi i32 addrspace(1)* [ %base1, %here ], [ %base2, %there ]
+  %ptr.gep = getelementptr i32, i32 addrspace(1)* %basephi, i32 15
+  %ptr.gep1 = getelementptr i32, i32 addrspace(1)* %ptr.gep, i32 15
+  %ptr.gep2 = getelementptr i32, i32 addrspace(1)* %ptr.gep1, i32 15
+  %ptr.gep3 = getelementptr i32, i32 addrspace(1)* %ptr.gep2, i32 15
+  %ptr.gep4 = getelementptr i32, i32 addrspace(1)* %ptr.gep3, i32 15
+  %ptr.gep5 = getelementptr i32, i32 addrspace(1)* %ptr.gep4, i32 15
+  %ptr.gep6 = getelementptr i32, i32 addrspace(1)* %ptr.gep5, i32 15
+  %ptr.gep7 = getelementptr i32, i32 addrspace(1)* %ptr.gep6, i32 15
+  %ptr.gep8 = getelementptr i32, i32 addrspace(1)* %ptr.gep7, i32 15
+  %ptr.gep9 = getelementptr i32, i32 addrspace(1)* %ptr.gep8, i32 15
+  %ptr.gep10 = getelementptr i32, i32 addrspace(1)* %ptr.gep9, i32 15
+  %ptr.gep11 = getelementptr i32, i32 addrspace(1)* %ptr.gep10, i32 15
+  call void @do_safepoint() [ "deopt"() ]
+; CHECK: gc.relocate
+; CHECK: bitcast
+; CHECK: gc.relocate
+; CHECK: bitcast
+; CHECK: call void @use_obj32(i32 addrspace(1)* %ptr.gep11.relocated.casted)
+; CHECK-NOT: remat
+  call void @use_obj32(i32 addrspace(1)* %ptr.gep11)
+  ret void
+}
Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===================================================================
--- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1856,6 +1856,12 @@
         if (CurrentIncomingBB != BasePhi->getIncomingBlock(i))
           return false;
       }
+      // The rematerialized gep/cast instructions should use the relocated base
+      // value (note that the current phi will never be relocated). So, all its
+      // uses should also be modified to the base phi. This does not affect the
+      // scenario where the gep/casts are relocated instead of being
+      // rematerialized.
+      CurrentPhi->replaceAllUsesWith(BasePhi);
       return true;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24399.70839.patch
Type: text/x-patch
Size: 3906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160909/867df219/attachment.bin>


More information about the llvm-commits mailing list