summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2016-03-17 16:21:59 +0000
committerNicolai Haehnle <nhaehnle@gmail.com>2016-03-17 16:21:59 +0000
commit79cad857a0e8fddccad46fcbc81c0ea66da7cfb7 (patch)
tree49cb5a2a7a28089e9dcfbf3243af8343da62dc3e
parentf8bff1c31c257abb760f08ef30f70205bc4b41f5 (diff)
downloadbcm5719-llvm-79cad857a0e8fddccad46fcbc81c0ea66da7cfb7.tar.gz
bcm5719-llvm-79cad857a0e8fddccad46fcbc81c0ea66da7cfb7.zip
AMDGPU: mark atomic instructions as sources of divergence
Summary: As explained by the comment, threads will typically see different values returned by atomic instructions even if the arguments are equal. Reviewers: arsenm, tstellarAMD Subscribers: arsenm, llvm-commits Differential Revision: http://reviews.llvm.org/D18156 llvm-svn: 263719
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp7
-rw-r--r--llvm/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll15
2 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
index 540ca5f399f..ff5558bf4db 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
@@ -186,6 +186,13 @@ bool AMDGPUTTIImpl::isSourceOfDivergence(const Value *V) const {
if (const LoadInst *Load = dyn_cast<LoadInst>(V))
return Load->getPointerAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
+ // Atomics are divergent because they are executed sequentially: when an
+ // atomic operation refers to the same address in each thread, then each
+ // thread after the first sees the value written by the previous thread as
+ // original value.
+ if (isa<AtomicRMWInst>(V) || isa<AtomicCmpXchgInst>(V))
+ return true;
+
if (const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V)) {
const TargetMachine &TM = getTLI()->getTargetMachine();
return isIntrinsicSourceOfDivergence(TM.getIntrinsicInfo(), Intrinsic);
diff --git a/llvm/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll b/llvm/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll
new file mode 100644
index 00000000000..60d0de6035b
--- /dev/null
+++ b/llvm/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll
@@ -0,0 +1,15 @@
+; RUN: opt -mtriple=amdgcn-- -analyze -divergence %s | FileCheck %s
+
+; CHECK: DIVERGENT: %orig = atomicrmw xchg i32* %ptr, i32 %val seq_cst
+define i32 @test1(i32* %ptr, i32 %val) #0 {
+ %orig = atomicrmw xchg i32* %ptr, i32 %val seq_cst
+ ret i32 %orig
+}
+
+; CHECK: DIVERGENT: %orig = cmpxchg i32* %ptr, i32 %cmp, i32 %new seq_cst seq_cst
+define {i32, i1} @test2(i32* %ptr, i32 %cmp, i32 %new) {
+ %orig = cmpxchg i32* %ptr, i32 %cmp, i32 %new seq_cst seq_cst
+ ret {i32, i1} %orig
+}
+
+attributes #0 = { "ShaderType"="0" }
OpenPOWER on IntegriCloud