[PATCH] D28970: AMDGPU/SI: Give up in promote aloca when a pointer may be captured.

Changpeng Fang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 13:47:54 PST 2017


cfang created this revision.
Herald added subscribers: tony-tye, yaxunl, nhaehnle, wdng, kzhuravl.

Give up in promote aloca when a pointer may be captured.


https://reviews.llvm.org/D28970

Files:
  lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
  test/CodeGen/AMDGPU/addrspacecast-captured.ll


Index: test/CodeGen/AMDGPU/addrspacecast-captured.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/addrspacecast-captured.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck %s
+
+; Nothing should be done if the addrspacecast is captured.
+
+; CHECK-LABEL: @addrspacecast_captured(
+; CHECK: %data = alloca i32, align 4
+; CHECK: %tmp = addrspacecast i32* %data to i32 addrspace(4)*
+; CHECK: %0 = ptrtoint i32 addrspace(4)* %tmp to i32
+; CHECK: store i32 %0, i32 addrspace(1)* %out
+define void @addrspacecast_captured(i32 addrspace(1)* %out) #0 {
+entry:
+  %data = alloca i32, align 4
+  %tmp = addrspacecast i32* %data to i32 addrspace(4)*
+  %0 = ptrtoint i32 addrspace(4)* %tmp to i32
+  store i32 %0, i32 addrspace(1)* %out
+  ret void
+}
+
+attributes #0 = { nounwind }
Index: lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
===================================================================
--- lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ 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 @@
     }
 
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28970.85186.patch
Type: text/x-patch
Size: 1689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170120/ba2dc4cf/attachment.bin>


More information about the llvm-commits mailing list