Skip to content

Commit 6017bfc

Browse files
committed
[RISCV] Override default sched policy
This is based on other targets like PPC/AArch64 and some experiments. Disclaimer: I haven't tested it on many cores, maybe we should make some options being features. I believe downstreams must have tried this before, so feedbacks are welcome.
1 parent 4f3bf1c commit 6017bfc

File tree

114 files changed

+4476
-4679
lines changed

Some content is hidden

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

114 files changed

+4476
-4679
lines changed

llvm/lib/Target/RISCV/RISCVSubtarget.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "RISCV.h"
1717
#include "RISCVFrameLowering.h"
1818
#include "RISCVTargetMachine.h"
19+
#include "llvm/CodeGen/MachineScheduler.h"
1920
#include "llvm/CodeGen/MacroFusion.h"
2021
#include "llvm/CodeGen/ScheduleDAGMutation.h"
2122
#include "llvm/MC/TargetRegistry.h"
@@ -199,3 +200,25 @@ unsigned RISCVSubtarget::getMinimumJumpTableEntries() const {
199200
? RISCVMinimumJumpTableEntries
200201
: TuneInfo->MinimumJumpTableEntries;
201202
}
203+
204+
void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
205+
unsigned NumRegionInstrs) const {
206+
// Do bidirectional scheduling since it provides a more balanced scheduling
207+
// leading to better performance. This will increase compile time.
208+
Policy.OnlyTopDown = false;
209+
Policy.OnlyBottomUp = false;
210+
211+
// Enabling or Disabling the latency heuristic is a close call: It seems to
212+
// help nearly no benchmark on out-of-order architectures, on the other hand
213+
// it regresses register pressure on a few benchmarking.
214+
// FIXME: This is from AArch64, but we haven't evaluated it on RISC-V.
215+
Policy.DisableLatencyHeuristic = true;
216+
217+
// Spilling is generally expensive on all RISC-V cores, so always enable
218+
// register-pressure tracking. This will increase compile time.
219+
Policy.ShouldTrackPressure = true;
220+
221+
// Enabling ShouldTrackLaneMasks when vector instructions are supported.
222+
// TODO: Add extensions that need register pairs as well?
223+
Policy.ShouldTrackLaneMasks = hasVInstructions();
224+
}

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
327327
unsigned getTailDupAggressiveThreshold() const {
328328
return TuneInfo->TailDupAggressiveThreshold;
329329
}
330+
331+
void overrideSchedPolicy(MachineSchedPolicy &Policy,
332+
unsigned NumRegionInstrs) const override;
330333
};
331334
} // End llvm namespace
332335

llvm/test/CodeGen/RISCV/GlobalISel/rv64zbb.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,13 @@ define signext i32 @ffs_i32(i32 signext %a) nounwind {
583583
; RV64I-NEXT: call __muldi3
584584
; RV64I-NEXT: slli s0, s0, 32
585585
; RV64I-NEXT: srli s0, s0, 32
586-
; RV64I-NEXT: mv a1, a0
587-
; RV64I-NEXT: li a0, 0
586+
; RV64I-NEXT: li a1, 0
588587
; RV64I-NEXT: beqz s0, .LBB9_2
589588
; RV64I-NEXT: # %bb.1:
590-
; RV64I-NEXT: srliw a0, a1, 24
591-
; RV64I-NEXT: addiw a0, a0, 1
589+
; RV64I-NEXT: srliw a1, a0, 24
590+
; RV64I-NEXT: addiw a1, a1, 1
592591
; RV64I-NEXT: .LBB9_2:
592+
; RV64I-NEXT: mv a0, a1
593593
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
594594
; RV64I-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
595595
; RV64I-NEXT: addi sp, sp, 16

0 commit comments

Comments
 (0)