Skip to content

Commit

Permalink
isDereferenceablePointer: look through gc.relocate calls
Browse files Browse the repository at this point in the history
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

llvm-svn: 228606
  • Loading branch information
artagnon committed Feb 9, 2015
1 parent 641c24b commit a7343d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions llvm/lib/IR/Value.cpp
Expand Up @@ -23,8 +23,10 @@
#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"
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
Expand Up @@ -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
Expand Down

0 comments on commit a7343d6

Please sign in to comment.