On Tue, May 02, 2017 at 04:37:16PM +0100, Tamar Christina wrote:
> Hi All, 
> 
> This patch adjusts the cost model so that when both sdiv and udiv are possible
> it prefers udiv over sdiv. This was done by making sdiv slightly more 
> expensive
> instead of making udiv cheaper to keep the baseline costs of a division the 
> same
> as before.
> 
> For aarch64 this patch along with my other two related mid-end changes
> makes a big difference in division by constants.

This patch seems to have an unrelated change to the MOD/UMOD costs to delete
the handling of floating-point values. That change makes sense, but would
have been better in a separate patch.

> Given:
> 
> int f2(int x)
> {
>   return ((x * x) % 300) + ((x * x) / 300);
> }
> 
> we now generate
> 
> f2:
>       mul     w0, w0, w0
>       mov     w1, 33205
>       movk    w1, 0x1b4e, lsl 16
>       mov     w2, 300
>       umull   x1, w0, w1
>       lsr     x1, x1, 37
>       msub    w0, w1, w2, w0
>       add     w0, w0, w1
>       ret
> 
> as opposed to
> 
> f2:
>       mul     w0, w0, w0
>       mov     w2, 33205
>       movk    w2, 0x1b4e, lsl 16
>       mov     w3, 300
>       smull   x1, w0, w2
>       umull   x2, w0, w2
>       asr     x1, x1, 37
>       sub     w1, w1, w0, asr 31
>       lsr     x2, x2, 37
>       msub    w0, w1, w3, w0
>       add     w0, w0, w2
>       ret
> 
> Bootstrapped and reg tested on aarch64-none-linux-gnu with no regressions.
> 
> OK for trunk?

OK.

Thanks,
James

> gcc/
> 2017-05-02  Tamar Christina  <tamar.christ...@arm.com>
> 
>       * config/aarch64/aarch64.c (aarch64_rtx_costs): Make sdiv more 
> expensive than udiv.
>       Remove floating point cases from mod.
> 
> gcc/testsuite/
> 2017-05-02  Tamar Christina  <tamar.christ...@arm.com>
> 
>       * gcc.target/aarch64/sdiv_costs_1.c: New.

Reply via email to