From fa46ae8c7ca09480ba702af1590e6bbb5a09105d Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Fri, 13 May 2022 22:39:40 +0200 Subject: [PATCH 01/18] enable store motion pass run after global common subexpression elimination docs: When -fgcse-sm is enabled, a store motion pass is run after global common subexpression elimination. This pass attempts to move stores out of loops. When used in conjunction with -fgcse-lm, loops containing a load/store sequence can be changed to a load before the loop and a store after the loop. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 9115f5c..1ff325a 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From ed3a8ad5d8f00fb98e147e5c1bfa8d55502f3016 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Fri, 13 May 2022 22:41:57 +0200 Subject: [PATCH 02/18] enable elimination of redundant loads that come after stores to the same memory location docs: When -fgcse-las is enabled, the global common subexpression elimination pass eliminates redundant loads that come after stores to the same memory location (both partial and full redundancies). --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 1ff325a..ff5399b 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 44ac1fd5c8dc093c4f38539cbfb41d225179c13a Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Fri, 13 May 2022 22:54:38 +0200 Subject: [PATCH 03/18] enable live range shrinkage to relief register pressure docs: I'd recommend to use this at least for x86/x86-64. I think any OOO processor with small or moderate register file which does not use the 1st insn scheduling might benefit from this too. On SPEC2000 for x86/x86-64 (I use Haswell processor, -O3 with general tuning), the optimization usage results in smaller code size in average (for floating point and integer benchmarks in 32- and 64-bit mode). The improvement better visible for SPECFP2000 (although I have the same improvement on x86-64 SPECInt2000 but it might be attributed mostly mcf benchmark unstability). It is about 0.5% for 32-bit and 64-bit mode. It is understandable, as the optimization has more opportunities to improve the code on longer BBs. Different from other heuristic optimizations, I don't see any significant worse performance. It gives practically the same or better performance (a few benchmarks imporoved by 1% or more upto 3%). The single but significant drawback is additional compilation time (4%-6%) as the 1st insn scheduling pass is quite expensive. Source of docs: https://gcc.gnu.org/legacy-ml/gcc-patches/2013-11/msg00420.html --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index ff5399b..6243700 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From bab81f19415a1edd65b69d005d8f97a74516b015 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Fri, 13 May 2022 23:05:53 +0200 Subject: [PATCH 04/18] enable evaluate register pressure in loops for decisions to move loop invariants This is enabled with -O3, but only for some targets. Seems to be off for x86_64. docs: Use IRA to evaluate register pressure in loops for decisions to move loop invariants. This option usually results in generation of faster and smaller code on machines with large register files (>= 32 registers), but it can slow the compiler down. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 6243700..73ea9df 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 4c0a56b5f9be71b159688426642945bbd662c268 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Fri, 13 May 2022 23:41:10 +0200 Subject: [PATCH 05/18] enable register pressure sensitive insn scheduling before register allocation docs: Enable register pressure sensitive insn scheduling before register allocation. This only makes sense when scheduling before register allocation is enabled, i.e. with -fschedule-insns or at -O2 or higher. Usage of this option can improve the generated code and decrease its size by preventing register pressure increase above the number of available hard registers and subsequent spills in register allocation. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 73ea9df..e3c77d2 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 0bb2d4b27a07b89f1e50c6853c72b3ccd29bc21c Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Fri, 13 May 2022 23:54:50 +0200 Subject: [PATCH 06/18] enable Swing Modulo Scheduling for basic innermost loop optimizations without blocking further rescheduling docs: SMS is intended to schedule instructions of loops rather than the traditional scheduler (in GCC) that does not give a special handling for loops. For more information on the theory behind SMS take a look at the 2004 GCC summit proceedings (page 55). This optimization helps in loops where there is a place to run consecutive iterations concurrently but the traditional instruction scheduling is not able to fully utilize the hardware functional units. This optimization is disabled by default because of compile time consumption; -fmodulo-sched activates it. Source: https://gcc.gnu.org/news/sms.html --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index e3c77d2..129fb61 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 191d8915a93369ae258c729ac872df6416363b7d Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 00:08:08 +0200 Subject: [PATCH 07/18] allow dead exception code to be removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docs: Consider that instructions that may throw exceptions but don’t otherwise contribute to the execution of the program can be optimized away. This does not affect calls to functions except those with the pure or const attributes. This option is enabled by default for the Ada and C++ compilers, as permitted by the language specifications. Optimization passes that cause dead exceptions to be removed are enabled independently at different optimization levels. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 129fb61..69b24c4 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 96e1ed1c7d45e46a42358664e07e6fccf7a1c4e3 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 00:15:56 +0200 Subject: [PATCH 08/18] enable graphite with identity transformation docs: Enable the identity transformation for graphite. For every SCoP we generate the polyhedral representation and transform it back to gimple. Using -fgraphite-identity we can check the costs or benefits of the GIMPLE -> GRAPHITE -> GIMPLE transformation. Some minimal optimizations are also performed by the code generator isl, like index splitting and dead code elimination in loops. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 69b24c4..87d2154 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 2bdf571fc90c0cbb383824c73be0b34bfd8807b3 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 00:32:07 +0200 Subject: [PATCH 09/18] enable auto split of the stack before it overflows docs: Generate code to automatically split the stack before it overflows. The resulting program has a discontiguous stack which can only overflow if the program is unable to allocate any more memory. This is most useful when running threaded programs, as it is no longer necessary to calculate a good stack size to use for each thread. This is currently only implemented for the x86 targets running GNU/Linux. When code compiled with -fsplit-stack calls code compiled without -fsplit-stack, there may not be much stack space available for the latter code to run. If compiling all code, including library code, with -fsplit-stack is not an option, then the linker can fix up these calls so that the code compiled without -fsplit-stack always has a large stack. Support for this is implemented in the gold linker in GNU binutils release 2.21 and later. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 87d2154..a07cd70 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 5792db8954f14c2c1e9519fd620f666c817314e2 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 00:37:56 +0200 Subject: [PATCH 10/18] enable interprocedural pointer analysis and interprocedural modification and reference analysis docs: Perform interprocedural pointer analysis and interprocedural modification and reference analysis. This option can cause excessive memory and compile-time usage on large compilation units. It is not enabled by default at any optimization level. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index a07cd70..a2c2f6f 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From a8ed047a5e068a88591f049c5d2b6ce33e7974cd Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 00:39:39 +0200 Subject: [PATCH 11/18] Detect paths that trigger erroneous or undefined behavior docs: Detect paths that trigger erroneous or undefined behavior due to a null value being used in a way forbidden by a returns_nonnull or nonnull attribute. Isolate those paths from the main control flow and turn the statement with erroneous or undefined behavior into a trap. This is not currently enabled, but may be enabled by -O2 in the future. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index a2c2f6f..5b9d22a 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 9abe7a0c48b483955dc436523989f63964cf6980 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 01:05:03 +0200 Subject: [PATCH 12/18] set regions for the integrated register allocator to the default value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the behaivor of gcc 12 isn't following the docs here. Regardless of the -O2/3 or -march=native/generic/x86-64-v3 it's always set to 'one'. Docs state it should be set to mixed if optimizations are on. Docs: Use specified regions for the integrated register allocator. The region argument should be one of the following: ‘all’ Use all loops as register allocation regions. This can give the best results for machines with a small and/or irregular register set. ‘mixed’ Use all loops except for loops with small register pressure as the regions. This value usually gives the best results in most cases and for most architectures, and is enabled by default when compiling with optimization for speed (-O, -O2, …). ‘one’ Use all functions as a single region. This typically results in the smallest code size, and is enabled by default for -Os or -O0. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 5b9d22a..acb4bcf 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 82f35b871ab68230ecd33bbdbc1e1a82654d0a98 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 01:58:39 +0200 Subject: [PATCH 13/18] correcting model cost for vectorization of loops marked with the OpenMP simd directive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc's behaivor is again not following the documentation, which lets assume that it would use dynamic by default. By default gcc 12 uses here unlimited which does not do any estimation how costly it is vs the benefit. Docs: Alter the cost model used for vectorization of loops marked with the OpenMP simd directive. The model argument should be one of ‘unlimited’, ‘dynamic’, ‘cheap’. All values of model have the same meaning as described in -fvect-cost-model and by default a cost model defined with -fvect-cost-model is used. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index acb4bcf..60c5310 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 27e539fb288847bb002a5d229181600730603c6f Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 20:59:21 +0200 Subject: [PATCH 14/18] Attempt to avoid false dependencies in scheduled code by making use of registers left over after register allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docs state that it should be active by default if -funroll-loops, which we don't use. docs: Attempt to avoid false dependencies in scheduled code by making use of registers left over after register allocation. This optimization most benefits processors with lots of registers. Depending on the debug information format adopted by the target, however, it can make debugging impossible, since variables no longer stay in a “home register”. Enabled by default with -funroll-loops. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 60c5310..32edc5b 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From c8d28055ec71c585cdf5d9b6efd7cf96f3e9abad Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 21:03:06 +0200 Subject: [PATCH 15/18] Constructs webs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docs: Constructs webs as commonly used for register allocation purposes and assign each web individual pseudo register. This allows the register allocation pass to operate on pseudos directly, but also strengthens several other optimization passes, such as CSE, loop optimizer and trivial dead code remover. It can, however, make debugging impossible, since variables no longer stay in a “home register”. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 32edc5b..5948d87 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 3dcf691597c0135fd0fe763af9951cee33b09012 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 21:16:08 +0200 Subject: [PATCH 16/18] enable vectorization of trees docs: Perform vectorization on trees. This flag enables -ftree-loop-vectorize and -ftree-slp-vectorize if not explicitly specified. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 5948d87..48139d6 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb -ftree-vectorize") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From cee2554f3f526d380e8911bf2ac77638a9237d7c Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 21:30:04 +0200 Subject: [PATCH 17/18] don't split LTO in multiple segments The rationale of the default 'dynamic' is to do some multiprocessing in a first local optimisation step. This might lead to failures on link time (rare!) but is also not optimal. More details: https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 48139d6..ad12456 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb -ftree-vectorize") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb -ftree-vectorize -flto-partition=one") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0 From 31de58baa7fab98041b7b6fc03384309b16ab0d7 Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Sat, 14 May 2022 21:34:46 +0200 Subject: [PATCH 18/18] assume loops are finite docs: Assume that a loop with an exit will eventually take the exit and not loop indefinitely. This allows the compiler to remove loops that otherwise have no side-effects, not considering eventual endless looping as such. This option is enabled by default at -O2 for C++ with -std=c++11 or higher. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index ad12456..74d2d95 100644 --- a/utils.go +++ b/utils.go @@ -727,7 +727,7 @@ func setupMakepkg(march string) error { } makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb -ftree-vectorize -flto-partition=one") + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul -fdevirtualize-at-ltrans -fgcse-sm -fgcse-las -flive-range-shrinkage -fira-loop-pressure -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -freschedule-modulo-scheduled-loops -fdelete-dead-exceptions -fgraphite -fgraphite-identity -fsplit-stack -fipa-pta -fisolate-erroneous-paths-attribute -fira-region=mixed -fsimd-cost-model=dynamic -frename-registers -fweb -ftree-vectorize -flto-partition=one -ffinite-loops") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe \"", "PACKAGER=\"ALHP "+march+" \"") -- 2.51.0