gnu /
gcc /
b5c64db0a49d4653418457a520648c4305e01e75 ch: Improve copy header when the bbs are predicated as non-executed [PR122734]
This is version based on https://gcc.gnu.org/pipermail/gcc-patches/2025-November/701533.html
review. Though the only thing is we still need an extra check for the edge probability
like it is done in single_likely_exit because probabilities are still not being tracked
correctly it seems.
I also added copy-headers-12.c which we fail by duplicating too much. But I think that is ok,
as this pattern of being the "correct" part of the loop header leading to a
noreturn function does not happen that often and when it does the header would have had a
statically figured out conditional which is already being checked.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/122734
gcc/ChangeLog:
* tree-ssa-loop-ch.cc (should_duplicate_loop_header_p): Add new argument,
canbe_neverexecuted. When canbe_neverexecuted is true, return if a loop
exit is "never executed" like we are doing an invariant conditional.
(ch_base::copy_headers): Update call to should_duplicate_loop_header_p.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/20030711-1.c: Update.
* gcc.dg/tree-ssa/copy-headers-10.c: New test.
* gcc.dg/tree-ssa/copy-headers-11.c: New test.
* gcc.dg/tree-ssa/copy-headers-12.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
5 files changed