Skip to content

Commit 567ea42

Browse files
committed
fixup: do not rely on stack objects being 16B aligned
1 parent 1709d18 commit 567ea42

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

llvm/lib/Target/RISCV/RISCVLoadStoreOptimizer.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ bool RISCVLoadStoreOpt::tryToPairLdStInst(MachineBasicBlock::iterator &MBBI) {
144144

145145
// Merge two adjacent load/store instructions into a paired instruction
146146
// (LDP/SDP/SWP/LWP) if the effective address is 16-byte aligned. This function
147-
// selects the appropriate paired opcode, verifies that the memory operand (or
148-
// fixed-stack slot) is 16-byte aligned, and checks that the offset is valid. If
149-
// all conditions are met, it builds and inserts the paired instruction.
147+
// selects the appropriate paired opcode, verifies that the memory operand is
148+
// 16-byte aligned, and checks that the offset is valid. If all conditions are
149+
// met, it builds and inserts the paired instruction.
150150
bool RISCVLoadStoreOpt::tryConvertToLdStPair(
151151
MachineBasicBlock::iterator First, MachineBasicBlock::iterator Second) {
152152
unsigned PairOpc;
@@ -172,12 +172,6 @@ bool RISCVLoadStoreOpt::tryConvertToLdStPair(
172172
const MachineMemOperand *MMO = *First->memoperands_begin();
173173
Align MMOAlign = MMO->getAlign();
174174

175-
// The stack pointer shall be aligned to a 128-bit per ABI.
176-
if (const PseudoSourceValue *Source = MMO->getPseudoValue()) {
177-
if (Source->kind() == PseudoSourceValue::FixedStack)
178-
MMOAlign = MF->getSubtarget().getFrameLowering()->getStackAlign();
179-
}
180-
181175
// Only pair if alignment is exactly 16 bytes.
182176
if (MMOAlign != 16)
183177
return false;

llvm/test/CodeGen/RISCV/load-store-pair.ll

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
145145
; RV32I_PAIR: # %bb.0: # %entry
146146
; RV32I_PAIR-NEXT: addi sp, sp, -16
147147
; RV32I_PAIR-NEXT: .cfi_def_cfa_offset 16
148-
; RV32I_PAIR-NEXT: mips.swp s3, s2, 8(sp) # 8-byte Folded Spill
149-
; RV32I_PAIR-NEXT: mips.swp s5, s4, 0(sp) # 8-byte Folded Spill
148+
; RV32I_PAIR-NEXT: sw s3, 8(sp) # 4-byte Folded Spill
149+
; RV32I_PAIR-NEXT: sw s2, 12(sp) # 4-byte Folded Spill
150+
; RV32I_PAIR-NEXT: sw s5, 0(sp) # 4-byte Folded Spill
151+
; RV32I_PAIR-NEXT: sw s4, 4(sp) # 4-byte Folded Spill
150152
; RV32I_PAIR-NEXT: .cfi_offset s2, -4
151153
; RV32I_PAIR-NEXT: .cfi_offset s3, -8
152154
; RV32I_PAIR-NEXT: .cfi_offset s4, -12
@@ -155,8 +157,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
155157
; RV32I_PAIR-NEXT: mips.lwp s5, s4, 8(a0)
156158
; RV32I_PAIR-NEXT: #APP
157159
; RV32I_PAIR-NEXT: #NO_APP
158-
; RV32I_PAIR-NEXT: mips.lwp s3, s2, 8(sp) # 8-byte Folded Reload
159-
; RV32I_PAIR-NEXT: mips.lwp s5, s4, 0(sp) # 8-byte Folded Reload
160+
; RV32I_PAIR-NEXT: lw s3, 8(sp) # 4-byte Folded Reload
161+
; RV32I_PAIR-NEXT: lw s2, 12(sp) # 4-byte Folded Reload
162+
; RV32I_PAIR-NEXT: lw s5, 0(sp) # 4-byte Folded Reload
163+
; RV32I_PAIR-NEXT: lw s4, 4(sp) # 4-byte Folded Reload
160164
; RV32I_PAIR-NEXT: .cfi_restore s2
161165
; RV32I_PAIR-NEXT: .cfi_restore s3
162166
; RV32I_PAIR-NEXT: .cfi_restore s4
@@ -169,8 +173,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
169173
; RV32D_PAIR: # %bb.0: # %entry
170174
; RV32D_PAIR-NEXT: addi sp, sp, -16
171175
; RV32D_PAIR-NEXT: .cfi_def_cfa_offset 16
172-
; RV32D_PAIR-NEXT: mips.swp s3, s2, 8(sp) # 8-byte Folded Spill
173-
; RV32D_PAIR-NEXT: mips.swp s5, s4, 0(sp) # 8-byte Folded Spill
176+
; RV32D_PAIR-NEXT: sw s3, 8(sp) # 4-byte Folded Spill
177+
; RV32D_PAIR-NEXT: sw s2, 12(sp) # 4-byte Folded Spill
178+
; RV32D_PAIR-NEXT: sw s5, 0(sp) # 4-byte Folded Spill
179+
; RV32D_PAIR-NEXT: sw s4, 4(sp) # 4-byte Folded Spill
174180
; RV32D_PAIR-NEXT: .cfi_offset s2, -4
175181
; RV32D_PAIR-NEXT: .cfi_offset s3, -8
176182
; RV32D_PAIR-NEXT: .cfi_offset s4, -12
@@ -179,8 +185,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
179185
; RV32D_PAIR-NEXT: mips.lwp s5, s4, 8(a0)
180186
; RV32D_PAIR-NEXT: #APP
181187
; RV32D_PAIR-NEXT: #NO_APP
182-
; RV32D_PAIR-NEXT: mips.lwp s3, s2, 8(sp) # 8-byte Folded Reload
183-
; RV32D_PAIR-NEXT: mips.lwp s5, s4, 0(sp) # 8-byte Folded Reload
188+
; RV32D_PAIR-NEXT: lw s3, 8(sp) # 4-byte Folded Reload
189+
; RV32D_PAIR-NEXT: lw s2, 12(sp) # 4-byte Folded Reload
190+
; RV32D_PAIR-NEXT: lw s5, 0(sp) # 4-byte Folded Reload
191+
; RV32D_PAIR-NEXT: lw s4, 4(sp) # 4-byte Folded Reload
184192
; RV32D_PAIR-NEXT: .cfi_restore s2
185193
; RV32D_PAIR-NEXT: .cfi_restore s3
186194
; RV32D_PAIR-NEXT: .cfi_restore s4
@@ -193,8 +201,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
193201
; RV64I_PAIR: # %bb.0: # %entry
194202
; RV64I_PAIR-NEXT: addi sp, sp, -32
195203
; RV64I_PAIR-NEXT: .cfi_def_cfa_offset 32
196-
; RV64I_PAIR-NEXT: mips.sdp s3, s2, 16(sp) # 16-byte Folded Spill
197-
; RV64I_PAIR-NEXT: mips.sdp s5, s4, 0(sp) # 16-byte Folded Spill
204+
; RV64I_PAIR-NEXT: sd s3, 16(sp) # 8-byte Folded Spill
205+
; RV64I_PAIR-NEXT: sd s2, 24(sp) # 8-byte Folded Spill
206+
; RV64I_PAIR-NEXT: sd s5, 0(sp) # 8-byte Folded Spill
207+
; RV64I_PAIR-NEXT: sd s4, 8(sp) # 8-byte Folded Spill
198208
; RV64I_PAIR-NEXT: .cfi_offset s2, -8
199209
; RV64I_PAIR-NEXT: .cfi_offset s3, -16
200210
; RV64I_PAIR-NEXT: .cfi_offset s4, -24
@@ -203,8 +213,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
203213
; RV64I_PAIR-NEXT: mips.ldp s5, s4, 16(a0)
204214
; RV64I_PAIR-NEXT: #APP
205215
; RV64I_PAIR-NEXT: #NO_APP
206-
; RV64I_PAIR-NEXT: mips.ldp s3, s2, 16(sp) # 16-byte Folded Reload
207-
; RV64I_PAIR-NEXT: mips.ldp s5, s4, 0(sp) # 16-byte Folded Reload
216+
; RV64I_PAIR-NEXT: ld s3, 16(sp) # 8-byte Folded Reload
217+
; RV64I_PAIR-NEXT: ld s2, 24(sp) # 8-byte Folded Reload
218+
; RV64I_PAIR-NEXT: ld s5, 0(sp) # 8-byte Folded Reload
219+
; RV64I_PAIR-NEXT: ld s4, 8(sp) # 8-byte Folded Reload
208220
; RV64I_PAIR-NEXT: .cfi_restore s2
209221
; RV64I_PAIR-NEXT: .cfi_restore s3
210222
; RV64I_PAIR-NEXT: .cfi_restore s4
@@ -217,8 +229,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
217229
; RV64P_8700: # %bb.0: # %entry
218230
; RV64P_8700-NEXT: addi sp, sp, -32
219231
; RV64P_8700-NEXT: .cfi_def_cfa_offset 32
220-
; RV64P_8700-NEXT: mips.sdp s3, s2, 16(sp) # 16-byte Folded Spill
221-
; RV64P_8700-NEXT: mips.sdp s5, s4, 0(sp) # 16-byte Folded Spill
232+
; RV64P_8700-NEXT: sd s3, 16(sp) # 8-byte Folded Spill
233+
; RV64P_8700-NEXT: sd s2, 24(sp) # 8-byte Folded Spill
234+
; RV64P_8700-NEXT: sd s5, 0(sp) # 8-byte Folded Spill
235+
; RV64P_8700-NEXT: sd s4, 8(sp) # 8-byte Folded Spill
222236
; RV64P_8700-NEXT: .cfi_offset s2, -8
223237
; RV64P_8700-NEXT: .cfi_offset s3, -16
224238
; RV64P_8700-NEXT: .cfi_offset s4, -24
@@ -227,8 +241,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
227241
; RV64P_8700-NEXT: mips.ldp s5, s4, 16(a0)
228242
; RV64P_8700-NEXT: #APP
229243
; RV64P_8700-NEXT: #NO_APP
230-
; RV64P_8700-NEXT: mips.ldp s3, s2, 16(sp) # 16-byte Folded Reload
231-
; RV64P_8700-NEXT: mips.ldp s5, s4, 0(sp) # 16-byte Folded Reload
244+
; RV64P_8700-NEXT: ld s3, 16(sp) # 8-byte Folded Reload
245+
; RV64P_8700-NEXT: ld s2, 24(sp) # 8-byte Folded Reload
246+
; RV64P_8700-NEXT: ld s5, 0(sp) # 8-byte Folded Reload
247+
; RV64P_8700-NEXT: ld s4, 8(sp) # 8-byte Folded Reload
232248
; RV64P_8700-NEXT: .cfi_restore s2
233249
; RV64P_8700-NEXT: .cfi_restore s3
234250
; RV64P_8700-NEXT: .cfi_restore s4
@@ -241,8 +257,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
241257
; RV64D_PAIR: # %bb.0: # %entry
242258
; RV64D_PAIR-NEXT: addi sp, sp, -32
243259
; RV64D_PAIR-NEXT: .cfi_def_cfa_offset 32
244-
; RV64D_PAIR-NEXT: mips.sdp s3, s2, 16(sp) # 16-byte Folded Spill
245-
; RV64D_PAIR-NEXT: mips.sdp s5, s4, 0(sp) # 16-byte Folded Spill
260+
; RV64D_PAIR-NEXT: sd s3, 16(sp) # 8-byte Folded Spill
261+
; RV64D_PAIR-NEXT: sd s2, 24(sp) # 8-byte Folded Spill
262+
; RV64D_PAIR-NEXT: sd s5, 0(sp) # 8-byte Folded Spill
263+
; RV64D_PAIR-NEXT: sd s4, 8(sp) # 8-byte Folded Spill
246264
; RV64D_PAIR-NEXT: .cfi_offset s2, -8
247265
; RV64D_PAIR-NEXT: .cfi_offset s3, -16
248266
; RV64D_PAIR-NEXT: .cfi_offset s4, -24
@@ -251,8 +269,10 @@ define dso_local void @testi(i8** nocapture noundef readonly %a) local_unnamed_a
251269
; RV64D_PAIR-NEXT: mips.ldp s5, s4, 16(a0)
252270
; RV64D_PAIR-NEXT: #APP
253271
; RV64D_PAIR-NEXT: #NO_APP
254-
; RV64D_PAIR-NEXT: mips.ldp s3, s2, 16(sp) # 16-byte Folded Reload
255-
; RV64D_PAIR-NEXT: mips.ldp s5, s4, 0(sp) # 16-byte Folded Reload
272+
; RV64D_PAIR-NEXT: ld s3, 16(sp) # 8-byte Folded Reload
273+
; RV64D_PAIR-NEXT: ld s2, 24(sp) # 8-byte Folded Reload
274+
; RV64D_PAIR-NEXT: ld s5, 0(sp) # 8-byte Folded Reload
275+
; RV64D_PAIR-NEXT: ld s4, 8(sp) # 8-byte Folded Reload
256276
; RV64D_PAIR-NEXT: .cfi_restore s2
257277
; RV64D_PAIR-NEXT: .cfi_restore s3
258278
; RV64D_PAIR-NEXT: .cfi_restore s4

0 commit comments

Comments
 (0)