* [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
@ 2017-05-02 15:37 Tamar Christina
2017-05-15 8:33 ` Tamar Christina
2017-06-07 10:04 ` Kyrill Tkachov
0 siblings, 2 replies; 7+ messages in thread
From: Tamar Christina @ 2017-05-02 15:37 UTC (permalink / raw)
To: GCC Patches
Cc: nd, Kyrylo Tkachov, Ramana Radhakrishnan, Richard Earnshaw, nickc
[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]
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.
Similar to aarch64 this patch along with my other two related mid-end changes
makes a big difference in division by constants.
Given:
int f2(int x)
{
return ((x * x) % 300) + ((x * x) / 300);
}
we now generate
f2:
mul r3, r0, r0
mov r0, r3
ldr r1, .L3
umull r2, r3, r0, r1
lsr r2, r3, #5
add r3, r2, r2, lsl #2
rsb r3, r3, r3, lsl #4
sub r0, r0, r3, lsl #2
add r0, r0, r2
bx lr
as opposed to
f2:
mul r3, r0, r0
mov r0, r3
ldr r3, .L4
push {r4, r5}
smull r4, r5, r0, r3
asr r3, r0, #31
rsb r3, r3, r5, asr #5
add r2, r3, r3, lsl #2
rsb r2, r2, r2, lsl #4
sub r0, r0, r2, lsl #2
add r0, r0, r3
pop {r4, r5}
bx lr
Bootstrapped and reg tested on arm-none-eabi
with no regressions.
OK for trunk?
Thanks,
Tamar
gcc/
2017-05-02 Tamar Christina <tamar.christina@arm.com>
* config/arm/arm.c (arm_rtx_costs_internal): Make sdiv more expensive than udiv.
gcc/testsuite/
2017-05-02 Tamar Christina <tamar.christina@arm.com>
* gcc.target/arm/sdiv_costs_1.c: New.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sdiv-arm.patch --]
[-- Type: text/x-patch; name="sdiv-arm.patch", Size: 1911 bytes --]
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index b24143e32e2f100000f3b150f7ed0df4fabb3cc8..ecc7688b1db6309a4dd694a8e254e64abe14d7e3 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -9258,6 +9258,8 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
*cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0);
else
*cost = LIBCALL_COST (2);
+
+ *cost += (code == DIV ? 1 : 0);
return false; /* All arguments must be in registers. */
case MOD:
@@ -9280,7 +9282,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
/* Fall-through. */
case UMOD:
- *cost = LIBCALL_COST (2);
+ *cost = LIBCALL_COST (2) + (code == MOD ? 1 : 0);
return false; /* All arguments must be in registers. */
case ROTATE:
diff --git a/gcc/testsuite/gcc.target/arm/sdiv_costs_1.c b/gcc/testsuite/gcc.target/arm/sdiv_costs_1.c
new file mode 100644
index 0000000000000000000000000000000000000000..76086ab9ce28fceb37a4e8a615a38923fa7b985a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/sdiv_costs_1.c
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=armv8-a" } */
+
+/* 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\tr\[0-9\]+, r\[0-9\]+, r\[0-9\]+" 4 } } */
+/* { dg-final { scan-assembler-times "sdiv\tr\[0-9\]+, r\[0-9\]+, r\[0-9\]+" 2 } } */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
2017-05-02 15:37 [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)] Tamar Christina
@ 2017-05-15 8:33 ` Tamar Christina
2017-06-07 9:58 ` Tamar Christina
2017-06-07 10:04 ` Kyrill Tkachov
1 sibling, 1 reply; 7+ messages in thread
From: Tamar Christina @ 2017-05-15 8:33 UTC (permalink / raw)
To: GCC Patches
Cc: nd, Kyrylo Tkachov, Ramana Radhakrishnan, Richard Earnshaw, nickc
Ping
________________________________________
From: gcc-patches-owner@gcc.gnu.org <gcc-patches-owner@gcc.gnu.org> on behalf of Tamar Christina <Tamar.Christina@arm.com>
Sent: Tuesday, May 2, 2017 4:37:12 PM
To: GCC Patches
Cc: nd; Kyrylo Tkachov; Ramana Radhakrishnan; Richard Earnshaw; nickc@redhat.com
Subject: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
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.
Similar to aarch64 this patch along with my other two related mid-end changes
makes a big difference in division by constants.
Given:
int f2(int x)
{
return ((x * x) % 300) + ((x * x) / 300);
}
we now generate
f2:
mul r3, r0, r0
mov r0, r3
ldr r1, .L3
umull r2, r3, r0, r1
lsr r2, r3, #5
add r3, r2, r2, lsl #2
rsb r3, r3, r3, lsl #4
sub r0, r0, r3, lsl #2
add r0, r0, r2
bx lr
as opposed to
f2:
mul r3, r0, r0
mov r0, r3
ldr r3, .L4
push {r4, r5}
smull r4, r5, r0, r3
asr r3, r0, #31
rsb r3, r3, r5, asr #5
add r2, r3, r3, lsl #2
rsb r2, r2, r2, lsl #4
sub r0, r0, r2, lsl #2
add r0, r0, r3
pop {r4, r5}
bx lr
Bootstrapped and reg tested on arm-none-eabi
with no regressions.
OK for trunk?
Thanks,
Tamar
gcc/
2017-05-02 Tamar Christina <tamar.christina@arm.com>
* config/arm/arm.c (arm_rtx_costs_internal): Make sdiv more expensive than udiv.
gcc/testsuite/
2017-05-02 Tamar Christina <tamar.christina@arm.com>
* gcc.target/arm/sdiv_costs_1.c: New.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
2017-05-15 8:33 ` Tamar Christina
@ 2017-06-07 9:58 ` Tamar Christina
0 siblings, 0 replies; 7+ messages in thread
From: Tamar Christina @ 2017-06-07 9:58 UTC (permalink / raw)
To: GCC Patches
Cc: nd, Kyrylo Tkachov, Ramana Radhakrishnan, Richard Earnshaw, nickc
Ping
________________________________________
From: gcc-patches-owner@gcc.gnu.org <gcc-patches-owner@gcc.gnu.org> on behalf of Tamar Christina <Tamar.Christina@arm.com>
Sent: Monday, May 15, 2017 9:32:55 AM
To: GCC Patches
Cc: nd; Kyrylo Tkachov; Ramana Radhakrishnan; Richard Earnshaw; nickc@redhat.com
Subject: Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
Ping
________________________________________
From: gcc-patches-owner@gcc.gnu.org <gcc-patches-owner@gcc.gnu.org> on behalf of Tamar Christina <Tamar.Christina@arm.com>
Sent: Tuesday, May 2, 2017 4:37:12 PM
To: GCC Patches
Cc: nd; Kyrylo Tkachov; Ramana Radhakrishnan; Richard Earnshaw; nickc@redhat.com
Subject: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
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.
Similar to aarch64 this patch along with my other two related mid-end changes
makes a big difference in division by constants.
Given:
int f2(int x)
{
return ((x * x) % 300) + ((x * x) / 300);
}
we now generate
f2:
mul r3, r0, r0
mov r0, r3
ldr r1, .L3
umull r2, r3, r0, r1
lsr r2, r3, #5
add r3, r2, r2, lsl #2
rsb r3, r3, r3, lsl #4
sub r0, r0, r3, lsl #2
add r0, r0, r2
bx lr
as opposed to
f2:
mul r3, r0, r0
mov r0, r3
ldr r3, .L4
push {r4, r5}
smull r4, r5, r0, r3
asr r3, r0, #31
rsb r3, r3, r5, asr #5
add r2, r3, r3, lsl #2
rsb r2, r2, r2, lsl #4
sub r0, r0, r2, lsl #2
add r0, r0, r3
pop {r4, r5}
bx lr
Bootstrapped and reg tested on arm-none-eabi
with no regressions.
OK for trunk?
Thanks,
Tamar
gcc/
2017-05-02 Tamar Christina <tamar.christina@arm.com>
* config/arm/arm.c (arm_rtx_costs_internal): Make sdiv more expensive than udiv.
gcc/testsuite/
2017-05-02 Tamar Christina <tamar.christina@arm.com>
* gcc.target/arm/sdiv_costs_1.c: New.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
2017-05-02 15:37 [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)] Tamar Christina
2017-05-15 8:33 ` Tamar Christina
@ 2017-06-07 10:04 ` Kyrill Tkachov
2017-06-07 10:15 ` Tamar Christina
1 sibling, 1 reply; 7+ messages in thread
From: Kyrill Tkachov @ 2017-06-07 10:04 UTC (permalink / raw)
To: Tamar Christina, GCC Patches
Cc: nd, Ramana Radhakrishnan, Richard Earnshaw, nickc
On 02/05/17 16:37, 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.
>
> Similar to aarch64 this patch along with my other two related mid-end changes
> makes a big difference in division by constants.
>
> Given:
>
> int f2(int x)
> {
> return ((x * x) % 300) + ((x * x) / 300);
> }
>
> we now generate
>
> f2:
> mul r3, r0, r0
> mov r0, r3
> ldr r1, .L3
> umull r2, r3, r0, r1
> lsr r2, r3, #5
> add r3, r2, r2, lsl #2
> rsb r3, r3, r3, lsl #4
> sub r0, r0, r3, lsl #2
> add r0, r0, r2
> bx lr
>
> as opposed to
>
> f2:
> mul r3, r0, r0
> mov r0, r3
> ldr r3, .L4
> push {r4, r5}
> smull r4, r5, r0, r3
> asr r3, r0, #31
> rsb r3, r3, r5, asr #5
> add r2, r3, r3, lsl #2
> rsb r2, r2, r2, lsl #4
> sub r0, r0, r2, lsl #2
> add r0, r0, r3
> pop {r4, r5}
> bx lr
>
> Bootstrapped and reg tested on arm-none-eabi
> with no regressions.
>
> OK for trunk?
>
> Thanks,
> Tamar
>
>
> gcc/
> 2017-05-02 Tamar Christina <tamar.christina@arm.com>
>
> * config/arm/arm.c (arm_rtx_costs_internal): Make sdiv more expensive than udiv.
>
>
> gcc/testsuite/
> 2017-05-02 Tamar Christina <tamar.christina@arm.com>
>
> * gcc.target/arm/sdiv_costs_1.c: New.
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index b24143e32e2f100000f3b150f7ed0df4fabb3cc8..ecc7688b1db6309a4dd694a8e254e64abe14d7e3 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -9258,6 +9258,8 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
*cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0);
else
*cost = LIBCALL_COST (2);
+
+ *cost += (code == DIV ? 1 : 0);
return false; /* All arguments must be in registers. */
We usually try to avoid adjusting the costs in units other than COSTS_N_INSNS.
Would adding COSTS_N_INSNS (1) here work?
If so, could you also add a comment here to describe why we're adjusting the cost.
case MOD:
@@ -9280,7 +9282,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
/* Fall-through. */
case UMOD:
- *cost = LIBCALL_COST (2);
+ *cost = LIBCALL_COST (2) + (code == MOD ? 1 : 0);
Same here.
Thanks,
Kyrill
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
2017-06-07 10:04 ` Kyrill Tkachov
@ 2017-06-07 10:15 ` Tamar Christina
2017-06-07 15:09 ` Tamar Christina
0 siblings, 1 reply; 7+ messages in thread
From: Tamar Christina @ 2017-06-07 10:15 UTC (permalink / raw)
To: Kyrill Tkachov, GCC Patches
Cc: nd, Ramana Radhakrishnan, Richard Earnshaw, nickc
Hi Kyrill,
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index
> b24143e32e2f100000f3b150f7ed0df4fabb3cc8..ecc7688b1db6309a4dd694a8e
> 254e64abe14d7e3 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -9258,6 +9258,8 @@ arm_rtx_costs_internal (rtx x, enum rtx_code
> code, enum rtx_code outer_code,
> *cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0);
> else
> *cost = LIBCALL_COST (2);
> +
> + *cost += (code == DIV ? 1 : 0);
> return false; /* All arguments must be in registers. */
>
>
> We usually try to avoid adjusting the costs in units other than
> COSTS_N_INSNS.
> Would adding COSTS_N_INSNS (1) here work?
> If so, could you also add a comment here to describe why we're adjusting the
> cost.
It would, I'm just slightly worried it might end up generating different code for DIV then.
The reason I have used a unit smaller than COSTS_N_INSNS it so that it should have any real
Impact on any other optimization as the cost is likely treated as an integer? It's only for things that
Compare the costs values between signed and unsigned would the small unit make a difference.
Since I think the compiler still has some hard coded cost limits somewhere it may be an issue, but I'm not
100% certain. I can make the change though.
>
> case MOD:
> @@ -9280,7 +9282,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code
> code, enum rtx_code outer_code,
>
> /* Fall-through. */
> case UMOD:
> - *cost = LIBCALL_COST (2);
> + *cost = LIBCALL_COST (2) + (code == MOD ? 1 : 0);
>
> Same here.
>
> Thanks,
> Kyrill
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
2017-06-07 10:15 ` Tamar Christina
@ 2017-06-07 15:09 ` Tamar Christina
2017-06-09 10:11 ` Kyrill Tkachov
0 siblings, 1 reply; 7+ messages in thread
From: Tamar Christina @ 2017-06-07 15:09 UTC (permalink / raw)
To: Kyrill Tkachov, GCC Patches
Cc: nd, Ramana Radhakrishnan, Richard Earnshaw, nickc
[-- Attachment #1: Type: text/plain, Size: 2111 bytes --]
Hi Kyrill,
I have updated the patch and regtested on arm-none-linux-gnueabihf.
OK for trunk?
Thanks,
Tamar
________________________________________
From: Tamar Christina
Sent: Wednesday, June 7, 2017 11:15:49 AM
To: Kyrill Tkachov; GCC Patches
Cc: nd; Ramana Radhakrishnan; Richard Earnshaw; nickc@redhat.com
Subject: RE: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
Hi Kyrill,
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index
> b24143e32e2f100000f3b150f7ed0df4fabb3cc8..ecc7688b1db6309a4dd694a8e
> 254e64abe14d7e3 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -9258,6 +9258,8 @@ arm_rtx_costs_internal (rtx x, enum rtx_code
> code, enum rtx_code outer_code,
> *cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0);
> else
> *cost = LIBCALL_COST (2);
> +
> + *cost += (code == DIV ? 1 : 0);
> return false; /* All arguments must be in registers. */
>
>
> We usually try to avoid adjusting the costs in units other than
> COSTS_N_INSNS.
> Would adding COSTS_N_INSNS (1) here work?
> If so, could you also add a comment here to describe why we're adjusting the
> cost.
It would, I'm just slightly worried it might end up generating different code for DIV then.
The reason I have used a unit smaller than COSTS_N_INSNS it so that it should have any real
Impact on any other optimization as the cost is likely treated as an integer? It's only for things that
Compare the costs values between signed and unsigned would the small unit make a difference.
Since I think the compiler still has some hard coded cost limits somewhere it may be an issue, but I'm not
100% certain. I can make the change though.
>
> case MOD:
> @@ -9280,7 +9282,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code
> code, enum rtx_code outer_code,
>
> /* Fall-through. */
> case UMOD:
> - *cost = LIBCALL_COST (2);
> + *cost = LIBCALL_COST (2) + (code == MOD ? 1 : 0);
>
> Same here.
>
> Thanks,
> Kyrill
>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: arm-div-costs.patch --]
[-- Type: text/x-patch; name="arm-div-costs.patch", Size: 2167 bytes --]
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index b24143e32e2f100000f3b150f7ed0df4fabb3cc8..442d12de4dcff50484229e2d27e65d78c3fd6b37 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -9258,6 +9258,10 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
*cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0);
else
*cost = LIBCALL_COST (2);
+
+ /* Make the cost of sdiv more expensive so when both sdiv and udiv are
+ possible udiv is prefered. */
+ *cost += (code == DIV ? COSTS_N_INSNS (1) : 0);
return false; /* All arguments must be in registers. */
case MOD:
@@ -9280,7 +9284,9 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
/* Fall-through. */
case UMOD:
- *cost = LIBCALL_COST (2);
+ /* Make the cost of sdiv more expensive so when both sdiv and udiv are
+ possible udiv is prefered. */
+ *cost = LIBCALL_COST (2) + (code == MOD ? COSTS_N_INSNS (1) : 0);
return false; /* All arguments must be in registers. */
case ROTATE:
diff --git a/gcc/testsuite/gcc.target/arm/sdiv_costs_1.c b/gcc/testsuite/gcc.target/arm/sdiv_costs_1.c
new file mode 100644
index 0000000000000000000000000000000000000000..76086ab9ce28fceb37a4e8a615a38923fa7b985a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/sdiv_costs_1.c
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=armv8-a" } */
+
+/* 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\tr\[0-9\]+, r\[0-9\]+, r\[0-9\]+" 4 } } */
+/* { dg-final { scan-assembler-times "sdiv\tr\[0-9\]+, r\[0-9\]+, r\[0-9\]+" 2 } } */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
2017-06-07 15:09 ` Tamar Christina
@ 2017-06-09 10:11 ` Kyrill Tkachov
0 siblings, 0 replies; 7+ messages in thread
From: Kyrill Tkachov @ 2017-06-09 10:11 UTC (permalink / raw)
To: Tamar Christina, GCC Patches
Cc: nd, Ramana Radhakrishnan, Richard Earnshaw, nickc
Hi Tamar,
On 07/06/17 16:09, Tamar Christina wrote:
> Hi Kyrill,
>
> I have updated the patch and regtested on arm-none-linux-gnueabihf.
>
> OK for trunk?
Ok.
Thanks,
Kyrill
> Thanks,
> Tamar
> ________________________________________
> From: Tamar Christina
> Sent: Wednesday, June 7, 2017 11:15:49 AM
> To: Kyrill Tkachov; GCC Patches
> Cc: nd; Ramana Radhakrishnan; Richard Earnshaw; nickc@redhat.com
> Subject: RE: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)]
>
> Hi Kyrill,
>
>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index
>> b24143e32e2f100000f3b150f7ed0df4fabb3cc8..ecc7688b1db6309a4dd694a8e
>> 254e64abe14d7e3 100644
>> --- a/gcc/config/arm/arm.c
>> +++ b/gcc/config/arm/arm.c
>> @@ -9258,6 +9258,8 @@ arm_rtx_costs_internal (rtx x, enum rtx_code
>> code, enum rtx_code outer_code,
>> *cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0);
>> else
>> *cost = LIBCALL_COST (2);
>> +
>> + *cost += (code == DIV ? 1 : 0);
>> return false; /* All arguments must be in registers. */
>>
>>
>> We usually try to avoid adjusting the costs in units other than
>> COSTS_N_INSNS.
>> Would adding COSTS_N_INSNS (1) here work?
>> If so, could you also add a comment here to describe why we're adjusting the
>> cost.
> It would, I'm just slightly worried it might end up generating different code for DIV then.
> The reason I have used a unit smaller than COSTS_N_INSNS it so that it should have any real
> Impact on any other optimization as the cost is likely treated as an integer? It's only for things that
> Compare the costs values between signed and unsigned would the small unit make a difference.
>
> Since I think the compiler still has some hard coded cost limits somewhere it may be an issue, but I'm not
> 100% certain. I can make the change though.
>
>> case MOD:
>> @@ -9280,7 +9282,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code
>> code, enum rtx_code outer_code,
>>
>> /* Fall-through. */
>> case UMOD:
>> - *cost = LIBCALL_COST (2);
>> + *cost = LIBCALL_COST (2) + (code == MOD ? 1 : 0);
>>
>> Same here.
>>
>> Thanks,
>> Kyrill
>>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-06-09 10:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 15:37 [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)] Tamar Christina
2017-05-15 8:33 ` Tamar Christina
2017-06-07 9:58 ` Tamar Christina
2017-06-07 10:04 ` Kyrill Tkachov
2017-06-07 10:15 ` Tamar Christina
2017-06-07 15:09 ` Tamar Christina
2017-06-09 10:11 ` Kyrill Tkachov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).