AMDGPU: Fix incorrect selection of buffer atomic fadd
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 5 Jun 2020 17:57:29 +0000 (13:57 -0400)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 5 Jun 2020 18:34:15 +0000 (14:34 -0400)
There were additional standalone patterns for these nodes which were
missing the subtarget predicate.

llvm/lib/Target/AMDGPU/BUFInstructions.td
llvm/test/CodeGen/AMDGPU/fail-select-buffer-atomic-fadd.ll [new file with mode: 0644]

index 7d6a6b9..2e5188b 100644 (file)
@@ -1422,8 +1422,10 @@ multiclass BufferAtomicPatterns_NO_RTN<SDPatternOperator name, ValueType vt,
   >;
 }
 
+let SubtargetPredicate = HasAtomicFaddInsts in {
 defm : BufferAtomicPatterns_NO_RTN<SIbuffer_atomic_fadd, f32, "BUFFER_ATOMIC_ADD_F32">;
 defm : BufferAtomicPatterns_NO_RTN<SIbuffer_atomic_pk_fadd, v2f16, "BUFFER_ATOMIC_PK_ADD_F16">;
+}
 
 def : GCNPat<
   (SIbuffer_atomic_cmpswap
diff --git a/llvm/test/CodeGen/AMDGPU/fail-select-buffer-atomic-fadd.ll b/llvm/test/CodeGen/AMDGPU/fail-select-buffer-atomic-fadd.ll
new file mode 100644 (file)
index 0000000..e52fcc7
--- /dev/null
@@ -0,0 +1,19 @@
+; RUN: not --crash llc -march=amdgcn -mcpu=tahiti -o /dev/null %s 2>&1 | FileCheck -check-prefix=FAIL %s
+; RUN: not --crash llc -march=amdgcn -mcpu=hawaii -o /dev/null %s 2>&1 | FileCheck -check-prefix=FAIL %s
+; RUN: not --crash llc -march=amdgcn -mcpu=fiji -o /dev/null %s 2>&1 | FileCheck -check-prefix=FAIL %s
+; RUN: not --crash llc -march=amdgcn -mcpu=gfx900 -o /dev/null %s 2>&1 | FileCheck -check-prefix=FAIL %s
+; RUN: not --crash llc -march=amdgcn -mcpu=gfx1010 -o /dev/null %s 2>&1 | FileCheck -check-prefix=FAIL %s
+
+; Make sure selection of these intrinsics fails on targets that do not
+; have the instruction available.
+; FIXME: Should also really make sure the v2f16 version fails.
+
+; FAIL: LLVM ERROR: Cannot select: {{.+}}: ch = BUFFER_ATOMIC_FADD
+define amdgpu_cs void @atomic_fadd(<4 x i32> inreg %arg0) {
+  call void @llvm.amdgcn.buffer.atomic.fadd.f32(float 1.0, <4 x i32> %arg0, i32 0, i32 112, i1 false)
+  ret void
+}
+
+declare void @llvm.amdgcn.buffer.atomic.fadd.f32(float, <4 x i32>, i32, i32, i1 immarg) #0
+
+attributes #0 = { nounwind }