Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2018-01

Question about $OPTIMIZATION LEVELn

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martok

Hi all,

just a quick question: is setting one of the LEVELn values like

  {$Optimization LEVEL3}

in a source file supposed to be functionally equivalent to calling the compiler for that file with -O3?

If so, then there's a bug: only the level gets applied, none of the associated switches (i.e. level3optimizerswitches, including the inherited lower levels) are set. This seems weird?
Patch seems straightforward, I'd just want some input on what the negative options like {$Optimization NOLEVEL3} should do.

Otherwise it's a documentation bug:
<https://www.freepascal.org/docs-html/prog/progsu58.html> claims {$OPTIMIZATION ON} is equivalent to {$OPTIMIZATION LEVEL2}, which it never was since that directive was introduced.

Slightly related, the Programmer's Guide lists ancient optimization switches in 11.3. Bug report coming in shortly.

Regards, Martok Ceterum censeo b32079 esse sanandam.

Reply by email

Martok
to Tomas Hajny

Huh.

Quick googling shows lots of projects out there that clearly assumed it would. So we need to get at least the documentation fixed for the future.

If I were to replace {$OPTIMISATIONS ON} with {$OPTIMISATIONS LEVEL4} somewhere, that switches most optimizations *off* instead of doing more. Not terribly intuitive.

On the other hand, there is no way to say "do all medium-expensive optimizations you know on this code": listing them individually is cumbersome, not portable and not extensible for when new flags are introduced.

Is there even a use case for the current behaviour? I.e., when would one actually mean -Oolevel3 instead of -O3?

Regards, Martok Ceterum censeo b32079 esse sanandam.

Reply by email

Jonas Maebe
to Martok
Martok wrote
Is there even a use case for the current behaviour? I.e., when would one actually mean -Oolevel3 instead of -O3?

The LevelX switches are only intended for internal use by the compiler, and were never intended to be exposed. They should simply give a warning or error when used. The ability to have the equivalent of -O1/-O2/-O3/-O4 in source code was never planned.

Jonas

Reply by email

Martok
to Jonas Maebe
Jonas Maebe wrote
The LevelX switches are only intended for internal use by the compiler, and were never intended to be exposed.

Good, that's what I thought too.

The ability to have the equivalent of -O1/-O2/-O3/-O4 in source code was never planned.

Florian wrote in 0025873,

But there is indeed no equivalent for -O3/4 at source level ({$optimizations on} equals to -O2). I'am open for suggestions how such a directive should look like.

May I propose to redefine {$optimization levelN} to do that? Reasons: a) we agree the flags alone (should) have no use
b) it's always been documented that way
c) it's used as if that was true in live code

Rough patch attached...

Regards, Martok Ceterum censeo b32079 esse sanandam.

Reply by email