[llvm-branch-commits] [llvm] [AMDGPU][SIMemoryLegalizer] Consider scratch operations as NV=1 if GAS is disabled (PR #189556)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Mar 31 01:19:10 PDT 2026


================
@@ -909,11 +909,22 @@ SIMemOpAccess::getLDSDMAInfo(const MachineBasicBlock::iterator &MI) const {
 /// 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 bool isNonVolatileMemoryAccess(const GCNSubtarget &ST,
+                                      const MachineInstr &MI) {
   if (MI.getNumMemOperands() == 0)
     return false;
+  // If globally addressable scratch is not in use, we can assume any scratch
+  // opcode accesses thread-local memory, thus is NV=1.
+  bool GASEnabled = ST.isGloballyAddressableScratchEnabled();
+  if (!GASEnabled && ST.getInstrInfo()->isFLATScratch(MI.getOpcode()))
+    return true;
   return all_of(MI.memoperands(), [&](const MachineMemOperand *MMO) {
-    return MMO->getFlags() & (MOThreadPrivate | MachineMemOperand::MOInvariant);
+    // If globally addressable scratch is enabled, we can only set NV=1 by
+    // checking for the thread-private or invariant memory. If it is disabled,
+    // we can additionally consider private memory.
+    return (!GASEnabled && MMO->getAddrSpace() == AMDGPUAS::PRIVATE_ADDRESS) ||
----------------
arsenm wrote:

Should this be represented as a different address space? 

https://github.com/llvm/llvm-project/pull/189556


More information about the llvm-branch-commits mailing list