Juan Manuel Martinez =?utf-8?q?Caamaño?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Juan Manuel Martinez Caamaño (jmmartinez)

<details>
<summary>Changes</summary>

Allows for type checking depending on the built-in signature.

This introduces some subtle changes in code generation: before, since
the signature was meaningless, we would accept any pointer type without
casting. After this change, the pointer of the `atomicrmw` matches the
flat address space.

---
Full diff: https://github.com/llvm/llvm-project/pull/173381.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+2-2) 
- (modified) clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl (+2-2) 
- (added) clang/test/SemaHIP/amdgpu-flat-atomic-fadd-err.hip (+29) 


``````````diff
diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 88b306462a92c..2623bd476f08f 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -272,14 +272,14 @@ TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2f16, 
"V2hV2h*1V2h", "t", "a
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fmin_f64, "dd*1d", "t", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fmax_f64, "dd*1d", "t", 
"gfx90a-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f64, "dd*0d", "t", 
"gfx90a-insts")
+TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f64, "dd*0d", "", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fmin_f64, "dd*0d", "t", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fmax_f64, "dd*0d", "t", 
"gfx90a-insts")
 
 TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f64, "dd*3d", "", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f32, "ff*3f", "", "gfx8-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f32, "ff*0f", "t", 
"gfx940-insts")
+TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f32, "ff*0f", "", 
"gfx940-insts")
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2f16, "V2hV2h*0V2h", "t", 
"atomic-flat-pk-add-16-insts")
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2bf16, "V2sV2s*0V2s", "t", 
"atomic-flat-pk-add-16-insts")
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2bf16, "V2sV2s*1V2s", "t", 
"atomic-global-pk-add-bf16-inst")
diff --git a/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl 
b/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
index ef97d12afab1d..8b10e544c71c4 100644
--- a/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
+++ b/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
@@ -47,7 +47,7 @@ void test_global_max_f64(__global double *addr, double x){
 }
 
 // CHECK-LABEL: test_flat_add_local_f64
-// CHECK: = atomicrmw fadd ptr addrspace(3) %{{.+}}, double %{{.+}} 
syncscope("agent") monotonic, align 8{{$}}
+// CHECK: = atomicrmw fadd ptr %{{.+}}, double %{{.+}} syncscope("agent") 
monotonic, align 8, !amdgpu.no.fine.grained.memory !{{[0-9]+$}}
 
 // GFX90A-LABEL:  test_flat_add_local_f64$local
 // GFX90A:  ds_add_rtn_f64
@@ -57,7 +57,7 @@ void test_flat_add_local_f64(__local double *addr, double x){
 }
 
 // CHECK-LABEL: test_flat_global_add_f64
-// CHECK: = atomicrmw fadd ptr addrspace(1) {{.+}}, double %{{.+}} 
syncscope("agent") monotonic, align 8, !amdgpu.no.fine.grained.memory 
!{{[0-9]+$}}
+// CHECK: = atomicrmw fadd ptr {{.+}}, double %{{.+}} syncscope("agent") 
monotonic, align 8, !amdgpu.no.fine.grained.memory !{{[0-9]+$}}
 
 // GFX90A-LABEL:  test_flat_global_add_f64$local
 // GFX90A:  global_atomic_add_f64
diff --git a/clang/test/SemaHIP/amdgpu-flat-atomic-fadd-err.hip 
b/clang/test/SemaHIP/amdgpu-flat-atomic-fadd-err.hip
new file mode 100644
index 0000000000000..1438b69d82719
--- /dev/null
+++ b/clang/test/SemaHIP/amdgpu-flat-atomic-fadd-err.hip
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -triple amdgcn -target-cpu gfx942 -verify %s 
-fcuda-is-device
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64 -aux-triple amdgcn -verify %s
+
+#define __device__ __attribute__((device))
+#define __shared__ __attribute__((shared))
+
+__device__ void test_flat_atomic_fadd_f32_valid(float *ptr, float val) {
+  float result;
+  result = __builtin_amdgcn_flat_atomic_fadd_f32(ptr, val);
+}
+
+__device__ void test_flat_atomic_fadd_f32_errors(float *ptr, float val,
+                                                double *ptr_d) {
+  float result;
+  result = __builtin_amdgcn_flat_atomic_fadd_f32(ptr, val, 0); // 
expected-error{{too many arguments to function call, expected 2, have 3}}
+  result = __builtin_amdgcn_flat_atomic_fadd_f32(ptr_d, val); // 
expected-error{{cannot initialize a parameter of type}}
+}
+
+__device__ void test_flat_atomic_fadd_f64_valid(double *ptr, double val) {
+  double result;
+  result = __builtin_amdgcn_flat_atomic_fadd_f64(ptr, val);
+}
+
+__device__ void test_flat_atomic_fadd_f64_errors(double *ptr, double val,
+                                                float *ptr_f) {
+  double result;
+  result = __builtin_amdgcn_flat_atomic_fadd_f64(ptr, val, 0); // 
expected-error{{too many arguments to function call, expected 2, have 3}}
+  result = __builtin_amdgcn_flat_atomic_fadd_f64(ptr_f, val); // 
expected-error{{cannot initialize a parameter of type}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/173381
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to