@@ -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
8589static 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,6 +469,16 @@ void RISCVPassConfig::addIRPasses() {
466469 addPass (createAtomicExpandLegacyPass ());
467470 addPass (createRISCVZacasABIFixPass ());
468471
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+
469482 if (getOptLevel () != CodeGenOptLevel::None) {
470483 if (EnableLoopDataPrefetch)
471484 addPass (createLoopDataPrefetchPass ());
0 commit comments