gcc.target/aarch64/sve/pr98119.c has been failing since r15-268.
The test expects pointer alignment to be done with a plain AND,
but that no longer happens.

It was combine that previously generated the ANDs, but I think it's
fair to argue that it isn't combine's job to handle this case.
The test's gimple output is pretty suboptimal.

The current gimple is:

  _21 = (unsigned long) vectp_x.4_22;
  _20 = _21 >> 1;
  _17 = (unsigned int) _20;
  _16 = _17 & 15;
  _9 = (sizetype) _16;
  _18 = (unsigned int) _9;
  _32 = _18 w* 2;
  _33 = -_32;                        // -(_21 & 30)
  vectp_x.6_10 = x_13(D) + _33;      // x_31(D) & ~30
  _41 = 18446744073709551584 - _32;  // -32 - (_21 & 30)
  vectp_x.9_38 = x_13(D) + _41;      // (x_31(D) - 32) & ~30
  _55 = _16 + 1000;

This series adds two groups of folds that together give:

  _21 = (unsigned long) vectp_x.4_22;
  _20 = _21 >> 1;
  _17 = (unsigned int) _20;
  _16 = _17 & 15;
  vectp_x.6_10 = x_13(D) & -31B;
  _18 = x_13(D) & -31B;
  vectp_x.9_38 = _18 + 18446744073709551584;
  _55 = _16 + 1000;

The duplicate "x_13(D) & -31B"s are unfortunate, but RTL CSE does get
rid of them.

I asked on IRC whether new folds to fix this kind of regression were
acceptable, but I admit that the patches ended up being bigger than
I'd imagined.  I'll fully understand if they seem like too much for
stage 4 after all.

Bootstrapped & regression-tested on aarch64-linux-gnu.  I'll also
test on x86_64-linux-gnu.  OK to install if that passes?

Richard


Richard Sandiford (2):
  match.pd: Fold ((X >> C1) & C2) * (1 << C1)
  match.pd: Extend pointer alignment folds

 gcc/match.pd                                 | 56 +++++++++++++
 gcc/testsuite/gcc.dg/fold-mul-and-lshift-1.c | 59 ++++++++++++++
 gcc/testsuite/gcc.dg/fold-mul-and-lshift-2.c | 15 ++++
 gcc/testsuite/gcc.dg/pointer-arith-11.c      | 39 ++++++++++
 gcc/testsuite/gcc.dg/pointer-arith-12.c      | 82 ++++++++++++++++++++
 5 files changed, 251 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/fold-mul-and-lshift-1.c
 create mode 100644 gcc/testsuite/gcc.dg/fold-mul-and-lshift-2.c
 create mode 100644 gcc/testsuite/gcc.dg/pointer-arith-11.c
 create mode 100644 gcc/testsuite/gcc.dg/pointer-arith-12.c

-- 
2.25.1

Reply via email to