From: Tamar Christina Date: Wed, 7 Jun 2017 10:06:29 +0000 (+0000) Subject: aarch64.c (aarch64_rtx_costs): Make sdiv more expensive than udiv. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cb9ac430cbadfe075164c86e9f1fe190138da15d;p=gcc.git aarch64.c (aarch64_rtx_costs): Make sdiv more expensive than udiv. 2017-06-07 Tamar Christina * config/aarch64/aarch64.c (aarch64_rtx_costs): Make sdiv more expensive than udiv. Remove floating point cases from mod. From-SVN: r248953 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index eb818fc2d69..3b204f828ed 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-06-07 Tamar Christina + + * config/aarch64/aarch64.c (aarch64_rtx_costs): Make sdiv more expensive than udiv. + Remove floating point cases from mod. + 2017-06-07 Tamar Christina * config/arm/aarch-cost-tables.h (cortexa53_extra_cost): Increase idiv cost. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 5707e5317e2..bce490ff555 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -7544,17 +7544,13 @@ cost_plus: case UMOD: if (speed) { + /* Slighly prefer UMOD over SMOD. */ if (VECTOR_MODE_P (mode)) *cost += extra_cost->vect.alu; else if (GET_MODE_CLASS (mode) == MODE_INT) *cost += (extra_cost->mult[mode == DImode].add - + extra_cost->mult[mode == DImode].idiv); - else if (mode == DFmode) - *cost += (extra_cost->fp[1].mult - + extra_cost->fp[1].div); - else if (mode == SFmode) - *cost += (extra_cost->fp[0].mult - + extra_cost->fp[0].div); + + extra_cost->mult[mode == DImode].idiv + + (code == MOD ? 1 : 0)); } return false; /* All arguments need to be in registers. */ @@ -7568,7 +7564,9 @@ cost_plus: else if (GET_MODE_CLASS (mode) == MODE_INT) /* There is no integer SQRT, so only DIV and UDIV can get here. */ - *cost += extra_cost->mult[mode == DImode].idiv; + *cost += (extra_cost->mult[mode == DImode].idiv + /* Slighly prefer UDIV over SDIV. */ + + (code == DIV ? 1 : 0)); else *cost += extra_cost->fp[mode == DFmode].div; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 268412e0c13..bd6bd76e551 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-07 Tamar Christina + + * gcc.target/aarch64/sdiv_costs_1.c: New. + 2017-06-07 Richard Biener PR tree-optimization/80928 diff --git a/gcc/testsuite/gcc.target/aarch64/sdiv_costs_1.c b/gcc/testsuite/gcc.target/aarch64/sdiv_costs_1.c new file mode 100644 index 00000000000..24d7f7df208 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sdiv_costs_1.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +/* Both sdiv and udiv can be used here, so prefer udiv. */ +int f1 (unsigned char *p) +{ + return 100 / p[1]; +} + +int f2 (unsigned char *p, unsigned short x) +{ + return x / p[0]; +} + +int f3 (unsigned char *p, int x) +{ + x &= 0x7fffffff; + return x / p[0]; +} + +int f5 (unsigned char *p, unsigned short x) +{ + return x % p[0]; +} + +/* This should only generate signed divisions. */ +int f4 (unsigned char *p) +{ + return -100 / p[1]; +} + +int f6 (unsigned char *p, short x) +{ + return x % p[0]; +} + +/* { dg-final { scan-assembler-times "udiv\tw\[0-9\]+, w\[0-9\]+" 4 } } */ +/* { dg-final { scan-assembler-times "sdiv\tw\[0-9\]+, w\[0-9\]+" 2 } } */