]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix profile update in copy-header
authorJan Hubicka <jh@suse.cz>
Sat, 1 Jul 2023 11:05:34 +0000 (13:05 +0200)
committerJan Hubicka <jh@suse.cz>
Sat, 1 Jul 2023 11:05:34 +0000 (13:05 +0200)
commit7e904d6c7f252ee947c237ed32dd43b2c248384d
treea92c54653e9fd592f0d8d03d28a8a7b6838c1895
parent620a35b24a2b6edb67720ec42864b571a972fa45
Fix profile update in copy-header

Most common source of profile mismatches is now copyheader pass.  The reason is that
in comon case the duplicated header condition will become constant true and that needs
changes in the loop exit condition probability.

While this can be done by jump threading it is not, since it gives up on loops.
Copy header pass now has logic to prove that first exit will become true, so this
patch adds necessary pumbing to the profile updating.
This is done in gimple_duplicate_sese_region in a way that is specific for this
particular case.  I think general case is kind-of unsolvable and loop-ch is the
only user of the infrastructure.  If we later invent some new users, maybe we
can export the region and region_copy arrays and let user to do the update.

With the patch we now get:

Pass dump id and name            |static mismat|dynamic mismatch
                                 |in count     |in count
107t cunrolli                    |      3    +3|        19237       +19237
127t ch                          |     13   +10|        19237
131t dom                         |     39   +26|        19237
133t isolate-paths               |     47    +8|        19237
134t reassoc                     |     49    +2|        19237
136t forwprop                    |     53    +4|       226943      +207706
159t cddce                       |     61    +8|       242222       +15279
161t ldist                       |     62    +1|       242222
172t ifcvt                       |     66    +4|       415472      +173250
173t vect                        |    143   +77|     10859784    +10444312
176t cunroll                     |    294  +151|    150357763   +139497979
183t loopdone                    |    291    -3|    150289533       -68230
194t tracer                      |    322   +31|    153230990     +2941457
195t fre                         |    317    -5|    153230990
197t dom                         |    286   -31|    154448079     +1217089
199t threadfull                  |    293    +7|    154724763      +276684
200t vrp                         |    297    +4|    155042448      +317685
204t dce                         |    294    -3|    155017073       -25375
206t sink                        |    292    -2|    155017073
211t cddce                       |    298    +6|    155018657        +1584
255t optimized                   |    296    -2|    155018657
256r expand                      |    273   -23|    154592622      -426035
258r into_cfglayout              |    268    -5|    154592661          +39
275r loop2_unroll                |    272    +4|    159701866     +5109205
291r ce2                         |    270    -2|    159723509
312r pro_and_epilogue            |    290   +20|    159792505       +68996
315r jump2                       |    296    +6|    164234016     +4441511
323r bbro                        |    294    -2|    159385430     -4848586

So ch introduces 10 new mismatches while originally it did 308.  At bbro the
number of mismatches dropped from 432 to 294.
Most offender is now cunroll pass. I think it is the case where loop has multiple
exits and one of exits becomes to be false in all but last peeled iteration.

This is another case where non-trivial loop update is needed.

Honza

gcc/ChangeLog:

* tree-cfg.cc (gimple_duplicate_sese_region): Add elliminated_edge
parmaeter; update profile.
* tree-cfg.h (gimple_duplicate_sese_region): Update prototype.
* tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Rename to ...
(static_loop_exit): ... this; return the edge to be elliminated.
(ch_base::copy_headers): Handle profile updating for eliminated exits.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/ifc-20040816-1.c: Reduce number of mismatches
from 2 to 1.
* gcc.dg/tree-ssa/loop-ch-profile-1.c: New test.
* gcc.dg/tree-ssa/loop-ch-profile-2.c: New test.
gcc/testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c
gcc/testsuite/gcc.dg/tree-ssa/loop-ch-profile-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/loop-ch-profile-2.c [new file with mode: 0644]
gcc/tree-cfg.cc
gcc/tree-cfg.h
gcc/tree-ssa-loop-ch.cc