@@ -81,6 +81,10 @@ static cl::opt<bool> EnableRISCVCopyPropagation(
81
81
" riscv-enable-copy-propagation" ,
82
82
cl::desc (" Enable the copy propagation with RISC-V copy instr" ),
83
83
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 ));
84
88
85
89
static cl::opt<bool > EnableRISCVDeadRegisterElimination (
86
90
" riscv-enable-dead-defs" , cl::Hidden,
@@ -373,7 +377,6 @@ class RISCVPassConfig : public TargetPassConfig {
373
377
if (!ST.getMacroFusions ().empty ()) {
374
378
DAG = DAG ? DAG : createGenericSchedLive (C);
375
379
376
- const RISCVSubtarget &ST = C->MF ->getSubtarget <RISCVSubtarget>();
377
380
if (ST.useLoadStorePairs ()) {
378
381
DAG->addMutation (createLoadClusterDAGMutation (DAG->TII , DAG->TRI ));
379
382
DAG->addMutation (createStoreClusterDAGMutation (DAG->TII , DAG->TRI ));
@@ -466,6 +469,16 @@ void RISCVPassConfig::addIRPasses() {
466
469
addPass (createAtomicExpandLegacyPass ());
467
470
addPass (createRISCVZacasABIFixPass ());
468
471
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
+
469
482
if (getOptLevel () != CodeGenOptLevel::None) {
470
483
if (EnableLoopDataPrefetch)
471
484
addPass (createLoopDataPrefetchPass ());
0 commit comments