[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-11-06 Thread Dan Zimmerman via cfe-commits

danzimm wrote:

Ping

https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-20 Thread Dan Zimmerman via cfe-commits

https://github.com/danzimm updated 
https://github.com/llvm/llvm-project/pull/228497

>From 1886b11f71735dcfe0ed742ac2f3b51427c38170 Mon Sep 17 00:00:00 2001
From: Dan Zimmerman 
Date: Tue, 8 Sep 2026 13:55:51 -0700
Subject: [PATCH 1/5] [AMDGPU] Add buffer_inv intrinsic and builtin

---
 clang/include/clang/Basic/BuiltinsAMDGPU.td   |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaAMDGPU.cpp | 13 +++
 .../builtins-amdgcn-buffer-inv.cl | 35 +++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  8 +
 .../AMDGPU/AMDGPURegBankLegalizeRules.cpp |  1 +
 llvm/lib/Target/AMDGPU/BUFInstructions.td |  1 +
 .../CodeGen/AMDGPU/llvm.amdgcn.buffer.inv.ll  | 22 
 .../Verifier/AMDGPU/llvm.amdgcn.buffer.inv.ll | 18 ++
 9 files changed, 102 insertions(+)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-amdgcn-buffer-inv.cl
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.buffer.inv.ll
 create mode 100644 llvm/test/Verifier/AMDGPU/llvm.amdgcn.buffer.inv.ll

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.td 
b/clang/include/clang/Basic/BuiltinsAMDGPU.td
index 34a1bd2d301a37..770f3af8d0e0fa 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.td
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.td
@@ -157,6 +157,7 @@ def __builtin_amdgcn_sched_group_barrier : 
AMDGPUBuiltin<"void(_Constant int, _C
 def __builtin_amdgcn_iglp_opt : AMDGPUBuiltin<"void(_Constant int)">;
 def __builtin_amdgcn_s_dcache_inv : AMDGPUBuiltin<"void()">;
 def __builtin_amdgcn_buffer_wbinvl1 : AMDGPUBuiltin<"void()">;
+def __builtin_amdgcn_buffer_inv : AMDGPUBuiltin<"void(_Constant int)", [], 
"buffer-inv-inst">;
 def __builtin_amdgcn_fence : AMDGPUBuiltin<"void(unsigned int, char const *, 
...)">;
 def __builtin_amdgcn_groupstaticsize : AMDGPUBuiltin<"unsigned int()">;
 def __builtin_amdgcn_wavefrontsize : AMDGPUBuiltin<"unsigned int()", [Const]>;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e6bdf2e7c41842..001689e849b7c1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -14437,6 +14437,9 @@ def note_amdgpu_named_barrier_reason_inherited : Note<
 // AMDGCN builtins diagnostics
 def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;
 def note_amdgcn_load_lds_size_valid_value : Note<"size must be %select{1, 2, 
or 4|1, 2, 4, 12 or 16}0">;
+def err_amdgcn_buffer_inv_invalid_cpol
+: Error<"argument to '__builtin_amdgcn_buffer_inv' must be a combination "
+"of the sc0 (1) and sc1 (16) cache-policy bits">;
 def err_invalid_sync_scope
 : Error<"unsupported atomic synchronization scope '%0'">;
 def err_amdgcn_processor_is_arg_not_literal
diff --git a/clang/lib/Sema/SemaAMDGPU.cpp b/clang/lib/Sema/SemaAMDGPU.cpp
index b1f6fa33649bd1..11472b1689f6c9 100644
--- a/clang/lib/Sema/SemaAMDGPU.cpp
+++ b/clang/lib/Sema/SemaAMDGPU.cpp
@@ -21,6 +21,7 @@
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/Sema.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -168,6 +169,18 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(const 
TargetInfo &TI,
   case AMDGPU::BI__builtin_amdgcn_s_setreg:
 return SemaRef.BuiltinConstantArgRange(TheCall, /*ArgNum=*/0, /*Low=*/0,
/*High=*/UINT16_MAX);
+  case AMDGPU::BI__builtin_amdgcn_buffer_inv: {
+llvm::APSInt CPol;
+if (SemaRef.BuiltinConstantArg(TheCall, /*ArgNum=*/0, CPol))
+  return true;
+
+// BUFFER_INV only supports the SC0 (1) and SC1 (16) cache-policy bits.
+if (!llvm::is_contained({0u, 1u, 16u, 17u}, CPol.getZExtValue()))
+  return Diag(TheCall->getArg(0)->getExprLoc(),
+  diag::err_amdgcn_buffer_inv_invalid_cpol)
+ << TheCall->getArg(0)->getSourceRange();
+return false;
+  }
   case AMDGPU::BI__builtin_amdgcn_s_wait_event: {
 llvm::APSInt Result;
 if (SemaRef.BuiltinConstantArg(TheCall, 0, Result))
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-buffer-inv.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-buffer-inv.cl
new file mode 100644
index 00..257a3649c751a4
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-buffer-inv.cl
@@ -0,0 +1,35 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu9.4-amd-amdhsa -DTEST_VALID 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu9.4-amd-amdhsa -DTEST_INVALID 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu9.0a-amd-amdhsa 
-DTEST_UNSUPPORTED -emit-llvm -o /dev/null -verify %s
+
+#ifdef TEST_VALID
+// CHECK-LABEL: @test_buffer_inv(
+// CHECK: call void @llvm.amdgcn.buffer.inv(i32 0)
+// CHECK: call void 

[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-19 Thread via cfe-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 163318 tests passed
* 5231 tests skipped
* 2 tests failed

## Failed Tests
(click on a test name to see its output)

### MemorySanitizer-Unit

MemorySanitizer-Unit._/Msan-x86_64-Test/MemorySanitizerOrigins/BinaryOp

```
Script:
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/lib/msan/tests/./Msan-x86_64-Test
 --gtest_filter=MemorySanitizerOrigins.BinaryOp
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:187
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin((void *)&t)), 
(origin))
  Actual: false
Expected: true

/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:4411
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin(z)), (oy))
  Actual: false
Expected: true

/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:187
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin((void *)&t)), 
(origin))
  Actual: false
Expected: true

/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:4411
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin(z)), (oy))
  Actual: false
Expected: true


```


MemorySanitizer-Unit._/Msan-x86_64-with-call-Test/MemorySanitizerOrigins/BinaryOp

```
Script:
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/lib/msan/tests/./Msan-x86_64-with-call-Test
 --gtest_filter=MemorySanitizerOrigins.BinaryOp
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:187
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin((void *)&t)), 
(origin))
  Actual: false
Expected: true

/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:4411
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin(z)), (oy))
  Actual: false
Expected: true

/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:187
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin((void *)&t)), 
(origin))
  Actual: false
Expected: true

/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/msan/tests/msan_test.cpp:4411
Value of: __msan_origin_is_descendant_or_same((__msan_get_origin(z)), (oy))
  Actual: false
Expected: true


```


If these failures are unrelated to your changes (for example tests are broken 
or flaky at HEAD), please open an issue at 
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.

https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-06 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5

arsenm wrote:

Old version 

https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-06 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm edited 
https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-06 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,35 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu9.4-amd-amdhsa -DTEST_VALID 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu9.4-amd-amdhsa -DTEST_INVALID 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgpu9.0a-amd-amdhsa 
-DTEST_UNSUPPORTED -emit-llvm -o /dev/null -verify %s

arsenm wrote:

The pure sema tests should go in test/SemaOpenCL

https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-06 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

It seems this instruction wasn't exactly "new" in gfx94*. It used to have a 
slightly different name, and had fewer control bits. This area seems to have a 
lot of churn, this has happened a few times with the flushes. Would you be 
better served by using an abstract fence instead? Here's the comparative 
codegen: 

```
┌┬─┬───┐
│Instruction │ Builtin 
│IR │
├┼─┼───┤
│ buffer_inv sc0 │ __builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "workgroup",   
│ fence syncscope("workgroup") acquire, !mmra !0 in │
│ (work-group)   │ "global") + tgsplit 
│  a function with "amdgpu-tg-split"│
├┼─┼───┤
│ buffer_inv sc1 │ __builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "agent",   
│ fence syncscope("agent") acquire, !mmra !0│
│ (agent)│ "global")   
│   │
├┼─┼───┤
│ buffer_inv sc0 sc1 │ __builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "", "global")  
│ fence acquire, !mmra !0   │
│  (system)  │ 
│   │
└┴─┴───┘

```

https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-06 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=amdgpu9.4-amd-amdhsa -verify-machineinstrs < %s | 
FileCheck --check-prefix=GFX94 %s
+; RUN: llc -mtriple=amdgpu9.4-amd-amdhsa -global-isel -global-isel-abort=1 
-verify-machineinstrs < %s | FileCheck --check-prefix=GFX94 %s
+; RUN: not llc -mtriple=amdgpu9.0a-amd-amdhsa -filetype=null < %s 2>&1 | 
FileCheck --check-prefix=GFX90A-ERR %s

arsenm wrote:

Don't need -verify-machineinstr or -global-isel-abort

https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-05 Thread Dan Zimmerman via cfe-commits

https://github.com/danzimm edited 
https://github.com/llvm/llvm-project/pull/228497
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-02 Thread Dan Zimmerman via cfe-commits

https://github.com/danzimm updated 
https://github.com/llvm/llvm-project/pull/228497

>From 7633649bf23094e0cb9b2f3159270c521477512d Mon Sep 17 00:00:00 2001
From: Dan Zimmerman 
Date: Wed, 23 Sep 2026 09:12:41 -0700
Subject: [PATCH 1/7] [AMDGPU] Add buffer_inv subtarget feature

---
 llvm/lib/Target/AMDGPU/AMDGPU.td |  8 +++-
 llvm/unittests/TargetParser/TargetParserTest.cpp | 12 
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index 90a0871ff3669..6b2c4bc27af98 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -510,6 +510,10 @@ defm GFX940Insts : AMDGPUSubtargetFeature<"gfx940-insts",
   /*GenPredicate=*/0
 >;
 
+defm BufferInvInst : AMDGPUSubtargetFeature<"buffer-inv-inst",
+  "Has buffer_inv instruction"
+>;
+
 defm Permlane16Insts : AMDGPUSubtargetFeature<"permlane16-insts",
   "Has v_permlane16_b32/v_permlanex16_b32 instructions"
 >;
@@ -2101,6 +2105,7 @@ def FeatureISAVersion9_4_Common : FeatureSet<
FeatureAGPRAlloc,
FeatureTgSplitSupport,
FeatureGFX940Insts,
+   FeatureBufferInvInst,
FeatureRequiresAlignedVGPRs,
FeatureFmaMixInsts,
FeatureDLInsts,
@@ -3357,7 +3362,8 @@ def AMDGPUFrontendVisibleFeatures {
   FeatureAtomicFaddRtnInsts, FeatureAtomicFlatPkAdd16Insts, 
FeatureAtomicGlobalPkAddBF16Inst,
   FeatureBF16ConversionInsts,
   FeatureBF16PackedInsts, FeatureBF16TransInsts, 
FeatureBF8ConversionScaleInsts,
-  FeatureBVHRayTracingInsts, FeatureBitOp3Insts, FeatureCIInsts,
+  FeatureBVHRayTracingInsts, FeatureBitOp3Insts, FeatureBufferInvInst,
+  FeatureCIInsts,
   FeatureClusters, FeatureCubeInsts, FeatureCvtPkNormVOP2Insts,
   FeatureCvtSrPkBF16F32Inst, FeatureDLInsts, FeatureDPP,
   FeatureDot10Insts, FeatureDot11Insts, FeatureDot12Insts,
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp 
b/llvm/unittests/TargetParser/TargetParserTest.cpp
index 78a13daac2867..6e0e469f75fd4 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -2877,6 +2877,18 @@ TEST(TargetParserTest, testAMDGPUgetFeatureBitset) {
   EXPECT_TRUE(Empty.empty());
 }
 
+TEST(TargetParserTest, testAMDGPUBufferInvInstFeature) {
+  auto Has = [](AMDGPU::GPUKind AK) {
+return AMDGPU::getFeatureBitset(AK).test(AMDGPU::FEAT_BUFFER_INV_INST);
+  };
+
+  EXPECT_FALSE(Has(AMDGPU::GK_GFX90A));
+  EXPECT_TRUE(Has(AMDGPU::GK_GFX942));
+  EXPECT_TRUE(Has(AMDGPU::GK_GFX950));
+  EXPECT_TRUE(Has(AMDGPU::GK_GFX9_4_GENERIC));
+  EXPECT_FALSE(Has(AMDGPU::GK_GFX1250));
+}
+
 TEST(TargetParserTest, testAMDGPUHalfAddressableLDSFeature) {
   auto Has = [](AMDGPU::GPUKind AK) {
 return AMDGPU::getFeatureBitset(AK).test(

>From cd9af185bd50a5e2d35f3a057117a5b6363b1028 Mon Sep 17 00:00:00 2001
From: Dan Zimmerman 
Date: Thu, 24 Sep 2026 10:20:47 -0700
Subject: [PATCH 2/7] [AMDGPU] Use BufferInvInst for buffer_inv predicates

---
 llvm/lib/Target/AMDGPU/BUFInstructions.td  |  8 +---
 llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s | 10 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s

diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td 
b/llvm/lib/Target/AMDGPU/BUFInstructions.td
index 057c0f103ce80..2b5d20c6849f7 100644
--- a/llvm/lib/Target/AMDGPU/BUFInstructions.td
+++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td
@@ -1429,7 +1429,7 @@ let SubtargetPredicate = HasAtomicFMinFMaxF64GlobalInsts 
in {
 }
 
 def BUFFER_INV : MUBUF_Invalidate<"buffer_inv"> {
-  let SubtargetPredicate = isGFX940Plus;
+  let SubtargetPredicate = HasBufferInvInst;
   let has_glc = 1;
   let has_sccb = 1;
   let InOperandList = (ins CPol_0:$cpol);
@@ -3660,10 +3660,12 @@ let AsmString = BUFFER_WBL2.Mnemonic, // drop flags
 defm BUFFER_WBL2  : MUBUF_Real_gfx90a<0x28>;
 defm BUFFER_INVL2 : MUBUF_Real_gfx90a<0x29>;
 
-let SubtargetPredicate = isGFX940Plus in {
+let SubtargetPredicate = isGFX940Plus in
 def BUFFER_WBL2_gfx940  : MUBUF_Real_gfx940<0x28, BUFFER_WBL2>;
+
+let SubtargetPredicate = HasBufferInvInst,
+AssemblerPredicate = HasBufferInvInst in
 def BUFFER_INV_gfx940   : MUBUF_Real_gfx940<0x29, BUFFER_INV>;
-}
 
 class MTBUF_Real_Base_vi  op, MTBUF_Pseudo ps, int Enc> :
   MTBUF_Real,
diff --git a/llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s 
b/llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s
new file mode 100644
index 0..52d7c4e5eed49
--- /dev/null
+++ b/llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s
@@ -0,0 +1,10 @@
+// RUN: llvm-mc -triple=amdgpu9.42 -show-encoding %s | FileCheck 
--check-prefix=SUPPORTED %s
+// RUN: llvm-mc -triple=amdgpu9.50 -show-encoding %s | FileCheck 
--check-prefix=SUPPORTED %s
+// RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx9-4-generic -show-encoding 
%s | FileCheck --check-prefix=SUPPORTED %s
+// RUN: not llvm-mc -triple=amdgpu9.0a -filetype=null %s 2>&1 | 

[clang] [llvm] [mlir] [AMDGPU] Introduce builtin, intrinsic and ROCDL instruction for buffer_inv (PR #228497)

2026-10-02 Thread Dan Zimmerman via cfe-commits

https://github.com/danzimm created 
https://github.com/llvm/llvm-project/pull/228497

Depends on https://github.com/llvm/llvm-project/pull/226254: The first 5 
commits are from that branch, this PR is the last 2 commits.

This PR was written with assistance by codex. I've audited and manually edited 
to make sure the PR is ready for review.


This PR is a second follow up to 
https://github.com/llvm/llvm-project/pull/221115, it exposes:
- `__builtin_amdgcn_buffer_inv(_Constant int)`; I added validation in 
SemaAMDGPU too
- `@llvm.amdgcn.buffer.inv(i32 immarg)`
- `rocdl.buffer.inv`

The lowering of `buffer_inv` was already implemented. Consequently defining a 
pattern on the pseudo was the only thing needed, outside of exposing the 
interface.

## Notes
- I implemented both the builtin and the intrinsic as there was ambiguity in 
https://github.com/llvm/llvm-project/pull/221115:
  - https://github.com/llvm/llvm-project/pull/221115#issuecomment-553703 
specifies `intrinsics like __builtin_amdgcn_buffer_wbinvl1` when suggesting a 
pattern to follow
- As I originally wanted to emit these instructions from triton, I also 
implemented the rocdl interface

>From a7f0eb06a85448adfc2292a3c67604279a359dce Mon Sep 17 00:00:00 2001
From: Dan Zimmerman 
Date: Wed, 23 Sep 2026 09:12:41 -0700
Subject: [PATCH 1/7] [AMDGPU] Add buffer_inv subtarget feature

---
 llvm/lib/Target/AMDGPU/AMDGPU.td |  8 +++-
 llvm/unittests/TargetParser/TargetParserTest.cpp | 12 
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index f96934e0b84349..e04bc53394577b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -510,6 +510,10 @@ defm GFX940Insts : AMDGPUSubtargetFeature<"gfx940-insts",
   /*GenPredicate=*/0
 >;
 
+defm BufferInvInst : AMDGPUSubtargetFeature<"buffer-inv-inst",
+  "Has buffer_inv instruction"
+>;
+
 defm Permlane16Insts : AMDGPUSubtargetFeature<"permlane16-insts",
   "Has v_permlane16_b32/v_permlanex16_b32 instructions"
 >;
@@ -2079,6 +2083,7 @@ def FeatureISAVersion9_4_Common : FeatureSet<
FeatureAGPRAlloc,
FeatureTgSplitSupport,
FeatureGFX940Insts,
+   FeatureBufferInvInst,
FeatureRequiresAlignedVGPRs,
FeatureFmaMixInsts,
FeatureDLInsts,
@@ -3324,7 +3329,8 @@ def AMDGPUFrontendVisibleFeatures {
   FeatureAtomicFaddRtnInsts, FeatureAtomicFlatPkAdd16Insts, 
FeatureAtomicGlobalPkAddBF16Inst,
   FeatureBF16ConversionInsts,
   FeatureBF16PackedInsts, FeatureBF16TransInsts, 
FeatureBF8ConversionScaleInsts,
-  FeatureBVHRayTracingInsts, FeatureBitOp3Insts, FeatureCIInsts,
+  FeatureBVHRayTracingInsts, FeatureBitOp3Insts, FeatureBufferInvInst,
+  FeatureCIInsts,
   FeatureClusters, FeatureCubeInsts, FeatureCvtPkNormVOP2Insts,
   FeatureCvtSrPkBF16F32Inst, FeatureDLInsts, FeatureDPP,
   FeatureDot10Insts, FeatureDot11Insts, FeatureDot12Insts,
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp 
b/llvm/unittests/TargetParser/TargetParserTest.cpp
index 62d6f3a4c955b4..2847942227df33 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -2875,6 +2875,18 @@ TEST(TargetParserTest, testAMDGPUgetFeatureBitset) {
   EXPECT_TRUE(Empty.empty());
 }
 
+TEST(TargetParserTest, testAMDGPUBufferInvInstFeature) {
+  auto Has = [](AMDGPU::GPUKind AK) {
+return AMDGPU::getFeatureBitset(AK).test(AMDGPU::FEAT_BUFFER_INV_INST);
+  };
+
+  EXPECT_FALSE(Has(AMDGPU::GK_GFX90A));
+  EXPECT_TRUE(Has(AMDGPU::GK_GFX942));
+  EXPECT_TRUE(Has(AMDGPU::GK_GFX950));
+  EXPECT_TRUE(Has(AMDGPU::GK_GFX9_4_GENERIC));
+  EXPECT_FALSE(Has(AMDGPU::GK_GFX1250));
+}
+
 TEST(TargetParserTest, testAMDGPUHalfAddressableLDSFeature) {
   auto Has = [](AMDGPU::GPUKind AK) {
 return AMDGPU::getFeatureBitset(AK).test(

>From 5a4808272dbfb15e7b38b88cee9f85614f9f6e73 Mon Sep 17 00:00:00 2001
From: Dan Zimmerman 
Date: Thu, 24 Sep 2026 10:20:47 -0700
Subject: [PATCH 2/7] [AMDGPU] Use BufferInvInst for buffer_inv predicates

---
 llvm/lib/Target/AMDGPU/BUFInstructions.td  |  8 +---
 llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s | 10 ++
 2 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/MC/AMDGPU/buffer-inv-subtarget-feature.s

diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td 
b/llvm/lib/Target/AMDGPU/BUFInstructions.td
index 057c0f103ce800..2b5d20c6849f78 100644
--- a/llvm/lib/Target/AMDGPU/BUFInstructions.td
+++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td
@@ -1429,7 +1429,7 @@ let SubtargetPredicate = HasAtomicFMinFMaxF64GlobalInsts 
in {
 }
 
 def BUFFER_INV : MUBUF_Invalidate<"buffer_inv"> {
-  let SubtargetPredicate = isGFX940Plus;
+  let SubtargetPredicate = HasBufferInvInst;
   let has_glc = 1;
   let has_sccb = 1;
   let InOperandList = (ins CPol_0:$cpol);
@@ -3660,10 +3660,12 @@ let AsmString = BUFFER_WBL2.Mnemonic, // drop flags
 defm BUFFER_WBL2  :