[PATCH] D18156: AMDGPU: mark atomic instructions as sources of divergence

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 17 09:27:02 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL263719: AMDGPU: mark atomic instructions as sources of divergence (authored by nha).

Changed prior to commit:
  http://reviews.llvm.org/D18156?vs=50631&id=50945#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18156

Files:
  llvm/trunk/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
  llvm/trunk/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll

Index: llvm/trunk/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll
===================================================================
--- llvm/trunk/test/Analysis/DivergenceAnalysis/AMDGPU/atomics.ll
+++ llvm/trunk/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" }
Index: llvm/trunk/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
===================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
@@ -186,6 +186,13 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18156.50945.patch
Type: text/x-patch
Size: 1770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160317/e2a2ded7/attachment.bin>


More information about the llvm-commits mailing list