]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/115825 - improve unroll estimates for volatile accesses
authorRichard Biener <rguenther@suse.de>
Wed, 10 Jul 2024 10:45:02 +0000 (12:45 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 25 Nov 2024 07:17:54 +0000 (08:17 +0100)
commitd1cf0d7a0f27fdd55302785f19f07d1c3f162ba5
tree861ac4d60bd2e15b6ea7f33cf3af20d25b6cff88
parentc84a8a274af3163a4042bcfd77dd1988bd1eb0ce
tree-optimization/115825 - improve unroll estimates for volatile accesses

The loop unrolling code assumes that one third of all volatile accesses
can be possibly optimized away which is of course not true.  This leads
to excessive unrolling in some cases.  The following tracks the number
of stmts with side-effects as those are not eliminatable later and
only assumes one third of the other stmts can be further optimized.

This causes some fallout in the testsuite where we rely on unrolling
even when calls are involved.  I have XFAILed g++.dg/warn/Warray-bounds-20.C
but adjusted the others with a #pragma GCC unroll to mimic previous
behavior and retain what the testcase was testing.  I've also filed
PR117671 for the case where the size estimation fails to honor the
stmts we then remove by inserting __builtin_unreachable ().
For gcc.dg/tree-ssa/cunroll-2.c the estimate that the code doesn't
grow is clearly bogus and we have explicit code to reject unrolling
for bodies containing calls so I've adjusted the testcase accordingly.

PR tree-optimization/115825
* tree-ssa-loop-ivcanon.cc (loop_size::not_eliminatable_after_peeling):
New.
(loop_size::last_iteration_not_eliminatable_after_peeling): Likewise.
(tree_estimate_loop_size): Count stmts with side-effects as
not optimistically eliminatable.
(estimated_unrolled_size): Compute the number of stmts that can
be optimistically eliminated by followup transforms.
(try_unroll_loop_completely): Adjust.

* gcc.dg/tree-ssa/cunroll-17.c: New testcase.
* gcc.dg/tree-ssa/cunroll-2.c: Adjust to not expect unrolling.
* gcc.dg/pr94600-1.c: Force unrolling.
* c-c++-common/ubsan/unreachable-3.c: Likewise.
* g++.dg/warn/Warray-bounds-20.C: XFAIL cases we rely on
unrolling loops created by new expressions and not inlined
CTOR invocations.
gcc/testsuite/c-c++-common/ubsan/unreachable-3.c
gcc/testsuite/g++.dg/warn/Warray-bounds-20.C
gcc/testsuite/gcc.dg/pr94600-1.c
gcc/testsuite/gcc.dg/tree-ssa/cunroll-17.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/cunroll-2.c
gcc/tree-ssa-loop-ivcanon.cc