Skip to content

Commit 859c871

Browse files
authored
[RISCV] Default to MicroOpBufferSize = 1 for scheduling purposes (#126608)
This change introduces a default schedule model for the RISCV target which leaves everything unchanged except the MicroOpBufferSize. The default value of this flag in NoSched is 0. Both configurations represent in order cores (i.e. no reorder window), the difference between them comes down to whether heuristics other than latency are allowed to apply. (Implementation details below) I left the processor models which explicitly set MicroOpBufferSize=0 unchanged in this patch, but strongly suspect we should change those too. Honestly, I think the LLVM wide default for this flag should be changed, but don't have the energy to manage the updates for all targets. Implementation wise, the effect of this change is that schedule units which are ready to run *except that* one of their predecessors may not have completed yet are added to the Available list, not the Pending one. The result of this is that it becomes possible to chose to schedule a node before it's ready cycle if the heuristics prefer. This is essentially chosing to insert a resource stall instead of e.g. increasing register pressure. Note that I was initially concerned there might be a correctness aspect (as in some kind of exposed pipeline design), but the generic scheduler doesn't seem to know how to insert noop instructions. Without that, a program wouldn't be guaranteed to schedule on an exposed pipeline depending on the program and schedule model in question. The effect of this is that we sometimes prefer register pressure in codegen results. This is mostly churn (or small wins) on scalar because we have many more registers, but is of major importance on vector - particularly high LMUL - because we effectively have many fewer registers and the relative cost of spilling is much higher. This is a significant improvement on high LMUL code quality for default rva23u configurations - or any non -mcpu vector configuration for that matter. Fixes #107532
1 parent 7a7f919 commit 859c871

File tree

403 files changed

+27972
-29158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

403 files changed

+27972
-29158
lines changed

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,30 @@ class RISCVTuneProcessorModel<string n,
8888

8989
defvar GenericTuneFeatures = [TuneOptimizedNF2SegmentLoadStore];
9090

91+
// Adjust the default cost model to enable all heuristics, not just latency
92+
// In particular, this enables register pressure heustics which are very
93+
// important for high LMUL vector code, and have little negative impact
94+
// on other configurations,
95+
def GenericModel : SchedMachineModel {
96+
let MicroOpBufferSize = 1;
97+
let CompleteModel = 0;
98+
}
99+
91100
def GENERIC_RV32 : RISCVProcessorModel<"generic-rv32",
92-
NoSchedModel,
101+
GenericModel,
93102
[Feature32Bit,
94103
FeatureStdExtI],
95104
GenericTuneFeatures>,
96105
GenericTuneInfo;
97106
def GENERIC_RV64 : RISCVProcessorModel<"generic-rv64",
98-
NoSchedModel,
107+
GenericModel,
99108
[Feature64Bit,
100109
FeatureStdExtI],
101110
GenericTuneFeatures>,
102111
GenericTuneInfo;
103112
// Support generic for compatibility with other targets. The triple will be used
104113
// to change to the appropriate rv32/rv64 version.
105-
def GENERIC : RISCVTuneProcessorModel<"generic", NoSchedModel>, GenericTuneInfo;
114+
def GENERIC : RISCVTuneProcessorModel<"generic", GenericModel>, GenericTuneInfo;
106115

107116
def MIPS_P8700 : RISCVProcessorModel<"mips-p8700",
108117
MIPSP8700Model,
@@ -496,7 +505,7 @@ def TENSTORRENT_ASCALON_D8 : RISCVProcessorModel<"tt-ascalon-d8",
496505
TunePostRAScheduler]>;
497506

498507
def VENTANA_VEYRON_V1 : RISCVProcessorModel<"veyron-v1",
499-
NoSchedModel,
508+
GenericModel,
500509
[Feature64Bit,
501510
FeatureStdExtI,
502511
FeatureStdExtZifencei,
@@ -556,7 +565,7 @@ def XIANGSHAN_NANHU : RISCVProcessorModel<"xiangshan-nanhu",
556565
TuneShiftedZExtWFusion]>;
557566

558567
def SPACEMIT_X60 : RISCVProcessorModel<"spacemit-x60",
559-
NoSchedModel,
568+
GenericModel,
560569
!listconcat(RVA22S64Features,
561570
[FeatureStdExtV,
562571
FeatureStdExtSscofpmf,
@@ -581,7 +590,7 @@ def SPACEMIT_X60 : RISCVProcessorModel<"spacemit-x60",
581590
}
582591

583592
def RP2350_HAZARD3 : RISCVProcessorModel<"rp2350-hazard3",
584-
NoSchedModel,
593+
GenericModel,
585594
[Feature32Bit,
586595
FeatureStdExtI,
587596
FeatureStdExtM,

llvm/test/CodeGen/RISCV/GlobalISel/add-imm.ll

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,30 +212,30 @@ define i64 @add64_accept(i64 %a) nounwind {
212212
define void @add32_reject() nounwind {
213213
; RV32I-LABEL: add32_reject:
214214
; RV32I: # %bb.0:
215-
; RV32I-NEXT: lui a0, %hi(ga)
216-
; RV32I-NEXT: lui a1, %hi(gb)
217-
; RV32I-NEXT: lw a2, %lo(ga)(a0)
218-
; RV32I-NEXT: lw a3, %lo(gb)(a1)
219-
; RV32I-NEXT: lui a4, 1
220-
; RV32I-NEXT: addi a4, a4, -1096
221-
; RV32I-NEXT: add a2, a2, a4
222-
; RV32I-NEXT: add a3, a3, a4
223-
; RV32I-NEXT: sw a2, %lo(ga)(a0)
224-
; RV32I-NEXT: sw a3, %lo(gb)(a1)
215+
; RV32I-NEXT: lui a0, 1
216+
; RV32I-NEXT: lui a1, %hi(ga)
217+
; RV32I-NEXT: lui a2, %hi(gb)
218+
; RV32I-NEXT: lw a3, %lo(ga)(a1)
219+
; RV32I-NEXT: lw a4, %lo(gb)(a2)
220+
; RV32I-NEXT: addi a0, a0, -1096
221+
; RV32I-NEXT: add a3, a3, a0
222+
; RV32I-NEXT: add a0, a4, a0
223+
; RV32I-NEXT: sw a3, %lo(ga)(a1)
224+
; RV32I-NEXT: sw a0, %lo(gb)(a2)
225225
; RV32I-NEXT: ret
226226
;
227227
; RV64I-LABEL: add32_reject:
228228
; RV64I: # %bb.0:
229-
; RV64I-NEXT: lui a0, %hi(ga)
230-
; RV64I-NEXT: lui a1, %hi(gb)
231-
; RV64I-NEXT: lw a2, %lo(ga)(a0)
232-
; RV64I-NEXT: lw a3, %lo(gb)(a1)
233-
; RV64I-NEXT: lui a4, 1
234-
; RV64I-NEXT: addi a4, a4, -1096
235-
; RV64I-NEXT: add a2, a2, a4
236-
; RV64I-NEXT: add a3, a3, a4
237-
; RV64I-NEXT: sw a2, %lo(ga)(a0)
238-
; RV64I-NEXT: sw a3, %lo(gb)(a1)
229+
; RV64I-NEXT: lui a0, 1
230+
; RV64I-NEXT: lui a1, %hi(ga)
231+
; RV64I-NEXT: lui a2, %hi(gb)
232+
; RV64I-NEXT: lw a3, %lo(ga)(a1)
233+
; RV64I-NEXT: lw a4, %lo(gb)(a2)
234+
; RV64I-NEXT: addi a0, a0, -1096
235+
; RV64I-NEXT: add a3, a3, a0
236+
; RV64I-NEXT: add a0, a4, a0
237+
; RV64I-NEXT: sw a3, %lo(ga)(a1)
238+
; RV64I-NEXT: sw a0, %lo(gb)(a2)
239239
; RV64I-NEXT: ret
240240
%1 = load i32, ptr @ga, align 4
241241
%2 = load i32, ptr @gb, align 4

0 commit comments

Comments
 (0)