Prefer open-coding vector integer division
commit1c91e6c28bc3a384316d83c3437def66b251485d
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 May 2018 08:18:42 +0000 (25 08:18 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 May 2018 08:18:42 +0000 (25 08:18 +0000)
treebf586692b116d22b1e515fb4c7f3bb8fc7f2774a
parentdbc7e6ae0ae1a7a89f353ca62c98884f0173d993
Prefer open-coding vector integer division

vect_recog_divmod_pattern currently bails out if the target has
native support for integer division, but I think in practice
it's always going to be better to open-code it anyway, just as
we usually open-code scalar divisions by constants.

I think the only currently affected targets are MIPS MSA and
powerpcspe (which is currently marked obsolete).  For:

  void
  foo (int *x)
  {
    for (int i = 0; i < 100; ++i)
      x[i] /= 2;
  }

the MSA port previously preferred to use division for powers of 2:

        .set    noreorder
        bnz.w   $w1,1f
        div_s.w $w0,$w0,$w1
        break   7
        .set    reorder
1:

(or just the div_s.w for -mno-check-zero-division), but after the patch
it open-codes them using shifts:

        clt_s.w $w1,$w0,$w2
        subv.w  $w0,$w0,$w1
        srai.w  $w0,$w0,1

MSA doesn't define a high-part pattern, so it still uses a division
instruction for the non-power-of-2 case.

Richard B pointed out that this would disable SLP of division by
different amounts, but I think in practice that's a price worth paying,
since the current cost model can't really tell whether using a general
vector division is better than using open-coded scalar divisions.
The fix would be either to support SLP of mixed open-coded divisions
or to improve the cost model and try SLP again without the patterns.
The patch adds an XFAILed test for this.

2018-05-23  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
* tree-vect-patterns.c: Include predict.h.
(vect_recog_divmod_pattern): Restrict check for division support
to when optimizing for size.

gcc/testsuite/
* gcc.dg/vect/bb-slp-div-1.c: New XFAILed test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260711 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/bb-slp-div-1.c [new file with mode: 0644]
gcc/tree-vect-patterns.c