Skip to content

Commit 64a7557

Browse files
djtodorodjtodoro
authored andcommitted
[RISCV] Enable SeparateConstOffsetFromGEPPass for RISC-V
We see benefits in terms of performance. CoreMark benchmarking demonstrates a 2.5% performance improvement.
1 parent 56adb1f commit 64a7557

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ static cl::opt<bool> EnableRISCVCopyPropagation(
8181
"riscv-enable-copy-propagation",
8282
cl::desc("Enable the copy propagation with RISC-V copy instr"),
8383
cl::init(true), cl::Hidden);
84+
static cl::opt<bool>
85+
EnableGEPOpt("riscv-enable-gep-opt", cl::Hidden,
86+
cl::desc("Enable optimizations on complex GEPs"),
87+
cl::init(false));
8488

8589
static cl::opt<bool> EnableRISCVDeadRegisterElimination(
8690
"riscv-enable-dead-defs", cl::Hidden,
@@ -373,7 +377,6 @@ class RISCVPassConfig : public TargetPassConfig {
373377
if (!ST.getMacroFusions().empty()) {
374378
DAG = DAG ? DAG : createGenericSchedLive(C);
375379

376-
const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
377380
if (ST.useLoadStorePairs()) {
378381
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
379382
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
@@ -466,7 +469,17 @@ void RISCVPassConfig::addIRPasses() {
466469
addPass(createAtomicExpandLegacyPass());
467470
addPass(createRISCVZacasABIFixPass());
468471

469-
if (getOptLevel() != CodeGenOptLevel::None) {
472+
if (TM->getOptLevel() == CodeGenOptLevel::Aggressive && EnableGEPOpt) {
473+
addPass(createSeparateConstOffsetFromGEPPass(false));
474+
// Call EarlyCSE pass to find and remove subexpressions in the lowered
475+
// result.
476+
addPass(createEarlyCSEPass());
477+
// Do loop invariant code motion in case part of the lowered result is
478+
// invariant.
479+
addPass(createLICMPass());
480+
}
481+
482+
if (getOptLevel() != CodeGenOptLevel::None){
470483
if (EnableLoopDataPrefetch)
471484
addPass(createLoopDataPrefetchPass());
472485

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llc -mtriple=riscv32 -O3 -riscv-enable-gep-opt=true -debug-pass=Structure < %s -o /dev/null 2>&1 | \
2+
; RUN: grep -v "Verify generated machine code" | \
3+
; RUN: FileCheck %s --check-prefixes=CHECK
4+
5+
6+
; REQUIRES: asserts
7+
8+
; CHECK-LABEL: Pass Arguments:
9+
; CHECK: Split GEPs to a variadic base and a constant offset for better CSE
10+

0 commit comments

Comments
 (0)