[llvm] [AMDGPU][CodeGen] LocalStackSlotAllocation: record per-instr FI offsets (PR #166979)
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 27 07:10:36 PST 2025
https://github.com/gandhi56 updated https://github.com/llvm/llvm-project/pull/166979
>From d85ae83ff235ceff3a94a75903ccaa91cbe849e9 Mon Sep 17 00:00:00 2001
From: Anshil Gandhi <gandhi21299 at gmail.com>
Date: Fri, 7 Nov 2025 12:24:43 -0500
Subject: [PATCH 1/3] [CodeGen][AMDGPU] LocalStackSlotAllocation: record
per-instr FI offsets
Capture per-instruction FI offsets via getFrameIndexInstrOffset and sort
frame refs by local offset + instruction's immediate offset. This change
reduces the need for scavenging registers as the base registers can now
be reused.
Resolves #155902
---
llvm/lib/CodeGen/LocalStackSlotAllocation.cpp | 17 +-
.../flat-scratch-neg-offset-bug-155902.ll | 230 ++++++++++++++++++
...local-stack-alloc-add-references.gfx10.mir | 10 +-
.../local-stack-alloc-block-sp-reference.ll | 11 +-
4 files changed, 253 insertions(+), 15 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/flat-scratch-neg-offset-bug-155902.ll
diff --git a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
index 987f64f56403d..402b285f53b7e 100644
--- a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -52,6 +52,7 @@ namespace {
MachineBasicBlock::iterator MI; // Instr referencing the frame
int64_t LocalOffset; // Local offset of the frame idx referenced
int FrameIdx; // The frame index
+ int64_t InstOffset; // Offset of the instruction from the base register
// Order reference instruction appears in program. Used to ensure
// deterministic order when multiple instructions may reference the same
@@ -59,12 +60,15 @@ namespace {
unsigned Order;
public:
- FrameRef(MachineInstr *I, int64_t Offset, int Idx, unsigned Ord) :
- MI(I), LocalOffset(Offset), FrameIdx(Idx), Order(Ord) {}
+ FrameRef(MachineInstr *I, int64_t Offset, int Idx, int64_t InstOffset,
+ unsigned Ord)
+ : MI(I), LocalOffset(Offset), FrameIdx(Idx), InstOffset(InstOffset),
+ Order(Ord) {}
bool operator<(const FrameRef &RHS) const {
- return std::tie(LocalOffset, FrameIdx, Order) <
- std::tie(RHS.LocalOffset, RHS.FrameIdx, RHS.Order);
+ return std::make_tuple(LocalOffset + InstOffset, FrameIdx, Order) <
+ std::make_tuple(RHS.LocalOffset + RHS.InstOffset, RHS.FrameIdx,
+ RHS.Order);
}
MachineBasicBlock::iterator getMachineInstr() const { return MI; }
@@ -346,7 +350,10 @@ bool LocalStackSlotImpl::insertFrameReferenceRegisters(MachineFunction &Fn) {
int64_t LocalOffset = LocalOffsets[Idx];
if (!TRI->needsFrameBaseReg(&MI, LocalOffset))
break;
- FrameReferenceInsns.push_back(FrameRef(&MI, LocalOffset, Idx, Order++));
+ int64_t InstOffset =
+ TRI->getFrameIndexInstrOffset(&MI, MO.getOperandNo());
+ FrameReferenceInsns.push_back(
+ FrameRef(&MI, LocalOffset, Idx, InstOffset, Order++));
break;
}
}
diff --git a/llvm/test/CodeGen/AMDGPU/flat-scratch-neg-offset-bug-155902.ll b/llvm/test/CodeGen/AMDGPU/flat-scratch-neg-offset-bug-155902.ll
new file mode 100644
index 0000000000000..633b9556cfec3
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/flat-scratch-neg-offset-bug-155902.ll
@@ -0,0 +1,230 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc < %s -verify-machineinstrs -O0 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 | FileCheck %s --check-prefix=GFX950
+
+; Ensure we don't crash with: "Cannot scavenge register in FI elimination!"
+define amdgpu_kernel void @issue155902(i64 %arg, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %arg5, i64 %arg6, i64 %arg7, i64 %arg8, i64 %arg9, i64 %arg10, i64 %arg11, i64 %arg12, i64 %arg13, i64 %arg14, i64 %arg15, i64 %arg16, i64 %arg17, i64 %arg18, i64 %arg19, i64 %arg20, i64 %arg21, i64 %arg22, i64 %arg23, i64 %arg24, i64 %arg25, i64 %arg26, i64 %arg27, i64 %arg28, i64 %arg29, i64 %arg30, i64 %arg31, i64 %arg32, i64 %arg33, i64 %arg34, i64 %arg35, i64 %arg36, i64 %arg37, i64 %arg38, i64 %arg39, i64 %arg40, i64 %arg41, i64 %arg42, i64 %arg43, i64 %arg44, i64 %arg45, i64 %arg46, i64 %arg47, i64 %arg48, i64 %arg49) {
+; GFX950-LABEL: issue155902:
+; GFX950: ; %bb.0: ; %bb
+; GFX950-NEXT: s_mov_b32 s33, 0x4008
+; GFX950-NEXT: s_mov_b64 s[2:3], s[4:5]
+; GFX950-NEXT: s_load_dwordx2 s[0:1], s[2:3], 0x0
+; GFX950-NEXT: s_load_dwordx2 vcc, s[2:3], 0x8
+; GFX950-NEXT: s_load_dwordx2 s[98:99], s[2:3], 0x10
+; GFX950-NEXT: s_load_dwordx2 s[96:97], s[2:3], 0x18
+; GFX950-NEXT: s_load_dwordx2 s[94:95], s[2:3], 0x20
+; GFX950-NEXT: s_load_dwordx2 s[92:93], s[2:3], 0x28
+; GFX950-NEXT: s_load_dwordx2 s[90:91], s[2:3], 0x30
+; GFX950-NEXT: s_load_dwordx2 s[88:89], s[2:3], 0x38
+; GFX950-NEXT: s_load_dwordx2 s[86:87], s[2:3], 0x40
+; GFX950-NEXT: s_load_dwordx2 s[84:85], s[2:3], 0x48
+; GFX950-NEXT: s_load_dwordx2 s[82:83], s[2:3], 0x50
+; GFX950-NEXT: s_load_dwordx2 s[80:81], s[2:3], 0x58
+; GFX950-NEXT: s_load_dwordx2 s[78:79], s[2:3], 0x60
+; GFX950-NEXT: s_load_dwordx2 s[76:77], s[2:3], 0x68
+; GFX950-NEXT: s_load_dwordx2 s[74:75], s[2:3], 0x70
+; GFX950-NEXT: s_load_dwordx2 s[72:73], s[2:3], 0x78
+; GFX950-NEXT: s_load_dwordx2 s[70:71], s[2:3], 0x80
+; GFX950-NEXT: s_load_dwordx2 s[68:69], s[2:3], 0x88
+; GFX950-NEXT: s_load_dwordx2 s[66:67], s[2:3], 0x90
+; GFX950-NEXT: s_load_dwordx2 s[64:65], s[2:3], 0x98
+; GFX950-NEXT: s_load_dwordx2 s[62:63], s[2:3], 0xa0
+; GFX950-NEXT: s_load_dwordx2 s[60:61], s[2:3], 0xa8
+; GFX950-NEXT: s_load_dwordx2 s[58:59], s[2:3], 0xb0
+; GFX950-NEXT: s_load_dwordx2 s[56:57], s[2:3], 0xb8
+; GFX950-NEXT: s_load_dwordx2 s[54:55], s[2:3], 0xc0
+; GFX950-NEXT: s_load_dwordx2 s[52:53], s[2:3], 0xc8
+; GFX950-NEXT: s_load_dwordx2 s[50:51], s[2:3], 0xd0
+; GFX950-NEXT: s_load_dwordx2 s[48:49], s[2:3], 0xd8
+; GFX950-NEXT: s_load_dwordx2 s[46:47], s[2:3], 0xe0
+; GFX950-NEXT: s_load_dwordx2 s[44:45], s[2:3], 0xe8
+; GFX950-NEXT: s_load_dwordx2 s[42:43], s[2:3], 0xf0
+; GFX950-NEXT: s_load_dwordx2 s[40:41], s[2:3], 0xf8
+; GFX950-NEXT: s_load_dwordx2 s[38:39], s[2:3], 0x100
+; GFX950-NEXT: s_load_dwordx2 s[36:37], s[2:3], 0x108
+; GFX950-NEXT: s_load_dwordx2 s[34:35], s[2:3], 0x110
+; GFX950-NEXT: s_load_dwordx2 s[30:31], s[2:3], 0x118
+; GFX950-NEXT: s_load_dwordx2 s[28:29], s[2:3], 0x120
+; GFX950-NEXT: s_load_dwordx2 s[26:27], s[2:3], 0x128
+; GFX950-NEXT: s_load_dwordx2 s[24:25], s[2:3], 0x130
+; GFX950-NEXT: s_load_dwordx2 s[22:23], s[2:3], 0x138
+; GFX950-NEXT: s_load_dwordx2 s[20:21], s[2:3], 0x140
+; GFX950-NEXT: s_load_dwordx2 s[18:19], s[2:3], 0x148
+; GFX950-NEXT: s_load_dwordx2 s[16:17], s[2:3], 0x150
+; GFX950-NEXT: s_load_dwordx2 s[14:15], s[2:3], 0x158
+; GFX950-NEXT: s_load_dwordx2 s[12:13], s[2:3], 0x160
+; GFX950-NEXT: s_load_dwordx2 s[10:11], s[2:3], 0x168
+; GFX950-NEXT: s_load_dwordx2 s[8:9], s[2:3], 0x170
+; GFX950-NEXT: s_load_dwordx2 s[6:7], s[2:3], 0x178
+; GFX950-NEXT: s_load_dwordx2 s[4:5], s[2:3], 0x180
+; GFX950-NEXT: s_nop 0
+; GFX950-NEXT: s_load_dwordx2 s[2:3], s[2:3], 0x188
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], 0
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s33 offset:8
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s33
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], 0x384
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s33 offset:16
+; GFX950-NEXT: s_mov_b32 s33, 0
+; GFX950-NEXT: ; implicit-def: $vgpr2 : SGPR spill to VGPR lane
+; GFX950-NEXT: v_writelane_b32 v2, s33, 0
+; GFX950-NEXT: s_waitcnt lgkmcnt(0)
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[0:1]
+; GFX950-NEXT: v_readlane_b32 s0, v2, 0
+; GFX950-NEXT: s_nop 4
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], vcc
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[98:99]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[96:97]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[94:95]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[92:93]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[90:91]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[88:89]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[86:87]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[84:85]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[82:83]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[80:81]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[78:79]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[76:77]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[74:75]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[72:73]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[70:71]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[68:69]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[66:67]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[64:65]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[62:63]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[60:61]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[58:59]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[56:57]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[54:55]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[52:53]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[50:51]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[48:49]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[46:47]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[44:45]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[42:43]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[40:41]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[38:39]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[36:37]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[34:35]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[30:31]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[28:29]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[26:27]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[24:25]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[22:23]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[20:21]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[18:19]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[16:17]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[14:15]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[12:13]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[10:11]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[8:9]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[6:7]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[4:5]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: v_mov_b64_e32 v[0:1], s[2:3]
+; GFX950-NEXT: scratch_store_dwordx2 off, v[0:1], s0
+; GFX950-NEXT: s_endpgm
+bb:
+ %alloca.big = alloca [4096 x i32], align 4, addrspace(5)
+ %alloca304 = alloca [2 x i64], align 8, addrspace(5)
+ %alloca307 = alloca i64, align 8, addrspace(5)
+ store [2 x i64] zeroinitializer, ptr addrspace(5) %alloca304, align 8
+ store i64 900, ptr addrspace(5) %alloca307, align 8
+ store i64 %arg, ptr addrspace(5) null, align 8
+ store i64 %arg1, ptr addrspace(5) null, align 8
+ store i64 %arg2, ptr addrspace(5) null, align 8
+ store i64 %arg3, ptr addrspace(5) null, align 8
+ store i64 %arg4, ptr addrspace(5) null, align 8
+ store i64 %arg5, ptr addrspace(5) null, align 8
+ store i64 %arg6, ptr addrspace(5) null, align 8
+ store i64 %arg7, ptr addrspace(5) null, align 8
+ store i64 %arg8, ptr addrspace(5) null, align 8
+ store i64 %arg9, ptr addrspace(5) null, align 8
+ store i64 %arg10, ptr addrspace(5) null, align 8
+ store i64 %arg11, ptr addrspace(5) null, align 8
+ store i64 %arg12, ptr addrspace(5) null, align 8
+ store i64 %arg13, ptr addrspace(5) null, align 8
+ store i64 %arg14, ptr addrspace(5) null, align 8
+ store i64 %arg15, ptr addrspace(5) null, align 8
+ store i64 %arg16, ptr addrspace(5) null, align 8
+ store i64 %arg17, ptr addrspace(5) null, align 8
+ store i64 %arg18, ptr addrspace(5) null, align 8
+ store i64 %arg19, ptr addrspace(5) null, align 8
+ store i64 %arg20, ptr addrspace(5) null, align 8
+ store i64 %arg21, ptr addrspace(5) null, align 8
+ store i64 %arg22, ptr addrspace(5) null, align 8
+ store i64 %arg23, ptr addrspace(5) null, align 8
+ store i64 %arg24, ptr addrspace(5) null, align 8
+ store i64 %arg25, ptr addrspace(5) null, align 8
+ store i64 %arg26, ptr addrspace(5) null, align 8
+ store i64 %arg27, ptr addrspace(5) null, align 8
+ store i64 %arg28, ptr addrspace(5) null, align 8
+ store i64 %arg29, ptr addrspace(5) null, align 8
+ store i64 %arg30, ptr addrspace(5) null, align 8
+ store i64 %arg31, ptr addrspace(5) null, align 8
+ store i64 %arg32, ptr addrspace(5) null, align 8
+ store i64 %arg33, ptr addrspace(5) null, align 8
+ store i64 %arg34, ptr addrspace(5) null, align 8
+ store i64 %arg35, ptr addrspace(5) null, align 8
+ store i64 %arg36, ptr addrspace(5) null, align 8
+ store i64 %arg37, ptr addrspace(5) null, align 8
+ store i64 %arg38, ptr addrspace(5) null, align 8
+ store i64 %arg39, ptr addrspace(5) null, align 8
+ store i64 %arg40, ptr addrspace(5) null, align 8
+ store i64 %arg41, ptr addrspace(5) null, align 8
+ store i64 %arg42, ptr addrspace(5) null, align 8
+ store i64 %arg43, ptr addrspace(5) null, align 8
+ store i64 %arg44, ptr addrspace(5) null, align 8
+ store i64 %arg45, ptr addrspace(5) null, align 8
+ store i64 %arg46, ptr addrspace(5) null, align 8
+ store i64 %arg47, ptr addrspace(5) null, align 8
+ store i64 %arg48, ptr addrspace(5) null, align 8
+ store i64 %arg49, ptr addrspace(5) null, align 8
+ ret void
+}
diff --git a/llvm/test/CodeGen/AMDGPU/local-stack-alloc-add-references.gfx10.mir b/llvm/test/CodeGen/AMDGPU/local-stack-alloc-add-references.gfx10.mir
index 8ea9ec397fe06..3be6456213168 100644
--- a/llvm/test/CodeGen/AMDGPU/local-stack-alloc-add-references.gfx10.mir
+++ b/llvm/test/CodeGen/AMDGPU/local-stack-alloc-add-references.gfx10.mir
@@ -49,15 +49,15 @@ machineFunctionInfo:
body: |
bb.0:
; GFX10-LABEL: name: local_stack_alloc__v_add_u32_e64__literal_offsets_commute
- ; GFX10: [[S_MOV_B32_:%[0-9]+]]:sreg_32_xm0 = S_MOV_B32 256
+ ; GFX10: [[S_MOV_B32_:%[0-9]+]]:sreg_32_xm0 = S_MOV_B32 100
; GFX10-NEXT: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 %stack.0, implicit $exec
; GFX10-NEXT: [[V_ADD_U32_e64_:%[0-9]+]]:vgpr_32 = V_ADD_U32_e64 killed [[S_MOV_B32_]], [[V_MOV_B32_e32_]], 0, implicit $exec
- ; GFX10-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY [[V_ADD_U32_e64_]]
- ; GFX10-NEXT: INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 1245193 /* reguse:VGPR_32 */, [[COPY]]
- ; GFX10-NEXT: [[V_ADD_U32_e64_1:%[0-9]+]]:vgpr_32 = V_ADD_U32_e64 256, [[V_ADD_U32_e64_]], 0, implicit $exec
+ ; GFX10-NEXT: [[V_ADD_U32_e64_1:%[0-9]+]]:vgpr_32 = V_ADD_U32_e64 156, [[V_ADD_U32_e64_]], 0, implicit $exec
; GFX10-NEXT: INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 1245193 /* reguse:VGPR_32 */, [[V_ADD_U32_e64_1]]
- ; GFX10-NEXT: [[V_ADD_U32_e64_2:%[0-9]+]]:vgpr_32 = V_ADD_U32_e64 [[V_ADD_U32_e64_]], -156, 0, implicit $exec
+ ; GFX10-NEXT: [[V_ADD_U32_e64_2:%[0-9]+]]:vgpr_32 = V_ADD_U32_e64 412, [[V_ADD_U32_e64_]], 0, implicit $exec
; GFX10-NEXT: INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 1245193 /* reguse:VGPR_32 */, [[V_ADD_U32_e64_2]]
+ ; GFX10-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY [[V_ADD_U32_e64_]]
+ ; GFX10-NEXT: INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 1245193 /* reguse:VGPR_32 */, [[COPY]]
; GFX10-NEXT: SI_RETURN
;
; GFX12-LABEL: name: local_stack_alloc__v_add_u32_e64__literal_offsets_commute
diff --git a/llvm/test/CodeGen/AMDGPU/local-stack-alloc-block-sp-reference.ll b/llvm/test/CodeGen/AMDGPU/local-stack-alloc-block-sp-reference.ll
index 5f0ca7bc42ae0..3d02d70d2fdbb 100644
--- a/llvm/test/CodeGen/AMDGPU/local-stack-alloc-block-sp-reference.ll
+++ b/llvm/test/CodeGen/AMDGPU/local-stack-alloc-block-sp-reference.ll
@@ -294,12 +294,13 @@ define amdgpu_kernel void @local_stack_offset_uses_sp_flat(ptr addrspace(1) %out
; FLATSCR-NEXT: s_add_u32 flat_scratch_lo, s8, s13
; FLATSCR-NEXT: s_addc_u32 flat_scratch_hi, s9, 0
; FLATSCR-NEXT: v_mov_b32_e32 v0, 0
-; FLATSCR-NEXT: s_mov_b32 s0, 0
-; FLATSCR-NEXT: scratch_store_dword off, v0, s0 offset:1024
+; FLATSCR-NEXT: s_movk_i32 s0, 0x2000
+; FLATSCR-NEXT: scratch_store_dword off, v0, s0
; FLATSCR-NEXT: s_waitcnt vmcnt(0)
+; FLATSCR-NEXT: s_mov_b32 s0, 0
; FLATSCR-NEXT: .LBB2_1: ; %loadstoreloop
; FLATSCR-NEXT: ; =>This Inner Loop Header: Depth=1
-; FLATSCR-NEXT: s_add_i32 s1, s0, 0x2000
+; FLATSCR-NEXT: s_add_i32 s1, s0, 0x4000
; FLATSCR-NEXT: s_add_i32 s0, s0, 1
; FLATSCR-NEXT: s_cmpk_lt_u32 s0, 0x2120
; FLATSCR-NEXT: scratch_store_byte off, v0, s1
@@ -307,12 +308,12 @@ define amdgpu_kernel void @local_stack_offset_uses_sp_flat(ptr addrspace(1) %out
; FLATSCR-NEXT: s_cbranch_scc1 .LBB2_1
; FLATSCR-NEXT: ; %bb.2: ; %split
; FLATSCR-NEXT: s_movk_i32 s0, 0x1000
-; FLATSCR-NEXT: s_addk_i32 s0, 0x2000
+; FLATSCR-NEXT: s_addk_i32 s0, 0x4000
; FLATSCR-NEXT: scratch_load_dwordx2 v[8:9], off, s0 offset:720 glc
; FLATSCR-NEXT: s_waitcnt vmcnt(0)
; FLATSCR-NEXT: scratch_load_dwordx4 v[0:3], off, s0 offset:704 glc
; FLATSCR-NEXT: s_waitcnt vmcnt(0)
-; FLATSCR-NEXT: s_movk_i32 s0, 0x2000
+; FLATSCR-NEXT: s_movk_i32 s0, 0x4000
; FLATSCR-NEXT: scratch_load_dwordx2 v[10:11], off, s0 offset:16 glc
; FLATSCR-NEXT: s_waitcnt vmcnt(0)
; FLATSCR-NEXT: scratch_load_dwordx4 v[4:7], off, s0 glc
>From 228ad57974c3494b4c4ec00ce7ce50477521181d Mon Sep 17 00:00:00 2001
From: Anshil Gandhi <95053726+gandhi56 at users.noreply.github.com>
Date: Thu, 27 Nov 2025 10:10:19 -0500
Subject: [PATCH 2/3] Update llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
Co-authored-by: Jay Foad <jay.foad at gmail.com>
---
llvm/lib/CodeGen/LocalStackSlotAllocation.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
index 402b285f53b7e..9b4c1a5d1c694 100644
--- a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -66,8 +66,8 @@ namespace {
Order(Ord) {}
bool operator<(const FrameRef &RHS) const {
- return std::make_tuple(LocalOffset + InstOffset, FrameIdx, Order) <
- std::make_tuple(RHS.LocalOffset + RHS.InstOffset, RHS.FrameIdx,
+ return std::tuple(LocalOffset + InstOffset, FrameIdx, Order) <
+ std::tuple(RHS.LocalOffset + RHS.InstOffset, RHS.FrameIdx,
RHS.Order);
}
>From 65377c303c781c19e8d414e222c66afca3584f6c Mon Sep 17 00:00:00 2001
From: Anshil Gandhi <95053726+gandhi56 at users.noreply.github.com>
Date: Thu, 27 Nov 2025 10:10:27 -0500
Subject: [PATCH 3/3] Update llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
Co-authored-by: Jay Foad <jay.foad at gmail.com>
---
llvm/lib/CodeGen/LocalStackSlotAllocation.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
index 9b4c1a5d1c694..44b1532fc1900 100644
--- a/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ b/llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -352,8 +352,8 @@ bool LocalStackSlotImpl::insertFrameReferenceRegisters(MachineFunction &Fn) {
break;
int64_t InstOffset =
TRI->getFrameIndexInstrOffset(&MI, MO.getOperandNo());
- FrameReferenceInsns.push_back(
- FrameRef(&MI, LocalOffset, Idx, InstOffset, Order++));
+ FrameReferenceInsns.emplace_back(
+ &MI, LocalOffset, Idx, InstOffset, Order++);
break;
}
}
More information about the llvm-commits
mailing list