This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][GCC][AARCH64]Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (1/2)]
- From: James Greenhalgh <james dot greenhalgh at arm dot com>
- To: Tamar Christina <Tamar dot Christina at arm dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, nd <nd at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>, Marcus Shawcroft <Marcus dot Shawcroft at arm dot com>
- Date: Tue, 6 Jun 2017 14:11:17 +0100
- Subject: Re: [PATCH][GCC][AARCH64]Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (1/2)]
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=pass (sender IP is 217.140.96.140) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=bestguesspass action=none header.from=arm.com;
- Nodisclaimer: True
- References: <VI1PR0801MB2031451A1018AA38163513C7FF170@VI1PR0801MB2031.eurprd08.prod.outlook.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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.christina@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.christina@arm.com>
>
> * gcc.target/aarch64/sdiv_costs_1.c: New.