[PATCH] D38849: [RS4GC] Look through vector bitcasts when looking for base pointer

Daniel Neilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 09:14:37 PDT 2017


dneilson created this revision.

In RS4GC it is possible that a base pointer is contained in a vector that
has undergone a bitcast from one element-pointertype to another. We teach
RS4GC how to look through bitcasts of vector types when looking for a base
pointer.


https://reviews.llvm.org/D38849

Files:
  lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  test/Transforms/RewriteStatepointsForGC/vector-bitcast.ll


Index: test/Transforms/RewriteStatepointsForGC/vector-bitcast.ll
===================================================================
--- /dev/null
+++ test/Transforms/RewriteStatepointsForGC/vector-bitcast.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -rewrite-statepoints-for-gc < %s | FileCheck %s
+;
+; A test to make sure that we can look through bitcasts of
+; vector types when a base pointer is contained in a vector.
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: uwtable
+define void @test() gc "statepoint-example" {
+; CHECK-LABEL: @test
+entry:
+; CHECK-LABEL: entry
+; CHECK: %bc = bitcast
+; CHECK: %[[p1:[A-Za-z0-9_]+]] = extractelement
+; CHECK: %[[p2:[A-Za-z0-9_]+]] = extractelement
+  %bc = bitcast <8 x i8 addrspace(1)*> undef to <8 x i32 addrspace(1)*>
+  %ptr= extractelement <8 x i32 addrspace(1)*> %bc, i32 7
+  switch i6 undef, label %bb3 [
+    i6 4, label %bb2
+    i6 22, label %bb1
+  ]
+
+bb1:
+; CHECK-LABEL: bb1
+; CHECK: llvm.experimental.gc.statepoint
+; CHECK: %[[p2]].relocated = {{.+}} @llvm.experimental.gc.relocate
+; CHECK: %[[p1]].relocated = {{.+}} @llvm.experimental.gc.relocate
+; CHECK: load atomic
+  %0 = call i8 addrspace(1)* undef() [ "deopt"() ]
+  %1 = load atomic i32, i32 addrspace(1)* %ptr unordered, align 4
+  unreachable
+
+bb2:
+  unreachable
+
+bb3:
+  unreachable
+}
Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===================================================================
--- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -421,6 +421,11 @@
   if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
     return findBaseDefiningValue(GEP->getPointerOperand());
 
+  // If the pointer comes through a bitcast of a vector of pointers to
+  // a vector of another type of pointer, then look through the bitcast
+  if (auto *BC = dyn_cast<BitCastInst>(I))
+    return findBaseDefiningValue(BC->getOperand(0));
+
   // A PHI or Select is a base defining value.  The outer findBasePointer
   // algorithm is responsible for constructing a base value for this BDV.
   assert((isa<SelectInst>(I) || isa<PHINode>(I)) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38849.118796.patch
Type: text/x-patch
Size: 2218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171012/c4603c1a/attachment.bin>


More information about the llvm-commits mailing list