Skip to content

Conversation

jofrn
Copy link
Contributor

@jofrn jofrn commented Sep 8, 2025

The chain calling convention is invalid in particular situations like being on an architecture it cannot compile to.

…lar situations like being on an architecture it cannot compile to.
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-llvm-ir

Author: None (jofrn)

Changes

The chain calling convention is invalid in particular situations like being on an architecture it cannot compile to.


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

2 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+8-2)
  • (added) llvm/test/CodeGen/AMDGPU/amdgpu-cs-chain-invalid-arch.ll (+6)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 1d3c379f461fa..63ae083fec8e8 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2938,10 +2938,16 @@ void Verifier::visitFunction(const Function &F) {
           "Calling convention parameter requires byval", &F);
     break;
   }
-  case CallingConv::AMDGPU_KERNEL:
-  case CallingConv::SPIR_KERNEL:
   case CallingConv::AMDGPU_CS_Chain:
   case CallingConv::AMDGPU_CS_ChainPreserve:
+  {
+    auto TT = M.getTargetTriple().str();
+    if (TT.find("gfx1200") || TT.find("gfx942"))
+      Check(false, "Chain calling convention is invalid on this target", &F);
+  }
+    [[fallthrough]];
+  case CallingConv::AMDGPU_KERNEL:
+  case CallingConv::SPIR_KERNEL:
     Check(F.getReturnType()->isVoidTy(),
           "Calling convention requires void return type", &F);
     [[fallthrough]];
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-cs-chain-invalid-arch.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-cs-chain-invalid-arch.ll
new file mode 100644
index 0000000000000..c6f8a09eaf5b6
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-cs-chain-invalid-arch.ll
@@ -0,0 +1,6 @@
+; RUN: not llc -mtriple=amdgcn -mcpu=gfx1200 -o - < %s 2>&1 | FileCheck %s
+
+define amdgpu_cs_chain void @test_alloca() {
+; CHECK: Chain calling convention is invalid on this target
+  ret void
+}

@jayfoad jayfoad requested a review from rovka September 8, 2025 14:23
Copy link

github-actions bot commented Sep 8, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/IR/Verifier.cpp

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4f2aa4005..bf05113c8 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2933,8 +2933,7 @@ void Verifier::visitFunction(const Function &F) {
     break;
   }
   case CallingConv::AMDGPU_CS_Chain:
-  case CallingConv::AMDGPU_CS_ChainPreserve:
-  {
+  case CallingConv::AMDGPU_CS_ChainPreserve: {
     auto TT = M.getTargetTriple().str();
     if (TT.find("gfx1200") || TT.find("gfx942"))
       Check(false, "Chain calling convention is invalid on this target", &F);

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

You cannot rely on this subtarget check

; RUN: not llc -mtriple=amdgcn -mcpu=gfx1200 -o - < %s 2>&1 | FileCheck %s

define amdgpu_cs_chain void @test_alloca() {
; CHECK: Chain calling convention is invalid on this target
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just fix this restriction, this seems totally artificial

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#132711 fixes the restriction, but they mentioned that the IR is invalid for this architecture, so the PR was never approved.

Copy link
Contributor

Choose a reason for hiding this comment

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

I reject the notion that IR can be invalid for an architecture

case CallingConv::AMDGPU_CS_ChainPreserve:
{
auto TT = M.getTargetTriple().str();
if (TT.find("gfx1200") || TT.find("gfx942"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unacceptable. We should never do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What other way does one check for subtarget?

Copy link
Contributor

Choose a reason for hiding this comment

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

The IR verifier cannot and should not check for the subtarget. We cannot have subtarget dependent IR valid rules

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