diff --git a/llvm/lib/Target/RISCV/CMakeLists.txt b/llvm/lib/Target/RISCV/CMakeLists.txt --- a/llvm/lib/Target/RISCV/CMakeLists.txt +++ b/llvm/lib/Target/RISCV/CMakeLists.txt @@ -51,6 +51,7 @@ AsmPrinter Core IPO + Scalar CodeGen MC RISCVDesc diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp --- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp @@ -35,6 +35,7 @@ #include "llvm/Support/FormattedStream.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Transforms/IPO.h" +#include "llvm/Transforms/Scalar.h" using namespace llvm; static cl::opt EnableRedundantCopyElimination( @@ -42,6 +43,11 @@ cl::desc("Enable the redundant copy elimination pass"), cl::init(true), cl::Hidden); +static cl::opt + EnableGEPOpt("riscv-enable-gep-opt", cl::Hidden, + cl::desc("Enable optimizations on complex GEPs"), + cl::init(false)); + extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() { RegisterTargetMachine X(getTheRISCV32Target()); RegisterTargetMachine Y(getTheRISCV64Target()); @@ -191,10 +197,17 @@ if (getOptLevel() != CodeGenOpt::None) addPass(createRISCVGatherScatterLoweringPass()); - + if (TM->getOptLevel() == CodeGenOpt::Aggressive && EnableGEPOpt) { + addPass(createSeparateConstOffsetFromGEPPass(false)); + // Call EarlyCSE pass to find and remove subexpressions in the lowered + // result. + addPass(createEarlyCSEPass()); + // Do loop invariant code motion in case part of the lowered result is + // invariant. + addPass(createLICMPass()); + } if (getOptLevel() != CodeGenOpt::None) addPass(createRISCVCodeGenPreparePass()); - TargetPassConfig::addIRPasses(); }