After tail-merge merges duplicate blocks, the predecessors that branched to
them now branch to a single successor.  This series re-runs ifcombine on those
predecessors so that sequential comparisons feeding a common successor are
combined into one condition; on targets with conditional compares the backend
then emits ccmp, and elsewhere it helps wherever ifcombine's cost model already
prefers the combined form.

  1/3 exports the ifcombine helpers via a new header.
  2/3 relaxes the uninit predicate analysis so a combined-condition shape does
      not produce bogus -Wmaybe-uninitialized warnings.
  3/3 collects the candidate predecessors after tail-merge and runs ifcombine
      on them to combine the conditions.

Bootstrapped and regression-tested on aarch64-linux-gnu and
x86_64-linux-gnu.

Changes in v3:
- Drop the targetm.have_ccmp () gate; the post-tail-merge ifcombine now runs on
  all targets, leaving profitability to ifcombine's own cost model.
- Replace the maybe_undef_at_dom_frontier_p work-around with a fix in the uninit
  predicate analysis (relax the definition predicate by the maybe-undef
  operands' incoming-edge conditions).
- apply_clusters: hoist the immediate-dominator check ahead of
  recognize_if_then_else and assert the gcond.
- Add gcc.dg/uninit-pred-13.c covering the uninit interaction.
- Make the pr102793 tests target-independent (force the combine with
  --param logical-op-non-short-circuit=1, drop the ccmp dg-skip-if) and use
  __UINT64_TYPE__.
- ifcombine: do not combine the conditions guarding a loop.  Extend the
  existing niter-safety check (which already leaves integer/pointer loop exit
  conditions alone) to loop guards too, so the post-tail-merge combine no
  longer makes a guarded loop's number-of-iterations unanalyzable; this
  restores the IV elimination in gcc.dg/tree-ssa/ivopt_mult_1.c and
  ivopt_mult_2.c.
- pr117123.C: force --param logical-op-non-short-circuit=0 so this
  value-numbering test keeps its short-circuit form (3 ifs) on all targets,
  rather than being combined to 2 where the target defaults to
  non-short-circuit (e.g. x86).

Konstantinos Eleftheriou (3):
  ifcombine: Add tree-ssa-ifcombine.h and update function signatures
  uninit: Relax PHI def predicate by maybe-undef edge conditions
  tail-merge: Combine conditions of merged blocks for ccmp [PR102793]

 gcc/gimple-predicate-analysis.cc           | 96 ++++++++++++++++++++--
 gcc/gimple-predicate-analysis.h            |  2 +
 gcc/testsuite/g++.dg/tree-ssa/pr117123.C   |  2 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr102793-1.c | 49 +++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr102793-2.c | 50 +++++++++++
 gcc/testsuite/gcc.dg/uninit-pred-13.c      | 60 ++++++++++++++
 gcc/tree-ssa-ifcombine.cc                  | 41 +++++++--
 gcc/tree-ssa-ifcombine.h                   | 27 ++++++
 gcc/tree-ssa-tail-merge.cc                 | 60 +++++++++++++-
 9 files changed, 370 insertions(+), 17 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/testsuite/gcc.dg/uninit-pred-13.c
 create mode 100644 gcc/tree-ssa-ifcombine.h

-- 
2.52.0

Reply via email to