Skip to content

[AMDGPU] Remove functions with incompatible gws attribute #78143

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
Jan 15, 2024
Merged

[AMDGPU] Remove functions with incompatible gws attribute #78143

merged 1 commit into from
Jan 15, 2024

Conversation

jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Jan 15, 2024

This change is to remove incompatible gws related functions
in order to make device-libs work correctly under -O0 for
gfx1200+

This change is to remove incompatible gws related functions
in order to make device-libs work correctly under -O0 for
gfx1200+
@llvmbot
Copy link
Member

llvmbot commented Jan 15, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Jay Foad (jayfoad)

Changes

This change is to remove incompatible gws related functions
in order to make device-libs work correctly under -O0 for
gfx1200+


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp (+2-1)
  • (added) llvm/test/CodeGen/AMDGPU/remove-incompatible-gws.ll (+54)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp b/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp
index 552380d54dfd09..6f1236fd3b7dae 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp
@@ -105,7 +105,8 @@ constexpr unsigned FeaturesToCheck[] = {AMDGPU::FeatureGFX11Insts,
                                         AMDGPU::FeatureDot8Insts,
                                         AMDGPU::FeatureExtendedImageInsts,
                                         AMDGPU::FeatureSMemRealTime,
-                                        AMDGPU::FeatureSMemTimeInst};
+                                        AMDGPU::FeatureSMemTimeInst,
+                                        AMDGPU::FeatureGWS};
 
 FeatureBitset expandImpliedFeatures(const FeatureBitset &Features) {
   FeatureBitset Result = Features;
diff --git a/llvm/test/CodeGen/AMDGPU/remove-incompatible-gws.ll b/llvm/test/CodeGen/AMDGPU/remove-incompatible-gws.ll
new file mode 100644
index 00000000000000..78ca923ddb0f0c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/remove-incompatible-gws.ll
@@ -0,0 +1,54 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -march=amdgcn -mcpu=gfx1030 -stop-after=amdgpu-remove-incompatible-functions\
+; RUN:   -pass-remarks=amdgpu-remove-incompatible-functions %s -o - 2>%t | FileCheck -check-prefixes=COMPATIBLE,IR %s
+; RUN: FileCheck -allow-empty --check-prefix=WARN-COMPATIBLE %s < %t
+; RUN: llc -march=amdgcn -mcpu=gfx1030 -verify-machineinstrs < %s
+
+; RUN: llc -march=amdgcn -mcpu=gfx1200 -stop-after=amdgpu-remove-incompatible-functions\
+; RUN:   -pass-remarks=amdgpu-remove-incompatible-functions %s -o - 2>%t | FileCheck -check-prefixes=INCOMPATIBLE,IR %s
+; RUN: FileCheck --check-prefixes=WARN-INCOMPATIBLE %s < %t
+; RUN: llc -march=amdgcn -mcpu=gfx1200 -verify-machineinstrs < %s
+
+; Note: This test checks the IR, but also has a run line to codegen the file just to check we
+; do not crash when trying to select those functions.
+
+; WARN-COMPATIBLE-NOT: removing function 'needs_gws':
+; WARN-INCOMPATIBLE:   removing function 'needs_gws': +gws is not supported on the current target
+
+
+; COMPATIBLE:       @GVRefs {{.*}} [ptr @needs_gws]
+; INCOMPATIBLE:     @GVRefs {{.*}} zeroinitializer
+@GVRefs = internal global [1 x ptr] [
+  ptr @needs_gws
+]
+
+
+; COMPATIBLE:         @ConstantExpr = internal global i64 ptrtoint (ptr @needs_gws to i64)
+; INCOMPATIBLE:       @ConstantExpr = internal global i64 0
+@ConstantExpr = internal global i64 ptrtoint (ptr @needs_gws to i64)
+
+
+; COMPATIBLE:         define void @needs_gws
+; INCOMPATIBLE-NOT:   define void @needs_gws
+define void @needs_gws(i32 %val0, i32 %val1) #0 {
+  call void @llvm.amdgcn.ds.gws.init(i32 %val0, i32 %val1)
+  call void @llvm.amdgcn.ds.gws.barrier(i32 %val0, i32 %val1)
+  ret void
+}
+
+; IR: define void @gws_caller(
+define void @gws_caller(i32 %val0, i32 %val1) {
+  ; COMPATIBLE: call void @needs_gws(
+  ; INCOMPATIBLE: call void null
+  call void @needs_gws(i32 %val0, i32 %val1)
+  ; IR: ret void
+  ret void
+}
+
+declare void @llvm.amdgcn.ds.gws.barrier(i32, i32) #1
+declare void @llvm.amdgcn.ds.gws.init(i32, i32) #2
+
+
+attributes #0 = { "target-features"="+gws"}
+attributes #1 = { convergent inaccessiblememonly nounwind }
+attributes #2 = { convergent inaccessiblememonly nounwind writeonly }

@jayfoad jayfoad merged commit f3d0788 into llvm:main Jan 15, 2024
@jayfoad jayfoad deleted the gfx12-incompatible-gws branch January 19, 2024 16:35
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
This change is to remove incompatible gws related functions
in order to make device-libs work correctly under -O0 for
gfx1200+

Co-authored-by: Changpeng Fang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants