[llvm] [AMDGPU] Look up DefaultDepCtrEncoding instead of caching in global state (PR #227720)

Steffen Larsen via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 06:49:41 PDT 2026


https://github.com/steffenlarsen created https://github.com/llvm/llvm-project/pull/227720

This commit removes the static cache for DefaultDepCtrEncoding in AMDGPUBaseInfo.cpp and instead looks it up from the table when needed. This avoids potential issues when querying encoding on different subtargets.

>From bce88c992e870c9ffc46a9a9f116c488c73aa048 Mon Sep 17 00:00:00 2001
From: Steffen Holst Larsen <sholstla at amd.com>
Date: Wed, 30 Sep 2026 08:22:39 -0500
Subject: [PATCH] [AMDGPU] Look up DefaultDepCtrEncoding instead of caching in
 global state

This commit removes the static cache for DefaultDepCtrEncoding in
AMDGPUBaseInfo.cpp and instead looks it up from the table when needed.
This avoids potential issues when querying encoding on different
subtargets.

Signed-off-by: Steffen Holst Larsen <sholstla at amd.com>
---
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp  |  5 +----
 llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index e45359719d6c9..4686c0eb70f3b 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -1941,10 +1941,7 @@ static int encodeCustomOperand(const CustomOperandVal *Opr, int Size,
 namespace DepCtr {
 
 int getDefaultDepCtrEncoding(const MCSubtargetInfo &STI) {
-  static int Default = -1;
-  if (Default == -1)
-    Default = getDefaultCustomOperandEncoding(DepCtrInfo, DEP_CTR_SIZE, STI);
-  return Default;
+  return getDefaultCustomOperandEncoding(DepCtrInfo, DEP_CTR_SIZE, STI);
 }
 
 bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal,
diff --git a/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp b/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp
index 51fda88e66eca..49b3f9e082b61 100644
--- a/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp
+++ b/llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp
@@ -10,6 +10,7 @@
 #include "AMDGPUGenSubtargetInfo.inc"
 #include "AMDGPUTargetMachine.h"
 #include "GCNSubtarget.h"
+#include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/TargetParser/AMDGPUTargetParser.h"
@@ -356,6 +357,21 @@ TEST_F(AMDGPUTestBase, TestReverseComposeSubRegIndices) {
   }
 }
 
+TEST_F(AMDGPUTestBase, TestDefaultDepCtrEncodingPerSubtarget) {
+  auto TM1010 = createAMDGPUTargetMachine(
+      Triple(Triple::amdgpu, Triple::AMDGPUSubArch1010), "", "");
+  auto TM1030 = createAMDGPUTargetMachine(
+      Triple(Triple::amdgpu, Triple::AMDGPUSubArch1030), "", "");
+  if (!TM1010 || !TM1030)
+    return;
+  const MCSubtargetInfo &STI1010 = TM1010->getMCSubtargetInfo();
+  const MCSubtargetInfo &STI1030 = TM1030->getMCSubtargetInfo();
+
+  EXPECT_EQ(AMDGPU::DepCtr::getDefaultDepCtrEncoding(STI1010), 0xff1f);
+  EXPECT_EQ(AMDGPU::DepCtr::getDefaultDepCtrEncoding(STI1030), 0xff9f);
+  EXPECT_EQ(AMDGPU::DepCtr::getDefaultDepCtrEncoding(STI1010), 0xff1f);
+}
+
 TEST_F(AMDGPUTestBase, TestGetNamedOperandIdx) {
   std::unique_ptr<const GCNTargetMachine> TM =
       createAMDGPUTargetMachine(Triple("amdgpu9.00-amd-"), "", "");



More information about the llvm-commits mailing list