From ba59efdfc80f404b0615cdddf40903f7e1f03d18 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Mon, 9 Feb 2015 21:08:03 +0000 Subject: [PATCH] isDereferenceablePointer: look through gc.relocate calls 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 | 9 +++++++++ test/Analysis/ValueTracking/memory-dereferenceable.ll | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index 52dcd6311ff..7d205f975eb 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -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" @@ -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(V)) + if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) { + GCRelocateOperands RelocateInst(I); + return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, Visited); + } + if (const AddrSpaceCastInst *ASC = dyn_cast(V)) return isDereferenceablePointer(ASC->getOperand(0), DL, Visited); diff --git a/test/Analysis/ValueTracking/memory-dereferenceable.ll b/test/Analysis/ValueTracking/memory-dereferenceable.ll index 1ec3fefc565..676d33a4e2e 100644 --- a/test/Analysis/ValueTracking/memory-dereferenceable.ll +++ b/test/Analysis/ValueTracking/memory-dereferenceable.ll @@ -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