Skip to content

Commit e72876a

Browse files
authored
[RISCV] Mask integer and float loads as canFoldAsLoad for stackmaps (#165761)
We have two mechanisms used in inline spilled for folding a load into a consuming instruction. One is used for stack reloads, the other for other load instructions (usually argument loads). We currently only implement optimizations for the first case, but stackmaps have generic support in target independent code for the other. We can go ahead and set the flag to enable that optimization. The primary motivation for this is that if we enable load rematerialization without it, we run into crashes where we can't make progress through rematerialization. We probably should enable the other foldMemoryOperand hook for RISCV specific instructions, but that's a separate optimization.
1 parent 8f7efa0 commit e72876a

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ std::optional<unsigned> getFoldedOpcode(MachineFunction &MF, MachineInstr &MI,
869869
}
870870
}
871871

872-
// This is the version used during inline spilling
872+
// This is the version used during InlineSpiller::spillAroundUses
873873
MachineInstr *RISCVInstrInfo::foldMemoryOperandImpl(
874874
MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops,
875875
MachineBasicBlock::iterator InsertPt, int FrameIndex, LiveIntervals *LIS,

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def BGE : BranchCC_rri<0b101, "bge">;
768768
def BLTU : BranchCC_rri<0b110, "bltu">;
769769
def BGEU : BranchCC_rri<0b111, "bgeu">;
770770

771-
let IsSignExtendingOpW = 1 in {
771+
let IsSignExtendingOpW = 1, canFoldAsLoad = 1 in {
772772
def LB : Load_ri<0b000, "lb">, Sched<[WriteLDB, ReadMemBase]>;
773773
def LH : Load_ri<0b001, "lh">, Sched<[WriteLDH, ReadMemBase]>;
774774
def LW : Load_ri<0b010, "lw">, Sched<[WriteLDW, ReadMemBase]>;
@@ -889,8 +889,10 @@ def CSRRCI : CSR_ii<0b111, "csrrci">;
889889
/// RV64I instructions
890890

891891
let Predicates = [IsRV64] in {
892+
let canFoldAsLoad = 1 in {
892893
def LWU : Load_ri<0b110, "lwu">, Sched<[WriteLDW, ReadMemBase]>;
893894
def LD : Load_ri<0b011, "ld">, Sched<[WriteLDD, ReadMemBase]>;
895+
}
894896
def SD : Store_rri<0b011, "sd">, Sched<[WriteSTD, ReadStoreData, ReadMemBase]>;
895897

896898
let IsSignExtendingOpW = 1 in {

llvm/lib/Target/RISCV/RISCVInstrInfoD.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ defvar DExtsRV64 = [DExt, ZdinxExt];
7171
//===----------------------------------------------------------------------===//
7272

7373
let Predicates = [HasStdExtD] in {
74+
let canFoldAsLoad = 1 in
7475
def FLD : FPLoad_r<0b011, "fld", FPR64, WriteFLD64>;
7576

7677
// Operands for stores are in the order srcreg, base, offset rather than

llvm/lib/Target/RISCV/RISCVInstrInfoF.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class PseudoFROUND<DAGOperand Ty, ValueType vt, ValueType intvt = XLenVT>
330330
//===----------------------------------------------------------------------===//
331331

332332
let Predicates = [HasStdExtF] in {
333+
let canFoldAsLoad = 1 in
333334
def FLW : FPLoad_r<0b010, "flw", FPR32, WriteFLD32>;
334335

335336
// Operands for stores are in the order srcreg, base, offset rather than

llvm/test/CodeGen/RISCV/rv64-stackmap.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
; CHECK-NEXT: .quad liveConstant
3939
; CHECK-NEXT: .quad 0
4040
; CHECK-NEXT: .quad 1
41-
; CHECK-NEXT: .quad spilledValue
42-
; CHECK-NEXT: .quad 144
41+
; CHECK-NEXT: .quad liveArgs
42+
; CHECK-NEXT: .quad 0
4343
; CHECK-NEXT: .quad 1
4444
; CHECK-NEXT: .quad directFrameIdx
4545
; CHECK-NEXT: .quad 48
@@ -278,7 +278,7 @@ define void @liveConstant() {
278278
;
279279
; Verify 28 stack map entries.
280280
;
281-
; CHECK-LABEL: .word .L{{.*}}-spilledValue
281+
; CHECK-LABEL: .word .L{{.*}}-liveArgs
282282
; CHECK-NEXT: .half 0
283283
; CHECK-NEXT: .half 28
284284
;
@@ -290,7 +290,7 @@ define void @liveConstant() {
290290
; CHECK-NEXT: .half 2
291291
; CHECK-NEXT: .half 0
292292
; CHECK-NEXT: .word
293-
define void @spilledValue(i64 %arg0, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i8 %l25, i16 zeroext %l26, i32 signext %l27) {
293+
define void @liveArgs(i64 %arg0, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i8 %l25, i16 zeroext %l26, i32 signext %l27) {
294294
entry:
295295
call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 11, i32 28, ptr null, i32 5, i64 %arg0, i64 %arg1, i64 %arg2, i64 %arg3, i64 %arg4, i64 %l0, i64 %l1, i64 %l2, i64 %l3, i64 %l4, i64 %l5, i64 %l6, i64 %l7, i64 %l8, i64 %l9, i64 %l10, i64 %l11, i64 %l12, i64 %l13, i64 %l14, i64 %l15, i64 %l16, i64 %l17, i64 %l18, i64 %l19, i64 %l20, i64 %l21, i64 %l22, i64 %l23, i64 %l24, i8 %l25, i16 %l26, i32 %l27)
296296
ret void

0 commit comments

Comments
 (0)