[llvm] [AMDGPU][GFX12.5] Add support for emitting memory operations with nv bit set (PR #179413)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 3 05:45:40 PST 2026
https://github.com/Pierre-vh updated https://github.com/llvm/llvm-project/pull/179413
>From f7f55ebbb49660ea476fe5ae06db5f401605878f Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Fri, 23 Jan 2026 12:58:02 +0100
Subject: [PATCH 1/3] [AMDGPU][GFX12.5] Add support for emitting memory
operations with nv bit set
- Add & document `!amdgpu.non.volatile` metadata and a corresponding `MONonVolatile` MachineMemOperand flag.
- Set nv=1 on memory operations on GFX12.5 if the operation accesses a constant address space,
is an invariant load, or has the `MONonVolatile` flag set.
---
llvm/docs/AMDGPUUsage.rst | 23 +
llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 2 +
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 1 +
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 4 +
llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp | 61 +-
.../AMDGPU/memory-legalizer-non-volatile.ll | 564 ++++++++++++++++++
.../promote-constOffset-to-imm-gfx12.mir | 2 +-
7 files changed, 643 insertions(+), 14 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll
diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index cd5410a31b98f..d3717dcc00908 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -1878,6 +1878,29 @@ and
!0 = !{}
+.. _amdgpu_non_volatile:
+
+'``amdgpu.non.volatile``' Metadata
+----------------------------------
+
+Explicitly marks memory accesses (load, store, rmw) to locations that are never written to by other threads during the execution of the shader.
+
+This metadata is a performance optimization and can be dropped if necessary.
+Using this metadata on a memory access to a location that is written to by other threads is undefined behavior.
+
+Sets ``NV=1`` on the instruction if the target supports it.
+
+.. code-block:: llvm
+
+ %val = load i32, ptr %in, align 4, !amdgpu.non.volatile !{}
+
+
+.. note::
+
+ This metadata is used to request ``NV=1`` on an operation, but the compiler may also set ``NV=1``
+ on memory accesses that do not have the metadata when it is safe to do so. For example, it may
+ set it on accesses to constant memory, when loading from or storing to scratch memory used for
+ spills, etc.
LLVM IR Attributes
==================
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index b043d5354042d..3b17198593db9 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -19357,6 +19357,8 @@ SITargetLowering::getTargetMMOFlags(const Instruction &I) const {
Flags |= MONoClobber;
if (I.getMetadata("amdgpu.last.use"))
Flags |= MOLastUse;
+ if (I.getMetadata("amdgpu.non.volatile"))
+ Flags |= MONonVolatile;
return Flags;
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 09efba485f6f8..14dee6d1804d8 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -9897,6 +9897,7 @@ SIInstrInfo::getSerializableMachineMemOperandTargetFlags() const {
{MONoClobber, "amdgpu-noclobber"},
{MOLastUse, "amdgpu-last-use"},
{MOCooperative, "amdgpu-cooperative"},
+ {MONonVolatile, "amdgpu-non-volatile"},
};
return ArrayRef(TargetFlags);
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index 05cf804d08ffc..fe7365c6b7a66 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -52,6 +52,10 @@ static const MachineMemOperand::Flags MOLastUse =
static const MachineMemOperand::Flags MOCooperative =
MachineMemOperand::MOTargetFlag3;
+/// Mark the MMO of non-volatile memory operations.
+static const MachineMemOperand::Flags MONonVolatile =
+ MachineMemOperand::MOTargetFlag4;
+
/// Utility to store machine instructions worklist.
struct SIInstrWorklist {
SIInstrWorklist() = default;
diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
index c16aa3e8a0352..6ceb7f7045a98 100644
--- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
@@ -398,6 +398,10 @@ class SICacheControl {
bool IsCrossAddrSpaceOrdering,
Position Pos) const = 0;
+ /// Handle operations that are considered non-volatile.
+ /// See \ref isNonVolatileMemoryAccess
+ virtual bool handleNonVolatile(MachineInstr &MI) const { return false; }
+
/// Virtual destructor to allow derivations to be deleted.
virtual ~SICacheControl() = default;
};
@@ -555,6 +559,8 @@ class SIGfx12CacheControl final : public SICacheControl {
SIAtomicAddrSpace AddrSpace) const override {
return setAtomicScope(MI, Scope, AddrSpace);
}
+
+ bool handleNonVolatile(MachineInstr &MI) const override;
};
class SIMemoryLegalizer final {
@@ -899,6 +905,23 @@ SIMemOpAccess::getLDSDMAInfo(const MachineBasicBlock::iterator &MI) const {
return constructFromMIWithMMO(MI);
}
+/// \returns true if \p MI has one or more MMO, and all of them are fit for
+/// being marked as non-volatile. This means that either they are accessing the
+/// constant address space, are accessing a known invariant memory location, or
+/// that they are marked with the non-volatile metadata/MMO flag.
+static bool isNonVolatileMemoryAccess(const MachineInstr &MI) {
+ static constexpr unsigned NVFlags =
+ (MONonVolatile | MachineMemOperand::MOInvariant);
+ if (MI.getNumMemOperands() == 0)
+ return false;
+ return all_of(MI.memoperands(), [&](const MachineMemOperand *MMO) {
+ unsigned AS = MMO->getAddrSpace();
+ return AS == AMDGPUAS::CONSTANT_ADDRESS ||
+ AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT ||
+ (MMO->getFlags() & NVFlags);
+ });
+}
+
SICacheControl::SICacheControl(const GCNSubtarget &ST) : ST(ST) {
TII = ST.getInstrInfo();
IV = getIsaVersion(ST.getCPU());
@@ -2061,6 +2084,17 @@ bool SIGfx12CacheControl::insertRelease(MachineBasicBlock::iterator &MI,
return Changed;
}
+bool SIGfx12CacheControl::handleNonVolatile(MachineInstr &MI) const {
+ // On GFX12.5, set the NV CPol bit.
+ if (!ST.hasGFX1250Insts())
+ return false;
+ MachineOperand *CPol = TII->getNamedOperand(MI, OpName::cpol);
+ if (!CPol)
+ return false;
+ CPol->setImm(CPol->getImm() | AMDGPU::CPol::NV);
+ return true;
+}
+
bool SIGfx12CacheControl::enableVolatileAndOrNonTemporal(
MachineBasicBlock::iterator &MI, SIAtomicAddrSpace AddrSpace, SIMemOp Op,
bool IsVolatile, bool IsNonTemporal, bool IsLastUse = false) const {
@@ -2456,20 +2490,21 @@ bool SIMemoryLegalizer::run(MachineFunction &MF) {
MI = II->getIterator();
}
- if (!(MI->getDesc().TSFlags & SIInstrFlags::maybeAtomic))
- continue;
-
- if (const auto &MOI = MOA.getLoadInfo(MI)) {
- Changed |= expandLoad(*MOI, MI);
- } else if (const auto &MOI = MOA.getStoreInfo(MI)) {
- Changed |= expandStore(*MOI, MI);
- } else if (const auto &MOI = MOA.getLDSDMAInfo(MI)) {
- Changed |= expandLDSDMA(*MOI, MI);
- } else if (const auto &MOI = MOA.getAtomicFenceInfo(MI)) {
- Changed |= expandAtomicFence(*MOI, MI);
- } else if (const auto &MOI = MOA.getAtomicCmpxchgOrRmwInfo(MI)) {
- Changed |= expandAtomicCmpxchgOrRmw(*MOI, MI);
+ if (MI->getDesc().TSFlags & SIInstrFlags::maybeAtomic) {
+ if (const auto &MOI = MOA.getLoadInfo(MI))
+ Changed |= expandLoad(*MOI, MI);
+ else if (const auto &MOI = MOA.getStoreInfo(MI))
+ Changed |= expandStore(*MOI, MI);
+ else if (const auto &MOI = MOA.getLDSDMAInfo(MI))
+ Changed |= expandLDSDMA(*MOI, MI);
+ else if (const auto &MOI = MOA.getAtomicFenceInfo(MI))
+ Changed |= expandAtomicFence(*MOI, MI);
+ else if (const auto &MOI = MOA.getAtomicCmpxchgOrRmwInfo(MI))
+ Changed |= expandAtomicCmpxchgOrRmw(*MOI, MI);
}
+
+ if (isNonVolatileMemoryAccess(*MI))
+ Changed |= CC->handleNonVolatile(*MI);
}
}
diff --git a/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll b/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll
new file mode 100644
index 0000000000000..c516292984001
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll
@@ -0,0 +1,564 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -O3 -mcpu=gfx1200 -mattr=+cumode < %s | FileCheck --check-prefixes=GFX12-CU %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -O3 -mcpu=gfx1250 < %s | FileCheck --check-prefixes=GFX1250,GFX1250-DAGISEL %s
+; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -O3 -mcpu=gfx1250 < %s | FileCheck --check-prefixes=GFX1250,GFX1250-GISEL %s
+
+define void @flat_i32_nonatomic(ptr addrspace(0) %in, ptr addrspace(0) %out) {
+; GFX12-CU-LABEL: flat_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: flat_load_b32 v0, v[0:1]
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: flat_store_b32 v[2:3], v0
+; GFX12-CU-NEXT: s_wait_dscnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: flat_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: flat_load_b32 v0, v[0:1]
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: flat_store_b32 v[2:3], v0
+; GFX1250-NEXT: s_wait_dscnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(0) %in
+ store i32 %val, ptr addrspace(0) %out
+ ret void
+}
+
+define i32 @md_invariant__flat_i32_nonatomic(ptr addrspace(0) %in, ptr addrspace(0) %out) {
+; GFX12-CU-LABEL: md_invariant__flat_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: flat_load_b32 v0, v[0:1]
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_invariant__flat_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: flat_load_b32 v0, v[0:1] nv
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(0) %in, !invariant.load !0
+ ret i32 %val
+}
+
+define void @md_nv__flat_i32_nonatomic(ptr addrspace(0) %in, ptr addrspace(0) %out) {
+; GFX12-CU-LABEL: md_nv__flat_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: flat_load_b32 v0, v[0:1]
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: flat_store_b32 v[2:3], v0
+; GFX12-CU-NEXT: s_wait_dscnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_nv__flat_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: flat_load_b32 v0, v[0:1] nv
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: flat_store_b32 v[2:3], v0 nv
+; GFX1250-NEXT: s_wait_dscnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(0) %in, !amdgpu.non.volatile !0
+ store i32 %val, ptr addrspace(0) %out, !amdgpu.non.volatile !0
+ ret void
+}
+
+define void @global_i32_nonatomic(ptr addrspace(1) %in, ptr addrspace(1) %out) {
+; GFX12-CU-LABEL: global_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: global_load_b32 v0, v[0:1], off
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: global_store_b32 v[2:3], v0, off
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: global_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: global_load_b32 v0, v[0:1], off
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: global_store_b32 v[2:3], v0, off
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(1) %in
+ store i32 %val, ptr addrspace(1) %out
+ ret void
+}
+
+define i32 @md_invariant__global_i32_nonatomic(ptr addrspace(1) %in, ptr addrspace(1) %out) {
+; GFX12-CU-LABEL: md_invariant__global_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: global_load_b32 v0, v[0:1], off
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_invariant__global_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: global_load_b32 v0, v[0:1], off nv
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(1) %in, !invariant.load !0
+ ret i32 %val
+}
+
+define void @md_nv__global_i32_nonatomic(ptr addrspace(1) %in, ptr addrspace(1) %out) {
+; GFX12-CU-LABEL: md_nv__global_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: global_load_b32 v0, v[0:1], off
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: global_store_b32 v[2:3], v0, off
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_nv__global_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: global_load_b32 v0, v[0:1], off nv
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: global_store_b32 v[2:3], v0, off nv
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(1) %in, !amdgpu.non.volatile !0
+ store i32 %val, ptr addrspace(1) %out, !amdgpu.non.volatile !0
+ ret void
+}
+
+; DS does not have nv.
+define void @lds_i32_nonatomic(ptr addrspace(3) %in, ptr addrspace(3) %out) {
+; GFX12-CU-LABEL: lds_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: ds_load_b32 v0, v0
+; GFX12-CU-NEXT: s_wait_dscnt 0x0
+; GFX12-CU-NEXT: ds_store_b32 v1, v0
+; GFX12-CU-NEXT: s_wait_dscnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: lds_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: ds_load_b32 v0, v0
+; GFX1250-NEXT: s_wait_dscnt 0x0
+; GFX1250-NEXT: ds_store_b32 v1, v0
+; GFX1250-NEXT: s_wait_dscnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(3) %in, !amdgpu.non.volatile !0
+ store i32 %val, ptr addrspace(3) %out, !amdgpu.non.volatile !0
+ ret void
+}
+
+define i32 @scalar_i32_nonatomic(ptr addrspace(4) inreg %in) {
+; GFX12-CU-LABEL: scalar_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: scalar_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(4) %in
+ ret i32 %val
+}
+
+define i32 @md_invariant__scalar_i32_nonatomic(ptr addrspace(4) inreg %in) {
+; GFX12-CU-LABEL: md_invariant__scalar_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_invariant__scalar_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(4) %in, !invariant.load !0
+ ret i32 %val
+}
+
+define i32 @md_nv__scalar_i32_nonatomic(ptr addrspace(4) inreg %in) {
+; GFX12-CU-LABEL: md_nv__scalar_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_nv__scalar_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(4) %in, !amdgpu.non.volatile !0
+ ret i32 %val
+}
+
+define void @scratch_i32_nonatomic(ptr addrspace(5) %in, ptr addrspace(5) %out) {
+; GFX12-CU-LABEL: scratch_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: scratch_load_b32 v0, v0, off
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: scratch_store_b32 v1, v0, off
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: scratch_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: scratch_load_b32 v0, v0, off
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: scratch_store_b32 v1, v0, off
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(5) %in
+ store i32 %val, ptr addrspace(5) %out
+ ret void
+}
+
+define i32 @md_invariant__scratch_i32_nonatomic(ptr addrspace(5) %in, ptr addrspace(5) %out) {
+; GFX12-CU-LABEL: md_invariant__scratch_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: scratch_load_b32 v0, v0, off
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_invariant__scratch_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: scratch_load_b32 v0, v0, off nv
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(5) %in, !invariant.load !0
+ ret i32 %val
+}
+
+define void @md_nv__scratch_i32_nonatomic(ptr addrspace(5) %in, ptr addrspace(5) %out) {
+; GFX12-CU-LABEL: md_nv__scratch_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: scratch_load_b32 v0, v0, off
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: scratch_store_b32 v1, v0, off
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_nv__scratch_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: scratch_load_b32 v0, v0, off nv
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: scratch_store_b32 v1, v0, off nv
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(5) %in, !amdgpu.non.volatile !0
+ store i32 %val, ptr addrspace(5) %out, !amdgpu.non.volatile !0
+ ret void
+}
+
+define i32 @scalar32_i32_nonatomic(ptr addrspace(6) inreg %in) {
+; GFX12-CU-LABEL: scalar32_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: s_mov_b32 s1, 0
+; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: scalar32_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: s_mov_b32 s1, 0
+; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(6) %in
+ ret i32 %val
+}
+
+define i32 @md_invariant__scalar32_i32_nonatomic(ptr addrspace(6) inreg %in) {
+; GFX12-CU-LABEL: md_invariant__scalar32_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: s_mov_b32 s1, 0
+; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_invariant__scalar32_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: s_mov_b32 s1, 0
+; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(6) %in, !invariant.load !0
+ ret i32 %val
+}
+
+define i32 @md_nv__scalar32_i32_nonatomic(ptr addrspace(6) inreg %in) {
+; GFX12-CU-LABEL: md_nv__scalar32_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: s_mov_b32 s1, 0
+; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_nv__scalar32_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: s_mov_b32 s1, 0
+; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(6) %in, !amdgpu.non.volatile !0
+ ret i32 %val
+}
+
+define void @buffer_i32_nonatomic(ptr addrspace(7) inreg %in, ptr addrspace(7) inreg %out) {
+; GFX12-CU-LABEL: buffer_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
+; GFX12-CU-NEXT: s_mov_b32 s7, s20
+; GFX12-CU-NEXT: s_mov_b32 s6, s19
+; GFX12-CU-NEXT: s_mov_b32 s5, s18
+; GFX12-CU-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen
+; GFX12-CU-NEXT: s_mov_b32 s4, s17
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-DAGISEL-LABEL: buffer_i32_nonatomic:
+; GFX1250-DAGISEL: ; %bb.0: ; %entry
+; GFX1250-DAGISEL-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-DAGISEL-NEXT: s_wait_kmcnt 0x0
+; GFX1250-DAGISEL-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s7, s20
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s6, s19
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s5, s18
+; GFX1250-DAGISEL-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s4, s17
+; GFX1250-DAGISEL-NEXT: s_wait_loadcnt 0x0
+; GFX1250-DAGISEL-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen
+; GFX1250-DAGISEL-NEXT: s_set_pc_i64 s[30:31]
+;
+; GFX1250-GISEL-LABEL: buffer_i32_nonatomic:
+; GFX1250-GISEL: ; %bb.0: ; %entry
+; GFX1250-GISEL-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-GISEL-NEXT: s_wait_kmcnt 0x0
+; GFX1250-GISEL-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
+; GFX1250-GISEL-NEXT: s_mov_b32 s4, s17
+; GFX1250-GISEL-NEXT: s_mov_b32 s5, s18
+; GFX1250-GISEL-NEXT: s_mov_b32 s6, s19
+; GFX1250-GISEL-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen
+; GFX1250-GISEL-NEXT: s_mov_b32 s7, s20
+; GFX1250-GISEL-NEXT: s_wait_loadcnt 0x0
+; GFX1250-GISEL-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen
+; GFX1250-GISEL-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(7) %in
+ store i32 %val, ptr addrspace(7) %out
+ ret void
+}
+
+define i32 @md_invariant__buffer_i32_nonatomic(ptr addrspace(7) inreg %in, ptr addrspace(7) inreg %out) {
+; GFX12-CU-LABEL: md_invariant__buffer_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_mov_b32_e32 v0, s16
+; GFX12-CU-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-LABEL: md_invariant__buffer_i32_nonatomic:
+; GFX1250: ; %bb.0: ; %entry
+; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-NEXT: s_wait_kmcnt 0x0
+; GFX1250-NEXT: v_mov_b32_e32 v0, s16
+; GFX1250-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen nv
+; GFX1250-NEXT: s_wait_loadcnt 0x0
+; GFX1250-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(7) %in, !invariant.load !0
+ ret i32 %val
+}
+
+define void @md_nv__buffer_i32_nonatomic(ptr addrspace(7) inreg %in, ptr addrspace(7) inreg %out) {
+; GFX12-CU-LABEL: md_nv__buffer_i32_nonatomic:
+; GFX12-CU: ; %bb.0: ; %entry
+; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-CU-NEXT: s_wait_expcnt 0x0
+; GFX12-CU-NEXT: s_wait_samplecnt 0x0
+; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
+; GFX12-CU-NEXT: s_wait_kmcnt 0x0
+; GFX12-CU-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
+; GFX12-CU-NEXT: s_mov_b32 s7, s20
+; GFX12-CU-NEXT: s_mov_b32 s6, s19
+; GFX12-CU-NEXT: s_mov_b32 s5, s18
+; GFX12-CU-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen
+; GFX12-CU-NEXT: s_mov_b32 s4, s17
+; GFX12-CU-NEXT: s_wait_loadcnt 0x0
+; GFX12-CU-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen
+; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX1250-DAGISEL-LABEL: md_nv__buffer_i32_nonatomic:
+; GFX1250-DAGISEL: ; %bb.0: ; %entry
+; GFX1250-DAGISEL-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-DAGISEL-NEXT: s_wait_kmcnt 0x0
+; GFX1250-DAGISEL-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s7, s20
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s6, s19
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s5, s18
+; GFX1250-DAGISEL-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen nv
+; GFX1250-DAGISEL-NEXT: s_mov_b32 s4, s17
+; GFX1250-DAGISEL-NEXT: s_wait_loadcnt 0x0
+; GFX1250-DAGISEL-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen nv
+; GFX1250-DAGISEL-NEXT: s_set_pc_i64 s[30:31]
+;
+; GFX1250-GISEL-LABEL: md_nv__buffer_i32_nonatomic:
+; GFX1250-GISEL: ; %bb.0: ; %entry
+; GFX1250-GISEL-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX1250-GISEL-NEXT: s_wait_kmcnt 0x0
+; GFX1250-GISEL-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
+; GFX1250-GISEL-NEXT: s_mov_b32 s4, s17
+; GFX1250-GISEL-NEXT: s_mov_b32 s5, s18
+; GFX1250-GISEL-NEXT: s_mov_b32 s6, s19
+; GFX1250-GISEL-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen nv
+; GFX1250-GISEL-NEXT: s_mov_b32 s7, s20
+; GFX1250-GISEL-NEXT: s_wait_loadcnt 0x0
+; GFX1250-GISEL-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen nv
+; GFX1250-GISEL-NEXT: s_set_pc_i64 s[30:31]
+entry:
+ %val = load i32, ptr addrspace(7) %in, !amdgpu.non.volatile !0
+ store i32 %val, ptr addrspace(7) %out, !amdgpu.non.volatile !0
+ ret void
+}
+
+!0 = !{}
diff --git a/llvm/test/CodeGen/AMDGPU/promote-constOffset-to-imm-gfx12.mir b/llvm/test/CodeGen/AMDGPU/promote-constOffset-to-imm-gfx12.mir
index 9215c0e664505..8d8c791fbd9ae 100644
--- a/llvm/test/CodeGen/AMDGPU/promote-constOffset-to-imm-gfx12.mir
+++ b/llvm/test/CodeGen/AMDGPU/promote-constOffset-to-imm-gfx12.mir
@@ -85,7 +85,7 @@ body: |
; GFX1250-LABEL: name: promote_async_load_u64
; GFX1250: liveins: $vgpr0, $sgpr4_sgpr5
; GFX1250-NEXT: {{ $}}
- ; GFX1250-NEXT: early-clobber renamable $sgpr0_sgpr1 = S_LOAD_DWORDX2_IMM_ec killed renamable $sgpr4_sgpr5, 36, 0 :: (dereferenceable invariant load (s64), align 4, addrspace 4)
+ ; GFX1250-NEXT: early-clobber renamable $sgpr0_sgpr1 = S_LOAD_DWORDX2_IMM_ec killed renamable $sgpr4_sgpr5, 36, 32 :: (dereferenceable invariant load (s64), align 4, addrspace 4)
; GFX1250-NEXT: renamable $vgpr1 = V_MOV_B32_e32 0, implicit $exec
; GFX1250-NEXT: renamable $vgpr0 = V_AND_B32_e32 1023, killed $vgpr0, implicit $exec
; GFX1250-NEXT: GLOBAL_LOAD_ASYNC_TO_LDS_B128_SADDR $vgpr1, $sgpr0_sgpr1, $vgpr0, 0, 0, implicit-def dead $asynccnt, implicit $exec, implicit $asynccnt :: (load store (s128), align 1, addrspace 3)
>From 994518f70ce086401bbb73af4dc2b9d8fbb7d7b9 Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Tue, 3 Feb 2026 14:09:35 +0100
Subject: [PATCH 2/3] Remove metadata
---
llvm/docs/AMDGPUUsage.rst | 23 --
llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 2 -
llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp | 2 +-
.../AMDGPU/memory-legalizer-non-volatile.ll | 218 ------------------
4 files changed, 1 insertion(+), 244 deletions(-)
diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index d3717dcc00908..cd5410a31b98f 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -1878,29 +1878,6 @@ and
!0 = !{}
-.. _amdgpu_non_volatile:
-
-'``amdgpu.non.volatile``' Metadata
-----------------------------------
-
-Explicitly marks memory accesses (load, store, rmw) to locations that are never written to by other threads during the execution of the shader.
-
-This metadata is a performance optimization and can be dropped if necessary.
-Using this metadata on a memory access to a location that is written to by other threads is undefined behavior.
-
-Sets ``NV=1`` on the instruction if the target supports it.
-
-.. code-block:: llvm
-
- %val = load i32, ptr %in, align 4, !amdgpu.non.volatile !{}
-
-
-.. note::
-
- This metadata is used to request ``NV=1`` on an operation, but the compiler may also set ``NV=1``
- on memory accesses that do not have the metadata when it is safe to do so. For example, it may
- set it on accesses to constant memory, when loading from or storing to scratch memory used for
- spills, etc.
LLVM IR Attributes
==================
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 3b17198593db9..b043d5354042d 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -19357,8 +19357,6 @@ SITargetLowering::getTargetMMOFlags(const Instruction &I) const {
Flags |= MONoClobber;
if (I.getMetadata("amdgpu.last.use"))
Flags |= MOLastUse;
- if (I.getMetadata("amdgpu.non.volatile"))
- Flags |= MONonVolatile;
return Flags;
}
diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
index 6ceb7f7045a98..b2ae7604d142f 100644
--- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
@@ -908,7 +908,7 @@ SIMemOpAccess::getLDSDMAInfo(const MachineBasicBlock::iterator &MI) const {
/// \returns true if \p MI has one or more MMO, and all of them are fit for
/// being marked as non-volatile. This means that either they are accessing the
/// constant address space, are accessing a known invariant memory location, or
-/// that they are marked with the non-volatile metadata/MMO flag.
+/// that they are marked with MONonVolatile.
static bool isNonVolatileMemoryAccess(const MachineInstr &MI) {
static constexpr unsigned NVFlags =
(MONonVolatile | MachineMemOperand::MOInvariant);
diff --git a/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll b/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll
index c516292984001..5017e572b70e5 100644
--- a/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll
+++ b/llvm/test/CodeGen/AMDGPU/memory-legalizer-non-volatile.ll
@@ -56,35 +56,6 @@ entry:
ret i32 %val
}
-define void @md_nv__flat_i32_nonatomic(ptr addrspace(0) %in, ptr addrspace(0) %out) {
-; GFX12-CU-LABEL: md_nv__flat_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: flat_load_b32 v0, v[0:1]
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: flat_store_b32 v[2:3], v0
-; GFX12-CU-NEXT: s_wait_dscnt 0x0
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-LABEL: md_nv__flat_i32_nonatomic:
-; GFX1250: ; %bb.0: ; %entry
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: flat_load_b32 v0, v[0:1] nv
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: flat_store_b32 v[2:3], v0 nv
-; GFX1250-NEXT: s_wait_dscnt 0x0
-; GFX1250-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(0) %in, !amdgpu.non.volatile !0
- store i32 %val, ptr addrspace(0) %out, !amdgpu.non.volatile !0
- ret void
-}
-
define void @global_i32_nonatomic(ptr addrspace(1) %in, ptr addrspace(1) %out) {
; GFX12-CU-LABEL: global_i32_nonatomic:
; GFX12-CU: ; %bb.0: ; %entry
@@ -136,63 +107,6 @@ entry:
ret i32 %val
}
-define void @md_nv__global_i32_nonatomic(ptr addrspace(1) %in, ptr addrspace(1) %out) {
-; GFX12-CU-LABEL: md_nv__global_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: global_load_b32 v0, v[0:1], off
-; GFX12-CU-NEXT: s_wait_loadcnt 0x0
-; GFX12-CU-NEXT: global_store_b32 v[2:3], v0, off
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-LABEL: md_nv__global_i32_nonatomic:
-; GFX1250: ; %bb.0: ; %entry
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: global_load_b32 v0, v[0:1], off nv
-; GFX1250-NEXT: s_wait_loadcnt 0x0
-; GFX1250-NEXT: global_store_b32 v[2:3], v0, off nv
-; GFX1250-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(1) %in, !amdgpu.non.volatile !0
- store i32 %val, ptr addrspace(1) %out, !amdgpu.non.volatile !0
- ret void
-}
-
-; DS does not have nv.
-define void @lds_i32_nonatomic(ptr addrspace(3) %in, ptr addrspace(3) %out) {
-; GFX12-CU-LABEL: lds_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: ds_load_b32 v0, v0
-; GFX12-CU-NEXT: s_wait_dscnt 0x0
-; GFX12-CU-NEXT: ds_store_b32 v1, v0
-; GFX12-CU-NEXT: s_wait_dscnt 0x0
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-LABEL: lds_i32_nonatomic:
-; GFX1250: ; %bb.0: ; %entry
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: ds_load_b32 v0, v0
-; GFX1250-NEXT: s_wait_dscnt 0x0
-; GFX1250-NEXT: ds_store_b32 v1, v0
-; GFX1250-NEXT: s_wait_dscnt 0x0
-; GFX1250-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(3) %in, !amdgpu.non.volatile !0
- store i32 %val, ptr addrspace(3) %out, !amdgpu.non.volatile !0
- ret void
-}
-
define i32 @scalar_i32_nonatomic(ptr addrspace(4) inreg %in) {
; GFX12-CU-LABEL: scalar_i32_nonatomic:
; GFX12-CU: ; %bb.0: ; %entry
@@ -245,32 +159,6 @@ entry:
ret i32 %val
}
-define i32 @md_nv__scalar_i32_nonatomic(ptr addrspace(4) inreg %in) {
-; GFX12-CU-LABEL: md_nv__scalar_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-LABEL: md_nv__scalar_i32_nonatomic:
-; GFX1250: ; %bb.0: ; %entry
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: v_mov_b32_e32 v0, s0
-; GFX1250-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(4) %in, !amdgpu.non.volatile !0
- ret i32 %val
-}
-
define void @scratch_i32_nonatomic(ptr addrspace(5) %in, ptr addrspace(5) %out) {
; GFX12-CU-LABEL: scratch_i32_nonatomic:
; GFX12-CU: ; %bb.0: ; %entry
@@ -322,33 +210,6 @@ entry:
ret i32 %val
}
-define void @md_nv__scratch_i32_nonatomic(ptr addrspace(5) %in, ptr addrspace(5) %out) {
-; GFX12-CU-LABEL: md_nv__scratch_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: scratch_load_b32 v0, v0, off
-; GFX12-CU-NEXT: s_wait_loadcnt 0x0
-; GFX12-CU-NEXT: scratch_store_b32 v1, v0, off
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-LABEL: md_nv__scratch_i32_nonatomic:
-; GFX1250: ; %bb.0: ; %entry
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: scratch_load_b32 v0, v0, off nv
-; GFX1250-NEXT: s_wait_loadcnt 0x0
-; GFX1250-NEXT: scratch_store_b32 v1, v0, off nv
-; GFX1250-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(5) %in, !amdgpu.non.volatile !0
- store i32 %val, ptr addrspace(5) %out, !amdgpu.non.volatile !0
- ret void
-}
-
define i32 @scalar32_i32_nonatomic(ptr addrspace(6) inreg %in) {
; GFX12-CU-LABEL: scalar32_i32_nonatomic:
; GFX12-CU: ; %bb.0: ; %entry
@@ -405,34 +266,6 @@ entry:
ret i32 %val
}
-define i32 @md_nv__scalar32_i32_nonatomic(ptr addrspace(6) inreg %in) {
-; GFX12-CU-LABEL: md_nv__scalar32_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: s_mov_b32 s1, 0
-; GFX12-CU-NEXT: s_load_b32 s0, s[0:1], 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: v_mov_b32_e32 v0, s0
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-LABEL: md_nv__scalar32_i32_nonatomic:
-; GFX1250: ; %bb.0: ; %entry
-; GFX1250-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: s_mov_b32 s1, 0
-; GFX1250-NEXT: s_load_b32 s0, s[0:1], 0x0 nv
-; GFX1250-NEXT: s_wait_kmcnt 0x0
-; GFX1250-NEXT: v_mov_b32_e32 v0, s0
-; GFX1250-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(6) %in, !amdgpu.non.volatile !0
- ret i32 %val
-}
-
define void @buffer_i32_nonatomic(ptr addrspace(7) inreg %in, ptr addrspace(7) inreg %out) {
; GFX12-CU-LABEL: buffer_i32_nonatomic:
; GFX12-CU: ; %bb.0: ; %entry
@@ -510,55 +343,4 @@ entry:
ret i32 %val
}
-define void @md_nv__buffer_i32_nonatomic(ptr addrspace(7) inreg %in, ptr addrspace(7) inreg %out) {
-; GFX12-CU-LABEL: md_nv__buffer_i32_nonatomic:
-; GFX12-CU: ; %bb.0: ; %entry
-; GFX12-CU-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX12-CU-NEXT: s_wait_expcnt 0x0
-; GFX12-CU-NEXT: s_wait_samplecnt 0x0
-; GFX12-CU-NEXT: s_wait_bvhcnt 0x0
-; GFX12-CU-NEXT: s_wait_kmcnt 0x0
-; GFX12-CU-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
-; GFX12-CU-NEXT: s_mov_b32 s7, s20
-; GFX12-CU-NEXT: s_mov_b32 s6, s19
-; GFX12-CU-NEXT: s_mov_b32 s5, s18
-; GFX12-CU-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen
-; GFX12-CU-NEXT: s_mov_b32 s4, s17
-; GFX12-CU-NEXT: s_wait_loadcnt 0x0
-; GFX12-CU-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen
-; GFX12-CU-NEXT: s_setpc_b64 s[30:31]
-;
-; GFX1250-DAGISEL-LABEL: md_nv__buffer_i32_nonatomic:
-; GFX1250-DAGISEL: ; %bb.0: ; %entry
-; GFX1250-DAGISEL-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-DAGISEL-NEXT: s_wait_kmcnt 0x0
-; GFX1250-DAGISEL-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
-; GFX1250-DAGISEL-NEXT: s_mov_b32 s7, s20
-; GFX1250-DAGISEL-NEXT: s_mov_b32 s6, s19
-; GFX1250-DAGISEL-NEXT: s_mov_b32 s5, s18
-; GFX1250-DAGISEL-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen nv
-; GFX1250-DAGISEL-NEXT: s_mov_b32 s4, s17
-; GFX1250-DAGISEL-NEXT: s_wait_loadcnt 0x0
-; GFX1250-DAGISEL-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen nv
-; GFX1250-DAGISEL-NEXT: s_set_pc_i64 s[30:31]
-;
-; GFX1250-GISEL-LABEL: md_nv__buffer_i32_nonatomic:
-; GFX1250-GISEL: ; %bb.0: ; %entry
-; GFX1250-GISEL-NEXT: s_wait_loadcnt_dscnt 0x0
-; GFX1250-GISEL-NEXT: s_wait_kmcnt 0x0
-; GFX1250-GISEL-NEXT: v_dual_mov_b32 v0, s16 :: v_dual_mov_b32 v1, s21
-; GFX1250-GISEL-NEXT: s_mov_b32 s4, s17
-; GFX1250-GISEL-NEXT: s_mov_b32 s5, s18
-; GFX1250-GISEL-NEXT: s_mov_b32 s6, s19
-; GFX1250-GISEL-NEXT: buffer_load_b32 v0, v0, s[0:3], null offen nv
-; GFX1250-GISEL-NEXT: s_mov_b32 s7, s20
-; GFX1250-GISEL-NEXT: s_wait_loadcnt 0x0
-; GFX1250-GISEL-NEXT: buffer_store_b32 v0, v1, s[4:7], null offen nv
-; GFX1250-GISEL-NEXT: s_set_pc_i64 s[30:31]
-entry:
- %val = load i32, ptr addrspace(7) %in, !amdgpu.non.volatile !0
- store i32 %val, ptr addrspace(7) %out, !amdgpu.non.volatile !0
- ret void
-}
-
!0 = !{}
>From 9610aafa02b50aa465988a59b5ae42b3ecf0495e Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Tue, 3 Feb 2026 14:34:31 +0100
Subject: [PATCH 3/3] Rename to MOThreadPrivate
---
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 2 +-
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 5 +++--
llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp | 4 ++--
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 14dee6d1804d8..7639ac46b907d 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -9897,7 +9897,7 @@ SIInstrInfo::getSerializableMachineMemOperandTargetFlags() const {
{MONoClobber, "amdgpu-noclobber"},
{MOLastUse, "amdgpu-last-use"},
{MOCooperative, "amdgpu-cooperative"},
- {MONonVolatile, "amdgpu-non-volatile"},
+ {MOThreadPrivate, "amdgpu-thread-private"},
};
return ArrayRef(TargetFlags);
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index fe7365c6b7a66..85585cbfc628a 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -52,8 +52,9 @@ static const MachineMemOperand::Flags MOLastUse =
static const MachineMemOperand::Flags MOCooperative =
MachineMemOperand::MOTargetFlag3;
-/// Mark the MMO of non-volatile memory operations.
-static const MachineMemOperand::Flags MONonVolatile =
+/// Mark the MMO of accesses to memory locations that are
+/// never written to by other threads.
+static const MachineMemOperand::Flags MOThreadPrivate =
MachineMemOperand::MOTargetFlag4;
/// Utility to store machine instructions worklist.
diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
index b2ae7604d142f..7ead871510c07 100644
--- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
@@ -908,10 +908,10 @@ SIMemOpAccess::getLDSDMAInfo(const MachineBasicBlock::iterator &MI) const {
/// \returns true if \p MI has one or more MMO, and all of them are fit for
/// being marked as non-volatile. This means that either they are accessing the
/// constant address space, are accessing a known invariant memory location, or
-/// that they are marked with MONonVolatile.
+/// that they are marked with the non-volatile metadata/MMO flag.
static bool isNonVolatileMemoryAccess(const MachineInstr &MI) {
static constexpr unsigned NVFlags =
- (MONonVolatile | MachineMemOperand::MOInvariant);
+ (MOThreadPrivate | MachineMemOperand::MOInvariant);
if (MI.getNumMemOperands() == 0)
return false;
return all_of(MI.memoperands(), [&](const MachineMemOperand *MMO) {
More information about the llvm-commits
mailing list