Skip to content

AMDGPU: Warn if trying to codegen without a subarch - #220245

Merged
arsenm merged 1 commit into
mainfrom
users/arsenm/amdgpu/warn-no-subarch
Sep 5, 2026
Merged

arsenm merged 1 commit into
mainfrom
users/arsenm/amdgpu/warn-no-subarch

Conversation

@arsenm

@arsenm arsenm commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Warn if using the legacy amdgcn name, or amdgpu without a
specified subarch. This is to push all the non-clang frontends
to update to the new system, but this should turn into an error
in the next release.

Co-authored-by: Claude (Opus 4.8) [email protected]

Warn if using the legacy amdgcn name, or amdgpu without a
specified subarch. This is to push all the non-clang frontends
to update to the new system, but this should turn into an error
in the next release.

Co-authored-by: Claude (Opus 4.8) <[email protected]>

arsenm commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm
arsenm marked this pull request as ready for review September 1, 2026 13:20
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

Warn if using the legacy amdgcn name, or amdgpu without a
specified subarch. This is to push all the non-clang frontends
to update to the new system, but this should turn into an error
in the next release.

Co-authored-by: Claude (Opus 4.8) <[email protected]>


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp (+20-1)
  • (added) llvm/test/CodeGen/AMDGPU/codegen-no-subarch-warn.ll (+16)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 7afda107a59bc..f754fd8bd24f3 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -385,7 +385,26 @@ void AMDGPUAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
 }
 
 bool AMDGPUAsmPrinter::doInitialization(Module &M) {
-  const llvm::Triple &TT = M.getTargetTriple();
+  const Triple &TT = M.getTargetTriple();
+  if (TT.getSubArch() == Triple::NoSubArch) {
+    Triple::SubArchType SubArch =
+        AMDGPU::getSubArch(AMDGPU::parseArchAMDGCN(getGlobalSTI()->getCPU()));
+    if (SubArch != Triple::NoSubArch) {
+      Triple Fixed(TT);
+      Fixed.setArch(Triple::amdgpu, SubArch);
+      M.getContext().diagnose(DiagnosticInfoGeneric(
+          "codegen with no subarch in the target triple is deprecated and will "
+          "become an error; use the target triple '" +
+              Fixed.str() + "' instead",
+          DS_Warning));
+    } else {
+      M.getContext().diagnose(DiagnosticInfoGeneric(
+          "codegen with no subarch in the target triple is deprecated and will "
+          "become an error",
+          DS_Warning));
+    }
+  }
+
   CodeObjectVersion = AMDGPU::getAMDHSACodeObjectVersion(M);
 
   if (TT.getOS() == Triple::AMDHSA) {
diff --git a/llvm/test/CodeGen/AMDGPU/codegen-no-subarch-warn.ll b/llvm/test/CodeGen/AMDGPU/codegen-no-subarch-warn.ll
new file mode 100644
index 0000000000000..d8360decef9b0
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/codegen-no-subarch-warn.ll
@@ -0,0 +1,16 @@
+; A target triple with no subarch still codegens, but is deprecated. Check that
+; the warning fires and names the replacement triple derived from -mcpu.
+
+; RUN: llc -mtriple=amdgcn -mcpu=gfx900 -filetype=null %s 2>&1 | FileCheck %s
+; RUN: llc -mtriple=amdgpu -mcpu=gfx900 -filetype=null %s 2>&1 | FileCheck %s
+
+; Without -mcpu there is no subarch to suggest, so the warning omits a triple.
+; RUN: llc -mtriple=amdgcn -filetype=null %s 2>&1 | FileCheck -check-prefix=NOCPU %s
+
+; CHECK: warning: codegen with no subarch in the target triple is deprecated and will become an error; use the target triple 'amdgpu9.00--' instead{{$}}
+
+; NOCPU: warning: codegen with no subarch in the target triple is deprecated and will become an error{{$}}
+
+define amdgpu_kernel void @kernel() {
+  ret void
+}

@arsenm
arsenm merged commit 5eef528 into main Sep 5, 2026
16 checks passed
@arsenm
arsenm deleted the users/arsenm/amdgpu/warn-no-subarch branch September 5, 2026 16:20
addmisol pushed a commit to addmisol/llvm-project2 that referenced this pull request Sep 6, 2026
Warn if using the legacy amdgcn name, or amdgpu without a
specified subarch. This is to push all the non-clang frontends
to update to the new system, but this should turn into an error
in the next release.

Co-authored-by: Claude (Opus 4.8) <[email protected]>
vadimkotov pushed a commit to vadimkotov/llvm-project that referenced this pull request Sep 8, 2026
Warn if using the legacy amdgcn name, or amdgpu without a
specified subarch. This is to push all the non-clang frontends
to update to the new system, but this should turn into an error
in the next release.

Co-authored-by: Claude (Opus 4.8) <[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.

2 participants