From 9d6797ae5804e4bf9a0a760d136d4b6a28b47b83 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 6 Jan 2015 19:52:07 +0000 Subject: [PATCH] R600/SI: Insert s_waitcnt before s_barrier instructions. This ensures that all memory operations are complete when all threads reach the barrier. llvm-svn: 225290 --- llvm/lib/Target/R600/SIInsertWaits.cpp | 6 +++++- llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.global.ll | 2 ++ llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.local.ll | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/R600/SIInsertWaits.cpp b/llvm/lib/Target/R600/SIInsertWaits.cpp index 2e56508e2fae..181b11643bf3 100644 --- a/llvm/lib/Target/R600/SIInsertWaits.cpp +++ b/llvm/lib/Target/R600/SIInsertWaits.cpp @@ -428,7 +428,11 @@ bool SIInsertWaits::runOnMachineFunction(MachineFunction &MF) { for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I) { - Changes |= insertWait(MBB, I, handleOperands(*I)); + // Wait for everything before a barrier. + if (I->getOpcode() == AMDGPU::S_BARRIER) + Changes |= insertWait(MBB, I, LastIssued); + else + Changes |= insertWait(MBB, I, handleOperands(*I)); pushInstruction(MBB, I); } diff --git a/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.global.ll b/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.global.ll index 31e170948a0a..a11d9ae7af08 100644 --- a/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.global.ll +++ b/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.global.ll @@ -3,6 +3,8 @@ ; FUNC-LABEL: {{^}}test_barrier_global: ; EG: GROUP_BARRIER +; SI: buffer_store_dword +; SI: s_waitcnt ; SI: s_barrier define void @test_barrier_global(i32 addrspace(1)* %out) { diff --git a/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.local.ll b/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.local.ll index 94b3cbc86eb0..76c2453d089f 100644 --- a/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.local.ll +++ b/llvm/test/CodeGen/R600/llvm.AMDGPU.barrier.local.ll @@ -3,6 +3,9 @@ ; FUNC-LABEL: {{^}}test_barrier_local: ; EG: GROUP_BARRIER + +; SI: buffer_store_dword +; SI: s_waitcnt ; SI: s_barrier define void @test_barrier_local(i32 addrspace(1)* %out) {