[llvm] r232769 - libLTO, llvm-lto, gold: Introduce flag for controlling optimization level.

Ahmed Bougacha ahmed.bougacha at gmail.com
Mon Mar 23 15:05:31 PDT 2015


On Mon, Mar 23, 2015 at 3:00 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
> On Mon, Mar 23, 2015 at 02:52:41PM -0700, Ahmed Bougacha wrote:
>> On Thu, Mar 19, 2015 at 3:01 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
>> > +static cl::opt<char>
>> > +OptLevel("O",
>> > +         cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
>> > +                  "(default = '-O2')"),
>>
>> This means LTO now defaults to -O2 - rather than the previous -O3 -
>> for CodeGenOpt, right?  That seems like a somewhat important change,
>> affecting all LTO users.
>>
>> Don't get me wrong, I think it's for the best, but people involved
>> with performance might be interested in this.
>
> I believe the default before was -O2, because OptLevel is initialized
> to 2 by the PassManagerBuilder constructor, and none of the previous LTO
> infrastructure changed it.

Right, that's the PassManager's OptLevel.  I'm wondering about the
CodeGenOpt::Level though.  Consider the gold plugin:

> --- llvm/trunk/tools/gold/gold-plugin.cpp (original)
> +++ llvm/trunk/tools/gold/gold-plugin.cpp Thu Mar 19 17:01:00 2015
> @@ -754,9 +760,24 @@ static void codegen(Module &M) {
>      Features.AddFeature(A);
>
>    TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
> +  CodeGenOpt::Level CGOptLevel;
> +  switch (options::OptLevel) {
> +  case 0:
> +    CGOptLevel = CodeGenOpt::None;
> +    break;
> +  case 1:
> +    CGOptLevel = CodeGenOpt::Less;
> +    break;
> +  case 2:
> +    CGOptLevel = CodeGenOpt::Default;
> +    break;
> +  case 3:
> +    CGOptLevel = CodeGenOpt::Aggressive;
> +    break;
> +  }
>    std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
>        TripleStr, options::mcpu, Features.getString(), Options, RelocationModel,
> -      CodeModel::Default, CodeGenOpt::Aggressive));
> +      CodeModel::Default, CGOptLevel));

This changed from -O3 to -O2 by default, right?

> Anyway, there is no difference between -O2 and -O3 for LTO, as far as I
> can tell.

Agreed; for CodeGenOpt there's not a whole lot of difference either,
so this isn't a huge deal.

-Ahmed

> Thanks,
> --
> Peter



More information about the llvm-commits mailing list