From dbc18f5acc3be34a739b81fb9e6473c21610cc83 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Fri, 3 Jun 2016 20:42:59 +0000 Subject: [PATCH] Merging r264214: ------------------------------------------------------------------------ r264214 | Matthew.Arsenault | 2016-03-23 16:17:29 -0700 (Wed, 23 Mar 2016) | 2 lines AMDGPU: Promote alloca should skip volatiles ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@271729 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp | 13 ++++++++++ .../CodeGen/AMDGPU/promote-alloca-volatile.ll | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/CodeGen/AMDGPU/promote-alloca-volatile.ll diff --git a/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp index 94db4fdce47..ae53f386242 100644 --- a/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp +++ b/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp @@ -301,9 +301,22 @@ static bool collectUsesWithPtrTypes(Value *Val, std::vector &WorkList) { return false; if (StoreInst *SI = dyn_cast_or_null(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(UseInst)) { + if (LI->isVolatile()) + return false; + } else if (AtomicRMWInst *RMW = dyn_cast_or_null(UseInst)) { + if (RMW->isVolatile()) + return false; + } else if (AtomicCmpXchgInst *CAS + = dyn_cast_or_null(UseInst)) { + if (CAS->isVolatile()) + return false; } if (!User->getType()->isPointerTy()) diff --git a/test/CodeGen/AMDGPU/promote-alloca-volatile.ll b/test/CodeGen/AMDGPU/promote-alloca-volatile.ll new file mode 100644 index 00000000000..313cdf59301 --- /dev/null +++ b/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 +} -- 2.50.1