This patch series extends the tail-merging pass to combine sequential conditions leading to a merged block on targets that support conditional compare (ccmp) instructions. After tail merging combines duplicate blocks, their predecessors now branch to the same successor. The sequential conditions in these predecessors can be combined using the existing ifcombine infrastructure, enabling the back end to generate ccmp instructions (e.g., on AArch64).
Patch 1 is a preparatory change that exports recognize_if_then_else and tree_ssa_ifcombine_bb from tree-ssa-ifcombine.cc via a new header, so they can be called from the tail-merging pass. Patch 2 is the main change. In apply_clusters, after each block replacement, predecessors of the merged block that have conditional branches are recorded as ifcombine candidates. After the tail-merge loop completes, dominance info is computed, maybe-undef SSA names are marked, and tree_ssa_ifcombine_bb is called for each candidate. Candidates are skipped when the dominance subtree of a successor has PHI arguments that are maybe-undef at the dominance frontier, to avoid introducing bogus -Wmaybe-uninitialized warnings. The transformation is gated on targetm.have_ccmp() since it produces beneficial code only when ccmp instructions are available. Bootstrapped and regression-tested on AArch64 and x86. Changes in v2: - Use tree_ssa_ifcombine_bb for combining conditions. Konstantinos Eleftheriou (2): ifcombine: Add tree-ssa-ifcombine.h and update function signatures tail-merge: Combine conditions of merged blocks for ccmp [PR102793] gcc/testsuite/gcc.dg/guality/pr54693-2.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr102793-1.c | 50 ++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr102793-2.c | 51 +++++++++ gcc/tree-ssa-ifcombine.cc | 4 +- gcc/tree-ssa-ifcombine.h | 28 +++++ gcc/tree-ssa-tail-merge.cc | 126 ++++++++++++++++++++- 6 files changed, 255 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr102793-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr102793-2.c create mode 100644 gcc/tree-ssa-ifcombine.h -- 2.52.0 base-commit: a68d8098393b14a3a175105c201ff8484fbdf8fb branch: kelefth/gcc-185-v2
