https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109832
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:afe5ed138a7bbf1bddc46f331f62707568bafe1f commit r17-5213-gafe5ed138a7bbf1bddc46f331f62707568bafe1f Author: Kyrylo Tkachov <[email protected]> Date: Thu Sep 3 14:45:40 2026 +0200 ccmp: Reject chains without an explicit comparison [PR109832] The conditional-compare expander accepts a plain boolean as a comparison against zero. This is useful when a chain also contains an explicit comparison. It is harmful when every leaf is a boolean. For example: _Bool f (_Bool x, _Bool y) { return x || y; } AArch64 emitted: and w1, w1, 255 tst w0, 255 ccmp w1, 0, 0, eq cset w0, ne Make candidate recognition report whether it found an explicit comparison. It already validates every statement before it follows the next definition. Reject a candidate without an explicit comparison. TER fallback starts a new conditional-compare recognition call for each forwarded suffix. Cache accepted all-boolean subchains in the existing per-function ssaexpand state so that these calls inspect a linear chain in linear time. The state is shared by cfgexpand and expression expansion and is released when RTL expansion finishes. The example then emits: orr w0, w0, w1 Tests cover all-boolean and mixed chains, a non-binary boolean definition, and a long rejected chain. Changes since v1: - Report explicit comparisons during candidate recognition. - Cache all-boolean subchains so TER fallback stays linear. - Add non-binary definition and long-chain tests. gcc/ PR middle-end/109832 * ccmp.cc (ccmp_tree_comparison_p): Report whether an accepted leaf is a comparison. (ccmp_candidate_p): Propagate the result and cache all-boolean candidates. (expand_ccmp_expr): Reject an all-boolean candidate. * tree-outof-ssa.h (ssaexpand::ccmp_no_comparison): New member. * tree-outof-ssa.cc (finish_out_of_ssa): Free it. gcc/testsuite/ PR middle-end/109832 * gcc.target/aarch64/ccmp_7.c: New test. * gcc.target/aarch64/ccmp_9.c: Likewise. * gcc.target/aarch64/ccmp_11.c: Likewise. * gcc.target/aarch64/ccmp_13.c: Likewise. Signed-off-by: Kyrylo Tkachov <[email protected]>
