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

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 11:17:38 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL292966: AMDGPU/SI: Give up in promote alloca when a pointer may be captured. (authored by chfang).

Changed prior to commit:
  https://reviews.llvm.org/D28970?vs=85613&id=85614#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28970

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


Index: llvm/trunk/test/CodeGen/AMDGPU/addrspacecast-captured.ll
===================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/addrspacecast-captured.ll
+++ llvm/trunk/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 }
Index: llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
===================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ llvm/trunk/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.85614.patch
Type: text/x-patch
Size: 2877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170124/b4ea95a8/attachment-0001.bin>


More information about the llvm-commits mailing list