From: Kyrylo Tkachov <[email protected]>

This is v4 of the series that starts with v3 1/8:
https://gcc.gnu.org/pipermail/gcc-patches/2026-November/737301.html
Each patch has a link to its v3 version and the changes from v3.

v3 2/8 and 3/8 (vect) are committed.  v3 1/8 (ranger) is dropped:
.CLZ and .CTZ take only unsigned arguments, and the GIMPLE verifier now
checks this.  The other patches have new numbers:

  v4 1/5  phiopt    v3 4/8  reset the debug binds (Richard)
  v4 2/5  phiopt    v3 5/8  Andrea Pinski's v4, no changes
  v4 3/5  phiopt    v3 6/8  no changes, OK'd by Jeff
  v4 4/5  match.pd  v3 7/8  test follows 1/5
  v4 5/5  match.pd  v3 8/8  no changes

The series is for PR126035, the split form of a double-word count:

  lo != 0 ? ctz (lo) : 32 + ctz (hi)
  hi != 0 ? clz (hi) : 32 + clz (lo)

For a nonzero value, one count of the double-word value gives the same
result.  The zstd sources in SPEC2026 use this form, with 32-bit table
based counts for the halves, which forwprop turns into .CTZ and .CLZ.

Patch 1 fixes a trunk bug: phiopt removes middle blocks with their
debug binds, so a debugger shows an old value.  It now resets the
variables of these binds before the condition.  That was the original approach,
and Richard suggested it's preferable.
Patch 2 is Andrea's patch: phiopt match-and-simplify accepts arms with several 
statements.
Patch 3 removes cond_removal_in_builtin_zero_pattern, which match.pd
and patch 2 then cover.  Patches 4 and 5 add the match.pd patterns for
counts that are undefined and defined at zero.

With patch 2 as posted, gcc.dg/tree-ssa/pr126035-1.c,
gcc.dg/tree-ssa/pr126035-4.c and gcc.target/aarch64/pr126035-1.c fail.
feeding_bb_info rejects an arm with a one-argument count and other
statements before the match, also when the result does not use them.
With that check removed, these tests pass.

On aarch64 the split 64-bit ctz of zstd used nine instructions with two
counts.  It now uses rbit, clz, cmp, mov and csel. The motivating case for this
series is zstd from SPEC2026, it improves by 3% on aarch64.

Patch 2 in this series is Andrea's patch to move more than 1 statement for
match in phiopt. I'm happy for Andrea to take that forward, I'm just posting
a coherent series here before end of stage 1 to make it easier for review.

Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux.
Thanks,
Kyrill

Andrea Pinski (1):
  phiopt: Support more than moving 1 statement for match

Kyrylo Tkachov (4):
  phiopt: Reset the debug binds of removed middle blocks
  phiopt: Remove cond_removal_in_builtin_zero_pattern
  match.pd: Combine split double-word clz and ctz [PR126035]
  match.pd: Combine split clz and ctz that are defined at zero
    [PR126035]

 gcc/doc/params.texi                           |   5 +
 gcc/gimple-match-head.cc                      |  31 +
 gcc/match.pd                                  | 106 ++-
 gcc/params.opt                                |   4 +
 gcc/testsuite/gcc.dg/torture/pr126035-1.c     | 142 ++++
 gcc/testsuite/gcc.dg/torture/pr126035-2.c     |  12 +
 gcc/testsuite/gcc.dg/torture/pr126035-3.c     | 131 ++++
 gcc/testsuite/gcc.dg/tree-ssa/and-ctz-1.c     |  21 +
 gcc/testsuite/gcc.dg/tree-ssa/and-shift-1.c   |  14 +
 gcc/testsuite/gcc.dg/tree-ssa/clamp-1.c       |  25 +
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-60.c    |  25 +
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-61.c    |  40 +
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-62.c    |  21 +
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-63.c    |  25 +
 gcc/testsuite/gcc.dg/tree-ssa/pr126035-1.c    |  89 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr126035-2.c    |  69 ++
 gcc/testsuite/gcc.dg/tree-ssa/pr126035-4.c    |  31 +
 gcc/testsuite/gcc.dg/tree-ssa/pr126035-5.c    |  55 ++
 .../gcc.dg/tree-ssa/ssa-dom-thread-16.c       |   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/umax-sub-1.c    |  14 +
 gcc/testsuite/gcc.target/aarch64/pr126035-1.c |  48 ++
 gcc/testsuite/gcc.target/aarch64/pr126035-2.c |  67 ++
 gcc/testsuite/gcc.target/aarch64/pr126035-3.c |  69 ++
 gcc/tree-ssa-phiopt.cc                        | 731 +++++++++---------
 24 files changed, 1408 insertions(+), 369 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr126035-1.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr126035-2.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr126035-3.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/and-ctz-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/and-shift-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/clamp-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-60.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-61.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-62.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-63.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr126035-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr126035-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr126035-4.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr126035-5.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/umax-sub-1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr126035-1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr126035-2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr126035-3.c


base-commit: e86951e831b893ee8fdc3f87d77dd469b8ec8500
-- 
2.34.1

Reply via email to