Skip to content

Commit 9de5329

Browse files
committed
[RISCV] add load/store misched/PostRA cluster options
Some processors benefit more from store clustering than load clustering, and vice-versa, depending on factors that are exclusive to each one (e.g. macrofusions implemented). Likewise, certain optimizations benefits more from misched clustering than postRA clustering. Macrofusions are again an example: in a processor with store pair macrofusions, like the veyron-v1, it is observed that misched clustering increases the amount of macrofusions more than postRA clustering. This of course isn't necessarily true for other processors, but it shows that processors can benefit from a more fine grained control of clustering mutations, and each one is able to do it differently. Add 4 new clustering options that deprecates the existing riscv-misched-load-store-clustering and riscv-postmisched-load-store-clustering options: - riscv-misched-load-clustering and riscv-misched-store-clustering: enable/disable load/store clustering during misched; - riscv-postmisched-load-clustering and riscv-postmisched-store-clustering: enable/disable load/store clustering during PostRA. To preserve the existing clustering behavior all 4 options are defaulted to 'true'.
1 parent 73e4b58 commit 9de5329

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,24 @@ static cl::opt<bool>
9494
cl::desc("Enable the loop data prefetch pass"),
9595
cl::init(true));
9696

97-
static cl::opt<bool> EnableMISchedLoadStoreClustering(
98-
"riscv-misched-load-store-clustering", cl::Hidden,
99-
cl::desc("Enable load and store clustering in the machine scheduler"),
97+
static cl::opt<bool> EnableMISchedLoadClustering(
98+
"riscv-misched-load-clustering", cl::Hidden,
99+
cl::desc("Enable load clustering in the machine scheduler"),
100100
cl::init(true));
101101

102-
static cl::opt<bool> EnablePostMISchedLoadStoreClustering(
103-
"riscv-postmisched-load-store-clustering", cl::Hidden,
104-
cl::desc("Enable PostRA load and store clustering in the machine scheduler"),
102+
static cl::opt<bool> EnableMISchedStoreClustering(
103+
"riscv-misched-store-clustering", cl::Hidden,
104+
cl::desc("Enable store clustering in the machine scheduler"),
105+
cl::init(true));
106+
107+
static cl::opt<bool> EnablePostMISchedLoadClustering(
108+
"riscv-postmisched-load-clustering", cl::Hidden,
109+
cl::desc("Enable PostRA load clustering in the machine scheduler"),
110+
cl::init(true));
111+
112+
static cl::opt<bool> EnablePostMISchedStoreClustering(
113+
"riscv-postmisched-store-clustering", cl::Hidden,
114+
cl::desc("Enable PostRA store clustering in the machine scheduler"),
105115
cl::init(true));
106116

107117
static cl::opt<bool>
@@ -300,12 +310,14 @@ bool RISCVTargetMachine::isNoopAddrSpaceCast(unsigned SrcAS,
300310
ScheduleDAGInstrs *
301311
RISCVTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
302312
ScheduleDAGMILive *DAG = createSchedLive(C);
303-
if (EnableMISchedLoadStoreClustering) {
313+
314+
if (EnableMISchedLoadClustering)
304315
DAG->addMutation(createLoadClusterDAGMutation(
305316
DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
317+
318+
if (EnableMISchedStoreClustering)
306319
DAG->addMutation(createStoreClusterDAGMutation(
307320
DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
308-
}
309321

310322
const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
311323
if (!DisableVectorMaskMutation && ST.hasVInstructions())
@@ -317,12 +329,14 @@ RISCVTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
317329
ScheduleDAGInstrs *
318330
RISCVTargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
319331
ScheduleDAGMI *DAG = createSchedPostRA(C);
320-
if (EnablePostMISchedLoadStoreClustering) {
332+
333+
if (EnablePostMISchedLoadClustering)
321334
DAG->addMutation(createLoadClusterDAGMutation(
322335
DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
336+
337+
if (EnablePostMISchedStoreClustering)
323338
DAG->addMutation(createStoreClusterDAGMutation(
324339
DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
325-
}
326340

327341
return DAG;
328342
}

llvm/test/CodeGen/RISCV/misched-load-clustering.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
; REQUIRES: asserts
2-
; RUN: llc -mtriple=riscv32 -verify-misched -riscv-misched-load-store-clustering=false \
2+
; RUN: llc -mtriple=riscv32 -verify-misched -riscv-misched-load-clustering=false \
3+
; RUN: -riscv-misched-store-clustering=false \
34
; RUN: -debug-only=machine-scheduler -o - 2>&1 < %s \
45
; RUN: | FileCheck -check-prefix=NOCLUSTER %s
5-
; RUN: llc -mtriple=riscv64 -verify-misched -riscv-misched-load-store-clustering=false \
6+
; RUN: llc -mtriple=riscv64 -verify-misched -riscv-misched-load-clustering=false \
7+
; RUN: -riscv-misched-store-clustering=false \
68
; RUN: -debug-only=machine-scheduler -o - 2>&1 < %s \
79
; RUN: | FileCheck -check-prefix=NOCLUSTER %s
810
; RUN: llc -mtriple=riscv32 -verify-misched \

llvm/test/CodeGen/RISCV/misched-mem-clustering.mir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
22
# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -verify-misched -enable-post-misched=false \
3-
# RUN: -riscv-postmisched-load-store-clustering=false -debug-only=machine-scheduler \
3+
# RUN: -riscv-postmisched-load-clustering=false \
4+
# RUN: -riscv-postmisched-store-clustering=false -debug-only=machine-scheduler \
45
# RUN: -start-before=machine-scheduler -stop-after=postmisched -misched-regpressure=false -o - 2>&1 < %s \
56
# RUN: | FileCheck -check-prefix=NOPOSTMISCHED %s
67
# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -mattr=+use-postra-scheduler -verify-misched -enable-post-misched=true \
7-
# RUN: -riscv-postmisched-load-store-clustering=false -debug-only=machine-scheduler \
8+
# RUN: -riscv-postmisched-load-clustering=false \
9+
# RUN: -riscv-postmisched-store-clustering=false -debug-only=machine-scheduler \
810
# RUN: -start-before=machine-scheduler -stop-after=postmisched -misched-regpressure=false -o - 2>&1 < %s \
911
# RUN: | FileCheck -check-prefix=NOCLUSTER %s
1012
# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -mattr=+use-postra-scheduler -verify-misched -enable-post-misched=true \

0 commit comments

Comments
 (0)