Commit 8f76f377 by Richard Sandiford Committed by Richard Sandiford

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.

From-SVN: r260711
parent 0d2b3bca
2018-05-25 Richard Sandiford <richard.sandiford@linaro.org> 2018-05-25 Richard Sandiford <richard.sandiford@linaro.org>
* tree-vect-patterns.c: Include predict.h.
(vect_recog_divmod_pattern): Restrict check for division support
to when optimizing for size.
2018-05-25 Richard Sandiford <richard.sandiford@linaro.org>
* doc/sourcebuild.texi (vect_double_cond_arith: Document. * doc/sourcebuild.texi (vect_double_cond_arith: Document.
* gimple-match.h (gimple_match_op::MAX_NUM_OPS): Bump to 4. * gimple-match.h (gimple_match_op::MAX_NUM_OPS): Bump to 4.
(gimple_match_op::gimple_match_op): Add an overload for 4 operands. (gimple_match_op::gimple_match_op): Add an overload for 4 operands.
......
2018-05-25 Richard Sandiford <richard.sandiford@linaro.org> 2018-05-25 Richard Sandiford <richard.sandiford@linaro.org>
* gcc.dg/vect/bb-slp-div-1.c: New XFAILed test.
2018-05-25 Richard Sandiford <richard.sandiford@linaro.org>
* lib/target-supports.exp * lib/target-supports.exp
(check_effective_target_vect_double_cond_arith): New proc. (check_effective_target_vect_double_cond_arith): New proc.
* gcc.dg/vect/vect-cond-arith-1.c: New test. * gcc.dg/vect/vect-cond-arith-1.c: New test.
......
/* { dg-do compile } */
/* { dg-additional-options "-msve-vector-bits=256" { target aarch64_sve } } */
int x[8];
void
f (void)
{
x[0] /= 2;
x[1] /= 3;
x[2] /= 4;
x[3] /= 5;
x[4] /= 6;
x[5] /= 7;
x[6] /= 8;
x[7] /= 9;
}
/* { dg-final { scan-tree-dump "basic block vectorized" "slp2" { xfail *-*-* } } } */
...@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see
#include "attribs.h" #include "attribs.h"
#include "cgraph.h" #include "cgraph.h"
#include "omp-simd-clone.h" #include "omp-simd-clone.h"
#include "predict.h"
/* Pattern recognition functions */ /* Pattern recognition functions */
static gimple *vect_recog_widen_sum_pattern (vec<gimple *> *, tree *, static gimple *vect_recog_widen_sum_pattern (vec<gimple *> *, tree *,
...@@ -2674,15 +2675,19 @@ vect_recog_divmod_pattern (vec<gimple *> *stmts, ...@@ -2674,15 +2675,19 @@ vect_recog_divmod_pattern (vec<gimple *> *stmts,
if (vectype == NULL_TREE) if (vectype == NULL_TREE)
return NULL; return NULL;
/* If the target can handle vectorized division or modulo natively, if (optimize_bb_for_size_p (gimple_bb (last_stmt)))
don't attempt to optimize this. */
optab = optab_for_tree_code (rhs_code, vectype, optab_default);
if (optab != unknown_optab)
{ {
machine_mode vec_mode = TYPE_MODE (vectype); /* If the target can handle vectorized division or modulo natively,
int icode = (int) optab_handler (optab, vec_mode); don't attempt to optimize this, since native division is likely
if (icode != CODE_FOR_nothing) to give smaller code. */
return NULL; optab = optab_for_tree_code (rhs_code, vectype, optab_default);
if (optab != unknown_optab)
{
machine_mode vec_mode = TYPE_MODE (vectype);
int icode = (int) optab_handler (optab, vec_mode);
if (icode != CODE_FOR_nothing)
return NULL;
}
} }
prec = TYPE_PRECISION (itype); prec = TYPE_PRECISION (itype);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment