summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChangpeng Fang <changpeng.fang@gmail.com>2017-01-24 19:06:28 +0000
committerChangpeng Fang <changpeng.fang@gmail.com>2017-01-24 19:06:28 +0000
commitc85abbd95595ea81f78914ff130c46b6dca671a1 (patch)
tree4d320bbe7687cad5afef24c5014124349c01109f
parentc38cd326fcd7a62cf188a1c0beb5af47ced8b2ac (diff)
downloadbcm5719-llvm-c85abbd95595ea81f78914ff130c46b6dca671a1.tar.gz
bcm5719-llvm-c85abbd95595ea81f78914ff130c46b6dca671a1.zip
AMDGPU/SI: Give up in promote alloca when a pointer may be captured.
Differential Revision: http://reviews.llvm.org/D28970 Reviewer: Matt llvm-svn: 292966
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp4
-rw-r--r--llvm/test/CodeGen/AMDGPU/addrspacecast-captured.ll47
2 files changed, 51 insertions, 0 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 5de73698323..b78777f391e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -21,6 +21,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
@@ -608,6 +609,9 @@ bool AMDGPUPromoteAlloca::collectUsesWithPtrTypes(
}
if (UseInst->getOpcode() == Instruction::AddrSpaceCast) {
+ // Give up if the pointer may be captured.
+ if (PointerMayBeCaptured(UseInst, true, true))
+ return false;
// Don't collect the users of this.
WorkList.push_back(User);
continue;
diff --git a/llvm/test/CodeGen/AMDGPU/addrspacecast-captured.ll b/llvm/test/CodeGen/AMDGPU/addrspacecast-captured.ll
new file mode 100644
index 00000000000..481a3e2b31b
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/addrspacecast-captured.ll
@@ -0,0 +1,47 @@
+; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck %s
+
+; Nothing should be done if the addrspacecast is captured.
+
+declare void @consume_ptr2int(i32) #0
+
+; CHECK-LABEL: @addrspacecast_captured(
+; CHECK: %data = alloca i32, align 4
+; CHECK: %cast = addrspacecast i32* %data to i32 addrspace(4)*
+; CHECK: %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
+; CHECK: store i32 %ptr2int, i32 addrspace(1)* %out
+define void @addrspacecast_captured(i32 addrspace(1)* %out) #0 {
+entry:
+ %data = alloca i32, align 4
+ %cast = addrspacecast i32* %data to i32 addrspace(4)*
+ %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
+ store i32 %ptr2int, i32 addrspace(1)* %out
+ ret void
+}
+
+; CHECK-LABEL: @addrspacecast_captured_store(
+; CHECK: %data = alloca i32, align 4
+; CHECK: %cast = addrspacecast i32* %data to i32 addrspace(4)*
+; CHECK: store i32 addrspace(4)* %cast, i32 addrspace(4)* addrspace(1)* %out
+define void @addrspacecast_captured_store(i32 addrspace(4)* addrspace(1)* %out) #0 {
+entry:
+ %data = alloca i32, align 4
+ %cast = addrspacecast i32* %data to i32 addrspace(4)*
+ store i32 addrspace(4)* %cast, i32 addrspace(4)* addrspace(1)* %out
+ ret void
+}
+
+; CHECK-LABEL: @addrspacecast_captured_call(
+; CHECK: %data = alloca i32, align 4
+; CHECK: %cast = addrspacecast i32* %data to i32 addrspace(4)*
+; CHECK: %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
+; CHECK: call void @consume_ptr2int(i32 %ptr2int)
+define void @addrspacecast_captured_call() #0 {
+entry:
+ %data = alloca i32, align 4
+ %cast = addrspacecast i32* %data to i32 addrspace(4)*
+ %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
+ call void @consume_ptr2int(i32 %ptr2int)
+ ret void
+}
+
+attributes #0 = { nounwind }
OpenPOWER on IntegriCloud