<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi Philip.
<div class=""><br class="">
</div>
<div class="">I had actually updated the comment in the Phabricator, after the commit. </div>
<div class=""><br class="">
</div>
<div class=""><a href="https://reviews.llvm.org/rL282150" class="">https://reviews.llvm.org/rL282150</a></div>
<div class=""><br class="">
</div>
<div class="">
<p style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;" class="">
Forgot to amend the commit before submit:</p>
<p style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;" class="">
Summary:<br style="margin-top: 0px;" class="">
When rematerializing for geps and casts in presence of phis, we need to make<br class="">
sure that unrelocated values (the current Phi node) should never be used.<br class="">
The relocation is only done for the base version of the phi, which is generated<br class="">
by findBasePointers function.</p>
<p style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;" class="">
This is a fix when IR verifier for safepoints identifies uses of unrelocated values,<br style="margin-top: 0px;" class="">
which was generated due to commit <a href="https://reviews.llvm.org/rL279975" class="phui-tag-view  phui-tag-type-object" data-sigil="hovercard" data-meta="0_22" style="text-decoration: none; color: rgb(0, 0, 0); cursor: pointer; font-weight: bold; position: relative; -webkit-font-smoothing: antialiased; white-space: nowrap;"><span class="phui-tag-core phui-tag-color-object" style="color: inherit; border: 1px solid rgb(231, 231, 231); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 0px 4px; background-color: rgb(231, 231, 231); margin-top: 0px;">rL279975</span></a>.</p>
<p style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;" class="">
Reviewers: Philip</p>
<div style="margin: 0px; padding: 0px; border: 0px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;" class="">
Differential Revision: <font color="#136cb2" class=""><span style="cursor: pointer;" class=""><a href="https://reviews.llvm.org/D24399" class="">https://reviews.llvm.org/D24399</a></span></font></div>
</div>
<div style="margin: 0px; padding: 0px; border: 0px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;" class="">
<br class="">
</div>
<div class=""><br class="">
</div>
<div class=""> </div>
<div class="">Thanks,</div>
<div class="">Anna</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Sep 27, 2016, at 7:20 PM, Philip Reames <<a href="mailto:listmail@philipreames.com" class="">listmail@philipreames.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Anna,<br class="">
<br class="">
It looks like the commit message lost the link with the review. Can you reply with a more full commit message and a link to the review thread?<br class="">
<br class="">
Philip<br class="">
<br class="">
<br class="">
On 09/22/2016 06:13 AM, Anna Thomas via llvm-commits wrote:<br class="">
<blockquote type="cite" class="">Author: annat<br class="">
Date: Thu Sep 22 08:13:06 2016<br class="">
New Revision: 282150<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=282150&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=282150&view=rev</a><br class="">
Log:<br class="">
[RS4GC] Remat in presence of phi and use live value<br class="">
<br class="">
Summary:<br class="">
<br class="">
Reviewers:<br class="">
<br class="">
Subscribers:<br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp<br class="">
    llvm/trunk/test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll<br class="">
<br class="">
Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=282150&r1=282149&r2=282150&view=diff" class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=282150&r1=282149&r2=282150&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)<br class="">
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Thu Sep 22 08:13:06 2016<br class="">
@@ -1976,7 +1976,8 @@ static void rematerializeLiveValues(Call<br class="">
     // Utility function which clones all instructions from "ChainToBase"<br class="">
     // and inserts them before "InsertBefore". Returns rematerialized value<br class="">
     // which should be used after statepoint.<br class="">
-    auto rematerializeChain = [&ChainToBase](Instruction *InsertBefore) {<br class="">
+    auto rematerializeChain = [&ChainToBase](<br class="">
+        Instruction *InsertBefore, Value *RootOfChain, Value *AlternateLiveBase) {<br class="">
       Instruction *LastClonedValue = nullptr;<br class="">
       Instruction *LastValue = nullptr;<br class="">
       for (Instruction *Instr: ChainToBase) {<br class="">
@@ -1996,13 +1997,24 @@ static void rematerializeLiveValues(Call<br class="">
           assert(LastValue);<br class="">
           ClonedValue->replaceUsesOfWith(LastValue, LastClonedValue);<br class="">
 #ifndef NDEBUG<br class="">
-          // Assert that cloned instruction does not use any instructions from<br class="">
-          // this chain other than LastClonedValue<br class="">
           for (auto OpValue : ClonedValue->operand_values()) {<br class="">
+            // Assert that cloned instruction does not use any instructions from<br class="">
+            // this chain other than LastClonedValue<br class="">
             assert(!is_contained(ChainToBase, OpValue) &&<br class="">
                    "incorrect use in rematerialization chain");<br class="">
+            // Assert that the cloned instruction does not use the RootOfChain<br class="">
+            // or the AlternateLiveBase.<br class="">
+            assert(OpValue != RootOfChain && OpValue != AlternateLiveBase);<br class="">
           }<br class="">
 #endif<br class="">
+        } else {<br class="">
+          // For the first instruction, replace the use of unrelocated base i.e.<br class="">
+          // RootOfChain/OrigRootPhi, with the corresponding PHI present in the<br class="">
+          // live set. They have been proved to be the same PHI nodes.  Note<br class="">
+          // that the *only* use of the RootOfChain in the ChainToBase list is<br class="">
+          // the first Value in the list.<br class="">
+          if (RootOfChain != AlternateLiveBase)<br class="">
+            ClonedValue->replaceUsesOfWith(RootOfChain, AlternateLiveBase);<br class="">
         }<br class="">
           LastClonedValue = ClonedValue;<br class="">
@@ -2017,7 +2029,8 @@ static void rematerializeLiveValues(Call<br class="">
     if (CS.isCall()) {<br class="">
       Instruction *InsertBefore = CS.getInstruction()->getNextNode();<br class="">
       assert(InsertBefore);<br class="">
-      Instruction *RematerializedValue = rematerializeChain(InsertBefore);<br class="">
+      Instruction *RematerializedValue = rematerializeChain(<br class="">
+          InsertBefore, RootOfChain, Info.PointerToBase[LiveValue]);<br class="">
       Info.RematerializedValues[RematerializedValue] = LiveValue;<br class="">
     } else {<br class="">
       InvokeInst *Invoke = cast<InvokeInst>(CS.getInstruction());<br class="">
@@ -2027,10 +2040,10 @@ static void rematerializeLiveValues(Call<br class="">
       Instruction *UnwindInsertBefore =<br class="">
           &*Invoke->getUnwindDest()->getFirstInsertionPt();<br class="">
 -      Instruction *NormalRematerializedValue =<br class="">
-          rematerializeChain(NormalInsertBefore);<br class="">
-      Instruction *UnwindRematerializedValue =<br class="">
-          rematerializeChain(UnwindInsertBefore);<br class="">
+      Instruction *NormalRematerializedValue = rematerializeChain(<br class="">
+          NormalInsertBefore, RootOfChain, Info.PointerToBase[LiveValue]);<br class="">
+      Instruction *UnwindRematerializedValue = rematerializeChain(<br class="">
+          UnwindInsertBefore, RootOfChain, Info.PointerToBase[LiveValue]);<br class="">
         Info.RematerializedValues[NormalRematerializedValue] = LiveValue;<br class="">
       Info.RematerializedValues[UnwindRematerializedValue] = LiveValue;<br class="">
<br class="">
Modified: llvm/trunk/test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll?rev=282150&r1=282149&r2=282150&view=diff" class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll?rev=282150&r1=282149&r2=282150&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll (original)<br class="">
+++ llvm/trunk/test/Transforms/RewriteStatepointsForGC/rematerialize-derived-pointers.ll Thu Sep 22 08:13:06 2016<br class="">
@@ -285,7 +285,7 @@ merge:<br class="">
   ; CHECK: %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint<br class="">
   ; 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)<br class="">
   ; CHECK: %basephi.base.relocated.casted = bitcast i8 addrspace(1)* %basephi.base.relocated to i32 addrspace(1)*<br class="">
-  ; CHECK: %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi, i32 15<br class="">
+  ; CHECK: %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi.base.relocated.casted, i32 15<br class="">
   ; CHECK: call void @use_obj32(i32 addrspace(1)* %ptr.gep.remat)<br class="">
   @@ -296,3 +296,35 @@ merge:<br class="">
   call void @use_obj32(i32 addrspace(1)* %ptr.gep)<br class="">
   ret void<br class="">
 }<br class="">
+<br class="">
+<br class="">
+define void @test_intersecting_chains_with_phi(i1 %cond) gc "statepoint-example" {<br class="">
+; CHECK-LABEL: test_intersecting_chains_with_phi<br class="">
+entry:<br class="">
+  %base1 = call i32 addrspace(1)* @new_instance()<br class="">
+  %base2 = call i32 addrspace(1)* @new_instance()<br class="">
+  br i1 %cond, label %here, label %there<br class="">
+<br class="">
+here:<br class="">
+  br label %merge<br class="">
+<br class="">
+there:<br class="">
+  br label %merge<br class="">
+<br class="">
+merge:<br class="">
+  %basephi = phi i32 addrspace(1)* [ %base1, %here ], [ %base2, %there ]<br class="">
+  %ptr.gep = getelementptr i32, i32 addrspace(1)* %basephi, i32 15<br class="">
+  %ptr.cast = bitcast i32 addrspace(1)* %ptr.gep to i64 addrspace(1)*<br class="">
+  %ptr.cast2 = bitcast i32 addrspace(1)* %ptr.gep to i16 addrspace(1)*<br class="">
+  call void @do_safepoint() [ "deopt"() ]<br class="">
+  ; CHECK: statepoint<br class="">
+  ; CHECK: %ptr.gep.remat1 = getelementptr i32, i32 addrspace(1)* %basephi.base.relocated.casted, i32 15<br class="">
+  ; CHECK: %ptr.cast.remat = bitcast i32 addrspace(1)* %ptr.gep.remat1 to i64 addrspace(1)*<br class="">
+  ; CHECK: %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi.base.relocated.casted, i32 15<br class="">
+  ; CHECK: %ptr.cast2.remat = bitcast i32 addrspace(1)* %ptr.gep.remat to i16 addrspace(1)*<br class="">
+  ; CHECK: call void @use_obj64(i64 addrspace(1)* %ptr.cast.remat)<br class="">
+  ; CHECK: call void @use_obj16(i16 addrspace(1)* %ptr.cast2.remat)<br class="">
+  call void @use_obj64(i64 addrspace(1)* %ptr.cast)<br class="">
+  call void @use_obj16(i16 addrspace(1)* %ptr.cast2)<br class="">
+  ret void<br class="">
+}<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class="">
</blockquote>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>