Forum > General

Optimization parameters

(1/4) > >>

Fred vS:
Hello.

In https://wiki.freepascal.org/Optimization , there is:


--- Quote ---Optimization Switches

You can enable general optimization groups using "-O1", "-O2", "-O3", and "-O4". Individual switches can be enabled with "-Oo<switch>".

As of 13 July 2020, the optimization groups (defined in /compiler/<arch>/cpuinfo.pas, which references /compiler/globtype.pas) are:

-O1: PEEPHOLE
--- End quote ---

Not sure to understand, is the fpc parameter -O1 equal to -OoPEEPHOLE ?

Because with one graphic application using -O1 as fpc parameter the application crash at loading ( no problems without any opt  parameter. )

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -O1 test.pas
But with -OoPEEPHOLE  as fpc parameter ( without -O1 ) the application runs perfectly.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -OoPEEPHOLE test.pas
The test is with fpc-llvm 3.3.1. on Debian 11 64 bit.

So it seems that  -O1 has different result than -OoPEEPHOLE or do I miss something?

Result of fpc-llvm switches:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fred@fred-pc ~> /usr/lib/fpc/3.3.1/ppcx64 -io
--- Quote ---STACKFRAME
PEEPHOLE
LOOPUNROLL
CSE
DFA
ORDERFIELDS
FASTMATH
REMOVEEMPTYPROCS
CONSTPROP
UNUSEDPARA
FORLOOP

--- End quote ---

Fre;D

Kays:

--- Quote from: Fred vS on November 03, 2022, 02:47:37 pm ---[…] Not sure to understand, is the fpc parameter -O1 equal to -OoPEEPHOLE ? […]
--- End quote ---
Correct. From a cursory reading I claim it’s a bug. There are a couple locations the compiler checks
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[…] if cs_opt_level1 in current_settings.optimizerswitches then […]Apparently you can only achieve cs_opt_level1 being included in optimizerswitches by specifying a numeric optimization level. The ‑OoPEEPHOLE only adds cs_opt_peephole to the set, not cs_opt_level1. Thus, your application should also crash if you compile it with
--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -O1 -OoNOPEEPHOLE test.pas

Fred vS:

--- Quote from: Kays on November 03, 2022, 07:05:43 pm ---
--- Quote from: Fred vS on November 03, 2022, 02:47:37 pm ---[…] Not sure to understand, is the fpc parameter -O1 equal to -OoPEEPHOLE ? […]
--- End quote ---
Correct. From a cursory reading I claim it’s a bug. There are a couple locations the compiler checks
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[…] if cs_opt_level1 in current_settings.optimizerswitches then […]Apparently you can only achieve cs_opt_level1 being included in optimizerswitches by specifying a numeric optimization level. The ‑OoPEEPHOLE only adds cs_opt_peephole to the set, not cs_opt_level1. Thus, your application should also crash if you compile it with
--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -O1 -OoNOPEEPHOLE test.pas
--- End quote ---

Ha, thanks or the light.
So, if a  cs_opt_level1  must be set, with -O1 there is only PEEPHOLE,  PEEPHOLE is the guilty.
It is a few strange that  cs_opt_level1 minimum -O1 must be set to use -OoSomething.
So it is not possible to add any optimiation without PEEPHOLE? (and test other optimization without it) ?

Fred vS:

--- Quote from: Kays on November 03, 2022, 07:05:43 pm ---[Thus, your application should also crash if you compile it with
--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -O1 -OoNOPEEPHOLE test.pas
--- End quote ---

Ooops I did not see the "NOPEEPHOLE" (that will disable the option according the doc.)
So logically the application should not crash because it is like disable -O1 ( or once more time I dont catch.)

I will try this, write you later with the result.

Fred vS:
Re-hello.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -O1 -OoNOPEEPHOLE test.pas
Also crash so it seems that  -O1 is not equal to -OoPEEPHOLE

Navigation

[0] Message Index

[#] Next page

Go to full version