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 @@ -49,6 +49,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 @@ -34,6 +34,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( @@ -41,6 +42,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(true)); + extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() { RegisterTargetMachine X(getTheRISCV32Target()); RegisterTargetMachine Y(getTheRISCV64Target()); @@ -167,7 +173,15 @@ addPass(createAtomicExpandPass()); addPass(createRISCVGatherScatterLoweringPass()); - + if (TM->getOptLevel() == CodeGenOpt::Aggressive && EnableGEPOpt) { + addPass(createSeparateConstOffsetFromGEPPass(false, true)); + // 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()); + } TargetPassConfig::addIRPasses(); }