summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2016-03-23 23:17:29 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2016-03-23 23:17:29 +0000
commit0a30e456b4aab86bb3066aca14218a498d1022f0 (patch)
treecd48dd5c595be18e4c6989ad36a797e669c79fa4 /llvm
parent9987f43ffa3e422efb0bc83186f5066f0155bf4c (diff)
downloadbcm5719-llvm-0a30e456b4aab86bb3066aca14218a498d1022f0.tar.gz
bcm5719-llvm-0a30e456b4aab86bb3066aca14218a498d1022f0.zip
AMDGPU: Promote alloca should skip volatiles
llvm-svn: 264214
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp13
-rw-r--r--llvm/test/CodeGen/AMDGPU/promote-alloca-volatile.ll26
2 files changed, 39 insertions, 0 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 9de8ee888b9..321323fb21c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -444,9 +444,22 @@ static bool collectUsesWithPtrTypes(Value *Val, std::vector<Value*> &WorkList) {
return false;
if (StoreInst *SI = dyn_cast_or_null<StoreInst>(UseInst)) {
+ if (SI->isVolatile())
+ return false;
+
// Reject if the stored value is not the pointer operand.
if (SI->getPointerOperand() != Val)
return false;
+ } else if (LoadInst *LI = dyn_cast_or_null<LoadInst>(UseInst)) {
+ if (LI->isVolatile())
+ return false;
+ } else if (AtomicRMWInst *RMW = dyn_cast_or_null<AtomicRMWInst>(UseInst)) {
+ if (RMW->isVolatile())
+ return false;
+ } else if (AtomicCmpXchgInst *CAS
+ = dyn_cast_or_null<AtomicCmpXchgInst>(UseInst)) {
+ if (CAS->isVolatile())
+ return false;
}
if (!User->getType()->isPointerTy())
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-volatile.ll b/llvm/test/CodeGen/AMDGPU/promote-alloca-volatile.ll
new file mode 100644
index 00000000000..313cdf59301
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-volatile.ll
@@ -0,0 +1,26 @@
+; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-promote-alloca < %s | FileCheck %s
+
+; CHECK-LABEL: @volatile_load(
+; CHECK: alloca [5 x i32]
+; CHECK load volatile i32, i32*
+define void @volatile_load(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
+entry:
+ %stack = alloca [5 x i32], align 4
+ %tmp = load i32, i32 addrspace(1)* %in, align 4
+ %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %tmp
+ %load = load volatile i32, i32* %arrayidx1
+ store i32 %load, i32 addrspace(1)* %out
+ ret void
+}
+
+; CHECK-LABEL: @volatile_store(
+; CHECK: alloca [5 x i32]
+; CHECK store volatile i32 %tmp, i32*
+define void @volatile_store(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
+entry:
+ %stack = alloca [5 x i32], align 4
+ %tmp = load i32, i32 addrspace(1)* %in, align 4
+ %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %tmp
+ store volatile i32 %tmp, i32* %arrayidx1
+ ret void
+}
OpenPOWER on IntegriCloud