isDereferenceablePointer: look through gc.relocate calls
authorRamkumar Ramachandra <artagnon@gmail.com>
Mon, 9 Feb 2015 21:08:03 +0000 (21:08 +0000)
committerRamkumar Ramachandra <artagnon@gmail.com>
Mon, 9 Feb 2015 21:08:03 +0000 (21:08 +0000)
While a theoretical GC might change dereferenceability on collection,
there is no such known collector and no need to account for the case
with a flag yet.

Differential Revision: http://reviews.llvm.org/D7454

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228606 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Value.cpp
test/Analysis/ValueTracking/memory-dereferenceable.ll

index 52dcd6311ff81bd7683c2d0f50dcda38fd889d45..7d205f975eb4ecd51754be724847f90140042b27 100644 (file)
 #include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/Statepoint.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
@@ -570,6 +572,13 @@ static bool isDereferenceablePointer(const Value *V, const DataLayout *DL,
     return true;
   }
 
+  // For gc.relocate, look through relocations
+  if (const IntrinsicInst *I = dyn_cast<IntrinsicInst>(V))
+    if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) {
+      GCRelocateOperands RelocateInst(I);
+      return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, Visited);
+    }
+
   if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V))
     return isDereferenceablePointer(ASC->getOperand(0), DL, Visited);
 
index 1ec3fefc56568e1d4fc51f4b3db7258c53f9f211..676d33a4e2ed3fa5e75deb3b54fe5243a61fb38f 100644 (file)
@@ -12,8 +12,7 @@ define void @test(i32 addrspace(1)* byval %dparam) {
 ; CHECK: %globalptr
 ; CHECK: %alloca
 ; CHECK: %dparam
-; We haven't yet taught it to look through relocations
-; CHECK-NOT: %relocate
+; CHECK: %relocate
 ; CHECK-NOT: %nparam
 entry:
     %globalptr = getelementptr inbounds [6 x i8]* @globalstr, i32 0, i32 0