Index: llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h =================================================================== --- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -230,6 +230,7 @@ const Target *MArch = nullptr; std::string TripleStr; unsigned OptLevel = 2; + unsigned SizeLevel = 0; lto_diagnostic_handler_t DiagHandler = nullptr; void *DiagContext = nullptr; bool ShouldInternalize = EnableLTOInternalization; Index: llvm/lib/LTO/LTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/LTOCodeGenerator.cpp +++ llvm/lib/LTO/LTOCodeGenerator.cpp @@ -211,6 +211,10 @@ } void LTOCodeGenerator::setOptLevel(unsigned Level) { + if (Level > 3) { + SizeLevel = Level - 3; + Level = 2; + } OptLevel = Level; switch (OptLevel) { case 0: @@ -578,7 +582,7 @@ PassManagerBuilder PMB; PMB.LoopVectorize = true; PMB.SLPVectorize = true; - PMB.Inliner = createFunctionInliningPass(); + PMB.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false); PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple); if (Freestanding) PMB.LibraryInfo->disableAllFunctions(); Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -985,8 +985,9 @@ // Now that we internalized some globals, see if we can hack on them! PM.add(createGlobalOptimizerPass()); - // Promote any localized global vars. - PM.add(createPromoteMemoryToRegisterPass()); + // Break up allocas + PM.add(createSROAPass()); + PM.add(createEarlyCSEPass()); // Linking modules together can lead to duplicated global constants, only // keep one copy of each constant. @@ -1039,9 +1040,6 @@ addExtensionsToPM(EP_Peephole, PM); PM.add(createJumpThreadingPass(/*FreezeSelectCond*/ true)); - // Break up allocas - PM.add(createSROAPass()); - // LTO provides additional opportunities for tailcall elimination due to // link-time inlining, and visibility of nocapture attribute. if (OptLevel > 1) Index: llvm/tools/lto/lto.cpp =================================================================== --- llvm/tools/lto/lto.cpp +++ llvm/tools/lto/lto.cpp @@ -152,8 +152,12 @@ CG->setAttr(attrs); } - if (OptLevel < '0' || OptLevel > '3') - report_fatal_error("Optimization level must be between 0 and 3"); + if (OptLevel == 's') + OptLevel = '4'; + else if (OptLevel == 'z') + OptLevel = '5'; + if (OptLevel < '0' || OptLevel > '5') + report_fatal_error("Optimization level must be between 0 and 3 or Os or Oz"); CG->setOptLevel(OptLevel - '0'); CG->setFreestanding(EnableFreestanding); } @@ -502,8 +506,12 @@ CodeGen->setFreestanding(EnableFreestanding); if (OptLevel.getNumOccurrences()) { - if (OptLevel < '0' || OptLevel > '3') - report_fatal_error("Optimization level must be between 0 and 3"); + if (OptLevel == 's') + OptLevel = '4'; + else if (OptLevel == 'z') + OptLevel = '5'; + if (OptLevel < '0' || OptLevel > '5') + report_fatal_error("Optimization level must be between 0 and 3 or Os or Oz"); CodeGen->setOptLevel(OptLevel - '0'); switch (OptLevel) { case '0':