]> git.ipfire.org Git - thirdparty/gcc.git/commit
Limit outer-loop unswitching by duplicated code size
authorliuhongt <hongtao.liu@intel.com>
Mon, 5 Jan 2026 02:52:23 +0000 (18:52 -0800)
committerliuhongt <hongtao.liu@intel.com>
Wed, 20 May 2026 06:43:15 +0000 (23:43 -0700)
commit1a787fd3dfefc8827d3e4289ae7bbaf18934bcd2
treeaf367cf904a65c5fe73d6fd4bd7f6a02121fefa2
parent61a39811893cf34794e6ffe5ab382882c6a5ddc0
Limit outer-loop unswitching by duplicated code size

When unswitching predicates from the innermost loop, hoisting the
unswitch out to an outer loop duplicates only the outer-loop bodies;
the innermost loop is shared.  Estimate the cost as
candidate_size - innermost_size and stop selecting an outer loop once
that exceeds param_max_unswitch_insns.  innermost_size is hoisted out
of the walk so estimate_loop_insns is called once per level.

gcc/ChangeLog:

* tree-ssa-loop-unswitch.cc (estimate_loop_insns): New function.
(init_loop_unswitch_info): Do not select an outer loop for
unswitching when the duplicated outer-body size exceeds
param_max_unswitch_insns.

gcc/testsuite/ChangeLog:

* gcc.dg/loop-unswitch-19.c: New test.
gcc/testsuite/gcc.dg/loop-unswitch-19.c [new file with mode: 0644]
gcc/tree-ssa-loop-unswitch.cc