[llvm] 58bf038 - [NVPTX] Rewrite sm_110* to sm_101* as demanded by PTX version (#218968)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 08:13:47 PDT 2026


Author: Alex MacLean
Date: 2026-08-27T08:13:41-07:00
New Revision: 58bf0389cb2e27e1d81077e0183028c7e53b7d26

URL: https://github.com/llvm/llvm-project/commit/58bf0389cb2e27e1d81077e0183028c7e53b7d26
DIFF: https://github.com/llvm/llvm-project/commit/58bf0389cb2e27e1d81077e0183028c7e53b7d26.diff

LOG: [NVPTX] Rewrite sm_110* to sm_101* as demanded by PTX version (#218968)

Added: 
    llvm/test/CodeGen/NVPTX/sm-110-rename.ll

Modified: 
    llvm/lib/Target/NVPTX/NVPTXSubtarget.cpp
    llvm/lib/Target/NVPTX/NVPTXSubtarget.h
    llvm/test/CodeGen/NVPTX/sm-version.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTXSubtarget.cpp b/llvm/lib/Target/NVPTX/NVPTXSubtarget.cpp
index d271ea1710f05..3ce431dccf0f0 100644
--- a/llvm/lib/Target/NVPTX/NVPTXSubtarget.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXSubtarget.cpp
@@ -45,6 +45,12 @@ void NVPTXSubtarget::anchor() {}
 // Note: LLVM's minimum supported PTX version is 3.2 (see FeaturePTX in
 // NVPTX.td), so older SMs that supported earlier PTX versions instead use 3.2
 // as their effective minimum.
+//
+// Note: sm_110* is the PTX ISA 9.0 spelling of sm_101*, which was introduced in
+// PTX ISA 8.6 (sm_101f in 8.8) and renamed in 9.0. Since getTargetName()
+// rewrites the new spelling back to the old one when emitting older PTX, the
+// sm_110* names work with any PTX version that supported sm_101*, so they take
+// sm_101*'s minimum PTX version rather than the 9.0 of the rename.
 static unsigned minPTXVersion(NVPTX::GPUKind Arch) {
   switch (Arch) {
   case NVPTX::GK_NONE:
@@ -87,6 +93,8 @@ static unsigned minPTXVersion(NVPTX::GPUKind Arch) {
   case NVPTX::GK_SM_100a:
   case NVPTX::GK_SM_101:
   case NVPTX::GK_SM_101a:
+  case NVPTX::GK_SM_110:
+  case NVPTX::GK_SM_110a:
     return 86;
   case NVPTX::GK_SM_120:
   case NVPTX::GK_SM_120a:
@@ -96,15 +104,13 @@ static unsigned minPTXVersion(NVPTX::GPUKind Arch) {
   case NVPTX::GK_SM_103:
   case NVPTX::GK_SM_103f:
   case NVPTX::GK_SM_103a:
+  case NVPTX::GK_SM_110f:
   case NVPTX::GK_SM_120f:
   case NVPTX::GK_SM_121:
   case NVPTX::GK_SM_121f:
   case NVPTX::GK_SM_121a:
     return 88;
   case NVPTX::GK_SM_88:
-  case NVPTX::GK_SM_110:
-  case NVPTX::GK_SM_110f:
-  case NVPTX::GK_SM_110a:
     return 90;
   case NVPTX::GK_SM_107:
   case NVPTX::GK_SM_107f:
@@ -114,6 +120,24 @@ static unsigned minPTXVersion(NVPTX::GPUKind Arch) {
   llvm_unreachable("invalid NVPTX GPUKind");
 }
 
+StringRef NVPTXSubtarget::getTargetName() const {
+  // Spell sm_110* as sm_101* when emitting PTX older than 9.0, which does not
+  // know the new names. See the note above minPTXVersion().
+  if (!hasFeature(NVPTX::PTX90))
+    switch (Arch) {
+    case NVPTX::GK_SM_110:
+      return "sm_101";
+    case NVPTX::GK_SM_110f:
+      return "sm_101f";
+    case NVPTX::GK_SM_110a:
+      return "sm_101a";
+    default:
+      break;
+    }
+
+  return NVPTX::getArchName(Arch);
+}
+
 NVPTXSubtarget &NVPTXSubtarget::initializeSubtargetDependencies(StringRef CPU,
                                                                 StringRef FS) {
   // If the user did not provide a target we default to the `sm_75` target.

diff  --git a/llvm/lib/Target/NVPTX/NVPTXSubtarget.h b/llvm/lib/Target/NVPTX/NVPTXSubtarget.h
index b2f24c1d5d2b3..0d1d64cf73b83 100644
--- a/llvm/lib/Target/NVPTX/NVPTXSubtarget.h
+++ b/llvm/lib/Target/NVPTX/NVPTXSubtarget.h
@@ -198,7 +198,7 @@ class NVPTXSubtarget : public NVPTXGenSubtargetInfo {
   bool hasTargetName() const { return !getCPU().empty(); }
 
   // The architecture's name, which is what `.target` is emitted from.
-  StringRef getTargetName() const { return NVPTX::getArchName(Arch); }
+  StringRef getTargetName() const;
 
   bool hasNativeBF16Support(unsigned Opcode) const;
 

diff  --git a/llvm/test/CodeGen/NVPTX/sm-110-rename.ll b/llvm/test/CodeGen/NVPTX/sm-110-rename.ll
new file mode 100644
index 0000000000000..09cb7390c54f7
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/sm-110-rename.ll
@@ -0,0 +1,44 @@
+; PTX ISA 9.0 renamed sm_101, sm_101f and sm_101a to sm_110, sm_110f and
+; sm_110a. Naming one of these architectures with -mcpu emits `.target` with the
+; spelling the PTX version in use knows, so that the sm_110 names work on the PTX
+; versions predating the rename.
+
+; RUN: llc < %s -mcpu=sm_110 | FileCheck %s --check-prefix=SM101
+; RUN: llc < %s -mcpu=sm_110 -mattr=+ptx88 | FileCheck %s --check-prefix=SM101-PTX88
+; RUN: llc < %s -mcpu=sm_110 -mattr=+ptx90 | FileCheck %s --check-prefix=SM110
+
+; RUN: llc < %s -mcpu=sm_110f | FileCheck %s --check-prefix=SM101F
+; RUN: llc < %s -mcpu=sm_110f -mattr=+ptx90 | FileCheck %s --check-prefix=SM110F
+
+; RUN: llc < %s -mcpu=sm_110a | FileCheck %s --check-prefix=SM101A
+; RUN: llc < %s -mcpu=sm_110a -mattr=+ptx90 | FileCheck %s --check-prefix=SM110A
+
+; RUN: %if ptxas-sm_101 && ptxas-isa-8.6 %{ llc < %s -mcpu=sm_110 | %ptxas-verify -arch=sm_101 %}
+; RUN: %if ptxas-sm_110 && ptxas-isa-9.0 %{ llc < %s -mcpu=sm_110 -mattr=+ptx90 | %ptxas-verify -arch=sm_110 %}
+
+; SM101: .version 8.6
+; SM101: .target sm_101
+
+; SM101-PTX88: .version 8.8
+; SM101-PTX88: .target sm_101
+
+; SM110: .version 9.0
+; SM110: .target sm_110
+
+; SM101F: .version 8.8
+; SM101F: .target sm_101f
+
+; SM110F: .version 9.0
+; SM110F: .target sm_110f
+
+; SM101A: .version 8.6
+; SM101A: .target sm_101a
+
+; SM110A: .version 9.0
+; SM110A: .target sm_110a
+
+target triple = "nvptx64-nvidia-cuda"
+
+define void @foo() {
+  ret void
+}

diff  --git a/llvm/test/CodeGen/NVPTX/sm-version.ll b/llvm/test/CodeGen/NVPTX/sm-version.ll
index 6a8ff3b83fb69..8894b4fe301ef 100644
--- a/llvm/test/CodeGen/NVPTX/sm-version.ll
+++ b/llvm/test/CodeGen/NVPTX/sm-version.ll
@@ -111,9 +111,9 @@
 ; SM107: .version 9.4
 ; SM107a: .version 9.4
 ; SM107f: .version 9.4
-; SM110: .version 9.0
-; SM110a: .version 9.0
-; SM110f: .version 9.0
+; SM110: .version 8.6
+; SM110a: .version 8.6
+; SM110f: .version 8.8
 ; SM120: .version 8.7
 ; SM120a: .version 8.7
 ; SM120f: .version 8.8
@@ -152,9 +152,11 @@
 ; SM107: .target sm_107
 ; SM107a: .target sm_107a
 ; SM107f: .target sm_107f
-; SM110: .target sm_110
-; SM110a: .target sm_110a
-; SM110f: .target sm_110f
+; The sm_11x defaults predate the rename to that name, so they are spelled
+; sm_101x here. See sm-110-rename.ll.
+; SM110: .target sm_101
+; SM110a: .target sm_101a
+; SM110f: .target sm_101f
 ; SM120: .target sm_120
 ; SM120a: .target sm_120a
 ; SM120f: .target sm_120f


        


More information about the llvm-commits mailing list