[llvm] [AMDGPU][Draft] OOB mode - module flag (PR #160922)

Piotr Sobczak via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 09:38:09 PDT 2025


https://github.com/piotrAMD created https://github.com/llvm/llvm-project/pull/160922

Draft of a solution based on a module flag to replace the subtarget feature with module flag.

>From 59a853360c32552ad4b233cc698806a01f17b383 Mon Sep 17 00:00:00 2001
From: Piotr Sobczak <piotr.sobczak at amd.com>
Date: Fri, 26 Sep 2025 17:58:13 +0200
Subject: [PATCH] [AMDGPU][Draft] OOB mode - module flag

Draft of a solution based on a module flag to replace the subtarget
feature with module flag.
---
 llvm/lib/Target/AMDGPU/AMDGPU.td               |  6 ------
 llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 10 ++++++++++
 llvm/lib/Target/AMDGPU/GCNSubtarget.h          | 15 +++++++++++++--
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index eaa1870f4be28..d158a10c01738 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -128,12 +128,6 @@ def FeatureUnalignedDSAccess : SubtargetFeature<"unaligned-ds-access",
   "Hardware supports unaligned local and region loads and stores"
 >;
 
-def FeatureRelaxedBufferOOBMode : SubtargetFeature<"relaxed-buffer-oob-mode",
-  "RelaxedBufferOOBMode",
-  "true",
-  "Disable strict out-of-bounds buffer guarantees. An OOB access may potentially cause an adjacent access to be treated as if it were also OOB"
->;
-
 def FeatureApertureRegs : SubtargetFeature<"aperture-regs",
   "HasApertureRegs",
   "true",
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 92a587b5771b6..fdfc2f9a079f7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1095,6 +1095,15 @@ bool AMDGPUTargetMachine::splitModule(
   return true;
 }
 
+static unsigned getOOBModeFromModule(const Module *M) {
+  unsigned Mode = 0;
+  if (M)
+    if (Metadata *MD = M->getModuleFlag("amdgpu.oob.mode"))
+      if (auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
+        Mode = CI->getZExtValue();
+  return Mode;
+}
+
 //===----------------------------------------------------------------------===//
 // GCN Target Machine (SI+)
 //===----------------------------------------------------------------------===//
@@ -1125,6 +1134,7 @@ GCNTargetMachine::getSubtargetImpl(const Function &F) const {
   }
 
   I->setScalarizeGlobalBehavior(ScalarizeGlobal);
+  I->setOOBMode(getOOBModeFromModule(F.getParent()));
 
   return I.get();
 }
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index a54d6651c25c1..cf50a0c6d088b 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -78,7 +78,6 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   bool BackOffBarrier = false;
   bool UnalignedScratchAccess = false;
   bool UnalignedAccessMode = false;
-  bool RelaxedBufferOOBMode = false;
   bool HasApertureRegs = false;
   bool SupportsXNACK = false;
   bool KernargPreload = false;
@@ -291,6 +290,17 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   // Dummy feature to use for assembler in tablegen.
   bool FeatureDisable = false;
 
+  // Module flag features.
+
+  // Out-Of-Bounds mode flags.
+  // Setting a bit enables a relaxed mode that disables strict OOB guarantees;
+  // an out-of-bounds access may cause a neighboring in-bounds access to be
+  // treated as OOB.
+  // If bit is set, enable relaxed mode. 0 in a bit keeps the corresponding check strict.
+  // OOBMode{0} - untyped buffers (buffer_load)
+  // OOBMode{1} - typed buffers (tbuffer_load)
+  unsigned OOBMode = 0;
+
 private:
   SIInstrInfo InstrInfo;
   SITargetLowering TLInfo;
@@ -646,7 +656,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
     return UnalignedAccessMode;
   }
 
-  bool hasRelaxedBufferOOBMode() const { return RelaxedBufferOOBMode; }
+  bool hasRelaxedBufferOOBMode() const { return OOBMode == 1; // TODO: Use named const/enum.}
+  void setOOBMode(unsigned val) { OOBMode = val; }
 
   bool hasApertureRegs() const {
     return HasApertureRegs;



More information about the llvm-commits mailing list