OSDN Git Service

AMDGPU: Fix DAG divergence not reporting flat loads
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 4 Sep 2018 18:58:19 +0000 (18:58 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 4 Sep 2018 18:58:19 +0000 (18:58 +0000)
Match behavior in DAG of r340343

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341393 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/SIISelLowering.cpp
test/CodeGen/AMDGPU/dag-divergence.ll [new file with mode: 0644]

index 0028fe1..749a361 100644 (file)
@@ -9206,10 +9206,10 @@ bool SITargetLowering::isSDNodeSourceOfDivergence(const SDNode * N,
     }
     break;
     case ISD::LOAD: {
-      const LoadSDNode *L = dyn_cast<LoadSDNode>(N);
-      // FIXME: Also needs to handle flat.
-      if (L->getMemOperand()->getAddrSpace() == AMDGPUAS::PRIVATE_ADDRESS)
-        return true;
+      const LoadSDNode *L = cast<LoadSDNode>(N);
+      unsigned AS = L->getAddressSpace();
+      // A flat load may access private memory.
+      return AS == AMDGPUAS::PRIVATE_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS;
     } break;
     case ISD::CALLSEQ_END:
     return true;
diff --git a/test/CodeGen/AMDGPU/dag-divergence.ll b/test/CodeGen/AMDGPU/dag-divergence.ll
new file mode 100644 (file)
index 0000000..6694fda
--- /dev/null
@@ -0,0 +1,30 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=fiji -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
+
+; GCN-LABEL: {{^}}private_load_maybe_divergent:
+; GCN: buffer_load_dword
+; GCN-NOT: s_load_dword s
+; GCN: flat_load_dword
+; GCN-NOT: s_load_dword s
+define amdgpu_kernel void @private_load_maybe_divergent(i32 addrspace(4)* %k, i32* %flat) {
+  %load = load volatile i32, i32 addrspace(5)* undef, align 4
+  %gep = getelementptr inbounds i32, i32 addrspace(4)* %k, i32 %load
+  %maybe.not.uniform.load = load i32, i32 addrspace(4)* %gep, align 4
+  store i32 %maybe.not.uniform.load, i32 addrspace(1)* undef
+  ret void
+}
+
+; GCN-LABEL: {{^}}flat_load_maybe_divergent:
+; GCN: s_load_dwordx4
+; GCN-NOT: s_load
+; GCN: flat_load_dword
+; GCN-NOT: s_load
+; GCN: flat_load_dword
+; GCN-NOT: s_load
+; GCN: flat_store_dword
+define amdgpu_kernel void @flat_load_maybe_divergent(i32 addrspace(4)* %k, i32* %flat) {
+  %load = load i32, i32* %flat, align 4
+  %gep = getelementptr inbounds i32, i32 addrspace(4)* %k, i32 %load
+  %maybe.not.uniform.load = load i32, i32 addrspace(4)* %gep, align 4
+  store i32 %maybe.not.uniform.load, i32 addrspace(1)* undef
+  ret void
+}