From: Kyrylo Tkachov <[email protected]>

This is a respin of the mergediamonds series, targeting the astcenc benchmark
in SPEC2026 fprate.

When a diamond tests the same condition as a dominating diamond, the
first full jump threader duplicates the blocks between the two.  The
selects of the diamonds then sit on different paths, and RTL
if-conversion cannot turn them into conditional selects (PR125672).
Comparison masks make this worse.  Early phiopt keeps them as PHIs, so
the threader also resolves each later test of a mask by duplicating
blocks (PR126043).

Patch 7 lets early phiopt form the negated masks -CMP and -(type) CMP,
which forwprop then folds into the tests.  Patch 8 moves the PHIs of a
later diamond with empty arms to the join of the nearest dominating
diamond with the same condition, if their arguments are available
there.  It runs before the first full threader.  The other patches fix
bugs that patches 7 and 8 expose or make easier to reach, and implement
PR127292:

  1  bitintlower: wrong code in the PHI copies of large and huge
     _BitInt values (PR121722).  Patch 8 makes it easier to reach.
  2  gimple-fold: wrong code when an inverted comparison can see NaNs.
     The tests of patch 7 need it.
  3  gimple-fold: wrong code in same_bool_comparison_p (GIMPLE input).
  4  reassoc: ICE when a range test follows a statement that ends its
     block.  The tests of patch 7 need it.
  5  match.pd: wrong code in the PR110293 folds for signed one-bit
     types.
  6  match.pd: the PR110293 folds for all comparisons (PR127292).
  7  phiopt: negated comparison masks in early phiopt (PR126043).
  8  backthreader: merge same-condition diamonds (PR125672).

Patches 1-5, 7 and 8 apply to trunk on their own, and patch 6 applies
on top of patch 5.  The performance gain needs patches 7 and 8
together.  With them, the rate of SPEC CPU2026 731.astcenc_r on NVIDIA
Vera improves by 20.6% at -O3 -ffast-math -mcpu=olympus -flto=auto and
by 15.3% without -ffast-math.  Its hot function has 41% fewer
instructions and 78% fewer conditional branches.

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

Changes since v2
(https://inbox.sourceware.org/gcc-patches/[email protected]/):

- Patches 1-6 are new.
- Patch 7 follows Andrea's reviews of v1 and v2.  It accepts only -CMP
  and -(type) CMP, checks the match sequence from its last statement
  and rejects any other statement in it.  The predictor check looks only
  at the last statement, and the embedded-diamond guard is gone.  The
  0/1 forms CMP and (type) CMP still give worse code where ifcombine
  merges the original branches, see the commit message.
- Patch 8 is no longer a separate pass.  It runs in the back_threader
  constructor of the first full threader, before the ranger is created,
  and leaves the empty diamonds to CFG cleanup.  One dominator walk
  records each diamond for its condition and, with the arms swapped, for
  the inverse condition, as DOM does.  Only the later diamond needs
  empty arms, and its condition may trap, because the earlier condition
  already raised the same exception.  Debug binds of the later arms move
  to its join with unknown values.  The commit message answers Andrea's
  question about live ranges.

Andrea, you opened PR126043, PR127292 is assigned to you.  Patches 6
and 7 are what I have for these PRs.  Please tell me if/how you want to
combine them with your patches.  I'm posting my versions as I wanted to have a
coherent series out there before stage 1 end.

Jakub, patch 1 changes how gimple-lower-bitint.cc emits the PHI copies.

Cc: Andrea Pinski <[email protected]>
Cc: Jakub Jelinek <[email protected]>

Kyrylo Tkachov (8):
  bitintlower: Lower the PHI copies of an edge as a parallel copy
    [PR121722]
  gimple-fold: Honour NaNs when inverting comparisons
  gimple-fold: Test the outer comparison in same_bool_comparison_p
  reassoc: Do not insert a range test after a statement that ends its
    block
  match.pd: Fold x ==/!= (T)(x ==/!= C) only if (T) true is 1
  match.pd: Fold X ==/!= (T) (X CMP C) for all comparisons [PR127292]
  phiopt: Allow negated comparison masks in early phiopt [PR126043]
  backthreader: Merge same-condition diamonds [PR125672]

 gcc/dbgcnt.def                                |   1 +
 gcc/gimple-fold.cc                            |  56 ++--
 gcc/gimple-lower-bitint.cc                    | 119 ++++---
 gcc/match.pd                                  |  68 ++--
 gcc/testsuite/g++.dg/opt/pr126043-2.C         |  20 ++
 gcc/testsuite/g++.dg/opt/pr126043.C           |  25 ++
 .../g++.dg/torture/reassoc-ends-bb-1.C        |  21 ++
 .../g++.dg/torture/reassoc-ends-bb-2.C        |  24 ++
 .../gcc.c-torture/compile/reassoc-ends-bb-1.c |  20 ++
 gcc/testsuite/gcc.dg/bitint-147.c             | 131 ++++++++
 gcc/testsuite/gcc.dg/predict-26.c             |  50 +++
 gcc/testsuite/gcc.dg/torture/bitint-116.c     | 138 ++++++++
 gcc/testsuite/gcc.dg/torture/bitint-117.c     |   5 +
 .../gcc.dg/torture/pr110293-bitint.c          |  48 +++
 gcc/testsuite/gcc.dg/torture/pr127292-2.c     |  61 ++++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-1.c    |  37 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-2.c    |  95 ++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-3.c    |  37 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-4.c    |  30 ++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-5.c    |  43 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-6.c    |  73 +++++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-7.c    | 112 +++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-8.c    |  21 ++
 gcc/testsuite/gcc.dg/tree-ssa/pr125672-9.c    |  57 ++++
 gcc/testsuite/gcc.dg/tree-ssa/pr126043-1.c    |  40 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr126043-2.c    |  27 ++
 gcc/testsuite/gcc.dg/tree-ssa/pr127292-1.c    |  66 ++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-54.c    |  31 ++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-55.c    |  37 +++
 .../gcc.dg/tree-ssa/ssa-ifcombine-7.c         |   3 +-
 .../gcc.dg/tree-ssa/ssa-ifcombine-nan-1.c     |  24 ++
 .../gcc.dg/tree-ssa/ssa-ifcombine-nan-2.c     |  43 +++
 .../gcc.dg/tree-ssa/ssa-ifcombine-nan-3.c     |  62 ++++
 gcc/tree-ssa-phiopt.cc                        |  92 ++++--
 gcc/tree-ssa-reassoc.cc                       |  11 +-
 gcc/tree-ssa-threadbackward.cc                | 297 ++++++++++++++++++
 36 files changed, 1888 insertions(+), 137 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/opt/pr126043-2.C
 create mode 100644 gcc/testsuite/g++.dg/opt/pr126043.C
 create mode 100644 gcc/testsuite/g++.dg/torture/reassoc-ends-bb-1.C
 create mode 100644 gcc/testsuite/g++.dg/torture/reassoc-ends-bb-2.C
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/reassoc-ends-bb-1.c
 create mode 100644 gcc/testsuite/gcc.dg/bitint-147.c
 create mode 100644 gcc/testsuite/gcc.dg/predict-26.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/bitint-116.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/bitint-117.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr110293-bitint.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr127292-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-3.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-4.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-5.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-6.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-7.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-8.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr125672-9.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr126043-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr126043-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr127292-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-54.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-55.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-nan-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-nan-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-nan-3.c

-- 
2.54.0 (Apple Git-157)

Reply via email to