Skip to content

AMDGPU: Fix libcall recognition of image array types #119832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Dec 13, 2024

Add tests with get_image_width as a sample for all of the non-extension
image types. The transform doesn't do anything, but this runs through
all the mangled libfunc parsing and shows it does not crash. It would
probably be smarter to check for exact match of the types, rather than
checking the prefix.

Copy link
Contributor Author

arsenm commented Dec 13, 2024

@arsenm arsenm marked this pull request as ready for review December 13, 2024 07:34
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Dec 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 13, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

Add tests with get_image_width as a sample for all of the non-extension
image types. The transform doesn't do anything, but this runs through
all the mangled libfunc parsing and shows it does not crash. It would
probably be smarter to check for exact match of the types, rather than
checking the prefix.


Patch is 22.04 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119832.diff

3 Files Affected:

  • (modified) clang/test/CodeGenOpenCL/opencl_types.cl (+78)
  • (modified) llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp (+3-3)
  • (modified) llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-image-function-signatures.ll (+316-40)
diff --git a/clang/test/CodeGenOpenCL/opencl_types.cl b/clang/test/CodeGenOpenCL/opencl_types.cl
index eb68ab850744a4..aac3492b7a9e8d 100644
--- a/clang/test/CodeGenOpenCL/opencl_types.cl
+++ b/clang/test/CodeGenOpenCL/opencl_types.cl
@@ -73,3 +73,81 @@ kernel void foo_wo_pipe(write_only pipe int p) {}
 void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {}
 // CHECK-SPIR-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}}
 // CHECK-AMDGCN-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}}(ptr addrspace(4){{.*}}ptr addrspace(4){{.*}}ptr addrspace(4){{.*}})
+
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test20ocl_image1d_array_ro(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_only image1d_array_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test20ocl_image1d_array_wo(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(write_only image1d_array_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test20ocl_image1d_array_rw(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_write image1d_array_t img) {}
+
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test21ocl_image1d_buffer_ro(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_only image1d_buffer_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test21ocl_image1d_buffer_wo(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(write_only image1d_buffer_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test21ocl_image1d_buffer_rw(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_write image1d_buffer_t img) {}
+
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test20ocl_image2d_array_ro(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_only image2d_array_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test20ocl_image2d_array_wo(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(write_only image2d_array_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test20ocl_image2d_array_rw(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_write image2d_array_t img) {}
+
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image1d_ro(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_only image1d_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image1d_wo(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(write_only image1d_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image1d_rw(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_write image1d_t img) {}
+
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image2d_ro(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_only image2d_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image2d_wo(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(write_only image2d_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image2d_rw(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_write image2d_t img) {}
+
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image3d_ro(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_only image3d_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image3d_wo(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(write_only image3d_t img) {}
+
+// CHECK-AMDGCN: define dso_local void @_Z20img_type_mangle_test14ocl_image3d_rw(ptr addrspace(4) %img)
+__attribute__((overloadable))
+void img_type_mangle_test(read_write image3d_t img) {}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
index 64db58be032def..9f192a9d50c318 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
@@ -622,9 +622,9 @@ bool ItaniumParamParser::parseItaniumParam(StringRef& param,
   if (isDigit(TC)) {
     res.ArgType =
         StringSwitch<AMDGPULibFunc::EType>(eatLengthPrefixedName(param))
-            .Case("ocl_image1darray", AMDGPULibFunc::IMG1DA)
-            .Case("ocl_image1dbuffer", AMDGPULibFunc::IMG1DB)
-            .Case("ocl_image2darray", AMDGPULibFunc::IMG2DA)
+            .StartsWith("ocl_image1d_array", AMDGPULibFunc::IMG1DA)
+            .StartsWith("ocl_image1d_buffer", AMDGPULibFunc::IMG1DB)
+            .StartsWith("ocl_image2d_array", AMDGPULibFunc::IMG2DA)
             .StartsWith("ocl_image1d", AMDGPULibFunc::IMG1D)
             .StartsWith("ocl_image2d", AMDGPULibFunc::IMG2D)
             .StartsWith("ocl_image3d", AMDGPULibFunc::IMG3D)
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-image-function-signatures.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-image-function-signatures.ll
index ab06292e949948..c3bdf06b1447ed 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-image-function-signatures.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-image-function-signatures.ll
@@ -4,62 +4,338 @@
 ; Make sure we can produce a valid FunctionType for the expected
 ; signature of image functions.
 
-declare i32 @_Z16get_image_height20ocl_image2d_depth_rw(ptr addrspace(4))
+define i32 @test_get_image_width_ro_image1d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image1d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image1d_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image1d_ro(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image1d_ro(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_wo_image1d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image1d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image1d_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image1d_wo(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image1d_wo(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_rw_image1d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image1d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image1d_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image1d_rw(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image1d_rw(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_ro_image1d_buffer_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image1d_buffer_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width21ocl_image1d_buffer_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width21ocl_image1d_buffer_ro(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width21ocl_image1d_buffer_ro(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_wo_image1d_buffer_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image1d_buffer_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width21ocl_image1d_buffer_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width21ocl_image1d_buffer_wo(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width21ocl_image1d_buffer_wo(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_rw_image1d_buffer_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image1d_buffer_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width21ocl_image1d_buffer_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width21ocl_image1d_buffer_rw(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width21ocl_image1d_buffer_rw(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_ro_image2d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image2d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image2d_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image2d_ro(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image2d_ro(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_wo_image2d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image2d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image2d_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image2d_wo(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image2d_wo(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_rw_image2d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image2d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image2d_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image2d_rw(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image2d_rw(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_ro_image3d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image3d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image3d_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image3d_ro(ptr addrspace(4) %img)
+  ret i32 %call
+}
 
-define i32 @call_ocl_image2d_depth(ptr addrspace(4) %img) {
-; CHECK-LABEL: define i32 @call_ocl_image2d_depth(
-; CHECK-SAME: ptr addrspace(4) [[IMG:%.*]]) {
-; CHECK-NEXT:    [[RESULT:%.*]] = call i32 @_Z16get_image_height20ocl_image2d_depth_rw(ptr addrspace(4) [[IMG]])
-; CHECK-NEXT:    ret i32 [[RESULT]]
+declare i32 @_Z15get_image_width14ocl_image3d_ro(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_wo_image3d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image3d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image3d_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image3d_wo(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image3d_wo(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_rw_image3d_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image3d_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width14ocl_image3d_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width14ocl_image3d_rw(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width14ocl_image3d_rw(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_ro_image1d_array_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image1d_array_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image1d_array_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image1d_array_ro(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width20ocl_image1d_array_ro(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_wo_image1d_array_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image1d_array_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image1d_array_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image1d_array_wo(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width20ocl_image1d_array_wo(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_rw_image1d_array_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image1d_array_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image1d_array_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image1d_array_rw(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width20ocl_image1d_array_rw(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_ro_image2d_array_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image2d_array_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image2d_array_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image2d_array_ro(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width20ocl_image2d_array_ro(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_wo_image2d_array_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image2d_array_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image2d_array_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image2d_array_wo(ptr addrspace(4) %img)
+  ret i32 %call
+}
+
+declare i32 @_Z15get_image_width20ocl_image2d_array_wo(ptr addrspace(4)) #1
+
+define i32 @test_get_image_width_rw_image2d_array_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image2d_array_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image2d_array_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
 ;
-  %result = call i32 @_Z16get_image_height20ocl_image2d_depth_rw(ptr addrspace(4) %img)
-  ret i32 %result
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image2d_array_rw(ptr addrspace(4) %img)
+  ret i32 %call
 }
 
-declare i32 @_Z15get_image_width14ocl_image3d_ro(ptr addrspace(4))
+declare i32 @_Z15get_image_width20ocl_image2d_array_rw(ptr addrspace(4)) #1
 
-define i32 @call_ocl_image3d_depth(ptr addrspace(4) %img) {
-; CHECK-LABEL: define i32 @call_ocl_image3d_depth(
-; CHECK-SAME: ptr addrspace(4) [[IMG:%.*]]) {
-; CHECK-NEXT:    [[RESULT:%.*]] = call i32 @_Z15get_image_width14ocl_image3d_ro(ptr addrspace(4) [[IMG]])
-; CHECK-NEXT:    ret i32 [[RESULT]]
+define i32 @test_get_image_width_ro_image2d_depth_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_ro_image2d_depth_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image2d_depth_ro(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
 ;
-  %result = call i32 @_Z15get_image_width14ocl_image3d_ro(ptr addrspace(4) %img)
-  ret i32 %result
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image2d_depth_ro(ptr addrspace(4) %img)
+  ret i32 %call
 }
 
-declare i32 @_Z15get_image_width14ocl_image1d_ro(ptr addrspace(4))
+declare i32 @_Z15get_image_width20ocl_image2d_depth_ro(ptr addrspace(4)) #1
 
-define i32 @call_get_image_width14ocl_image1d_ro(ptr addrspace(4) %img) {
-; CHECK-LABEL: define i32 @call_get_image_width14ocl_image1d_ro(
-; CHECK-SAME: ptr addrspace(4) [[IMG:%.*]]) {
-; CHECK-NEXT:    [[RESULT:%.*]] = call i32 @_Z15get_image_width14ocl_image1d_ro(ptr addrspace(4) [[IMG]])
-; CHECK-NEXT:    ret i32 [[RESULT]]
+define i32 @test_get_image_width_wo_image2d_depth_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_wo_image2d_depth_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image2d_depth_wo(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
 ;
-  %result = call i32 @_Z15get_image_width14ocl_image1d_ro(ptr addrspace(4) %img)
-  ret i32 %result
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image2d_depth_wo(ptr addrspace(4) %img)
+  ret i32 %call
 }
 
-declare <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(ptr addrspace(4))
+declare i32 @_Z15get_image_width20ocl_image2d_depth_wo(ptr addrspace(4)) #1
 
-define <2 x i32> @call_Z13get_image_dim20ocl_image2d_array_ro(ptr addrspace(4) %img) {
-; CHECK-LABEL: define <2 x i32> @call_Z13get_image_dim20ocl_image2d_array_ro(
-; CHECK-SAME: ptr addrspace(4) [[IMG:%.*]]) {
-; CHECK-NEXT:    [[RESULT:%.*]] = call <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(ptr addrspace(4) [[IMG]])
-; CHECK-NEXT:    ret <2 x i32> [[RESULT]]
+define i32 @test_get_image_width_rw_image2d_depth_t(ptr addrspace(4) readnone %img) {
+; CHECK-LABEL: define i32 @test_get_image_width_rw_image2d_depth_t(
+; CHECK-SAME: ptr addrspace(4) readnone [[IMG:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @_Z15get_image_width20ocl_image2d_depth_rw(ptr addrspace(4) [[IMG]])
+; CHECK-NEXT:    ret i32 [[CALL]]
 ;
-  %result = call <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(ptr addrspace(4) %img)
-  ret <2 x i32> %result
+entry:
+  %call = tail call i32 @_Z15get_image_width20ocl_image2d_depth_rw(ptr addrspace(4) %img)
+  ret i32 %call
 }
 
-declare i32 @_Z15get_image_width20ocl_image1d_array_ro(ptr addrspace(4))
+declare i32 @_Z15get_image_width20ocl_image2d_depth_rw(ptr addrspace(4)) #1
 
-define i32 @call_Z15get_image_width20ocl_image1d_array_ro(ptr addrspace(4) %img) {
-; CHECK-LABEL: define i32 @call_Z15get_image_width20ocl_image1d_array_ro(
-; CHECK-SAME: ptr addrspace(4) [[IMG:%.*]]) {
-; CHECK-NEXT:    [[RESULT:%.*]] = call i32 @_Z1...
[truncated]

Copy link
Contributor Author

arsenm commented Dec 16, 2024

Merge activity

  • Dec 16, 12:57 AM EST: A user started a stack merge that includes this pull request via Graphite.
  • Dec 16, 1:02 AM EST: Graphite rebased this pull request as part of a merge.
  • Dec 16, 1:04 AM EST: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/amdgpu-simplify-libcall-verify-signature branch from 01db72e to 8f52a2f Compare December 16, 2024 05:58
.Case("ocl_image2darray", AMDGPULibFunc::IMG2DA)
.StartsWith("ocl_image1d_array", AMDGPULibFunc::IMG1DA)
.StartsWith("ocl_image1d_buffer", AMDGPULibFunc::IMG1DB)
.StartsWith("ocl_image2d_array", AMDGPULibFunc::IMG2DA)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this change also fix the mangling generated in getItaniumTypeName?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that does anything today. I don't think we actually have any transforms on these image cases. Either way, that code is more broken since it already isn't refining the ro/wo/rw type variants

Base automatically changed from users/arsenm/amdgpu-simplify-libcall-verify-signature to main December 16, 2024 06:01
Add tests with get_image_width as a sample for all of the non-extension
image types. The transform doesn't do anything, but this runs through
all the mangled libfunc parsing and shows it does not crash. It would
probably be smarter to check for exact match of the types, rather than
checking the prefix.
@arsenm arsenm force-pushed the users/arsenm/amdgpu-libfunc-ocl-image-array-names branch from 7543aca to 79687ef Compare December 16, 2024 06:02
@arsenm arsenm merged commit 1100d6a into main Dec 16, 2024
5 of 8 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu-libfunc-ocl-image-array-names branch December 16, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants