* [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops
@ 2015-10-19 14:18 Kyrill Tkachov
2015-10-19 14:31 ` Segher Boessenkool
2015-10-19 14:33 ` Bernd Schmidt
0 siblings, 2 replies; 6+ messages in thread
From: Kyrill Tkachov @ 2015-10-19 14:18 UTC (permalink / raw)
To: GCC Patches; +Cc: Eric Botcazou, Segher Boessenkool
[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]
Hi all,
This second patch teaches simplify_binary_operation to return the dereferenced
constants from the constant pool in the binary expression if other simplifications failed.
This, combined with the 1/2 patch for aarch64
(https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01744.html) allow for:
int
foo (float a)
{
return a * 32.0f;
}
to generate the code:
foo:
fcvtzs w0, s0, #5
ret
because combine now successfully tries to match:
(set (reg/i:SI 0 x0)
(fix:SI (mult:SF (reg:SF 32 v0 [ a ])
(const_double:SF 3.2e+1 [0x0.8p+6]))))
whereas before it would not try the to use the const_double directly
but rather its constant pool reference.
I've seen this patch trigger once in 453.gromacs from SPEC2006 on aarch64 where it
ended up eliminating a floating-point multiplication and a load from a constant pool.
There were no other changes, so I reckon this is pretty low impact.
Bootstrapped and tested on aarch64, arm, x86_64.
CC'ing Eric as this is an RTL optimisation and Segher as this is something that
has an effect through combine.
Ok for trunk?
Thanks,
Kyrill
2015-10-19 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* simplify-rtx.c (simplify_binary_operation): If either operand was
a constant pool reference use them if all other simplifications failed.
2015-10-19 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* gcc.target/aarch64/fmul_fcvt_1.c: Add multiply-by-32 cases.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: simplify-rtx-constpool.patch --]
[-- Type: text/x-patch; name=simplify-rtx-constpool.patch, Size: 2512 bytes --]
commit f941a03f6ca5dcc0d509490d0e0ec39cefed714b
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date: Mon Oct 12 17:12:34 2015 +0100
[simplify-rtx] Use constants from pool when simplifying binops
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 5ea5522..519850a 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -2001,7 +2001,17 @@ simplify_binary_operation (enum rtx_code code, machine_mode mode,
tem = simplify_const_binary_operation (code, mode, trueop0, trueop1);
if (tem)
return tem;
- return simplify_binary_operation_1 (code, mode, op0, op1, trueop0, trueop1);
+ tem = simplify_binary_operation_1 (code, mode, op0, op1, trueop0, trueop1);
+
+ if (tem)
+ return tem;
+
+ /* If the above steps did not result in a simplification and op0 or op1
+ were constant pool references, use the referenced constants directly. */
+ if (trueop0 != op0 || trueop1 != op1)
+ return simplify_gen_binary (code, mode, trueop0, trueop1);
+
+ return NULL_RTX;
}
/* Subroutine of simplify_binary_operation. Simplify a binary operation
diff --git a/gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c b/gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c
index 5af8290..354f2be 100644
--- a/gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c
@@ -83,6 +83,17 @@ FUNC_DEFD (16)
/* { dg-final { scan-assembler "fcvtzu\tx\[0-9\], d\[0-9\]*.*#4" } } */
/* { dg-final { scan-assembler "fcvtzu\tw\[0-9\], d\[0-9\]*.*#4" } } */
+FUNC_DEFS (32)
+FUNC_DEFD (32)
+/* { dg-final { scan-assembler "fcvtzs\tw\[0-9\], s\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzs\tx\[0-9\], s\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzs\tx\[0-9\], d\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzs\tw\[0-9\], d\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzu\tw\[0-9\], s\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzu\tx\[0-9\], s\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzu\tx\[0-9\], d\[0-9\]*.*#5" } } */
+/* { dg-final { scan-assembler "fcvtzu\tw\[0-9\], d\[0-9\]*.*#5" } } */
+
#define FUNC_TESTS(__a, __b) \
do \
@@ -120,10 +131,12 @@ main (void)
FUNC_TESTS (4, i);
FUNC_TESTS (8, i);
FUNC_TESTS (16, i);
+ FUNC_TESTS (32, i);
FUNC_TESTD (4, i);
FUNC_TESTD (8, i);
FUNC_TESTD (16, i);
+ FUNC_TESTD (32, i);
}
return 0;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops
2015-10-19 14:18 [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops Kyrill Tkachov
@ 2015-10-19 14:31 ` Segher Boessenkool
2015-10-19 14:37 ` Kyrill Tkachov
2015-10-19 14:33 ` Bernd Schmidt
1 sibling, 1 reply; 6+ messages in thread
From: Segher Boessenkool @ 2015-10-19 14:31 UTC (permalink / raw)
To: Kyrill Tkachov; +Cc: GCC Patches, Eric Botcazou
Hi Kyrill,
On Mon, Oct 19, 2015 at 02:57:54PM +0100, Kyrill Tkachov wrote:
> because combine now successfully tries to match:
> (set (reg/i:SI 0 x0)
> (fix:SI (mult:SF (reg:SF 32 v0 [ a ])
> (const_double:SF 3.2e+1 [0x0.8p+6]))))
>
> whereas before it would not try the to use the const_double directly
> but rather its constant pool reference.
What happens if the constant pool reference is actually the better
code, do we still generate that?
Segher
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops
2015-10-19 14:18 [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops Kyrill Tkachov
2015-10-19 14:31 ` Segher Boessenkool
@ 2015-10-19 14:33 ` Bernd Schmidt
2015-10-19 14:42 ` Kyrill Tkachov
1 sibling, 1 reply; 6+ messages in thread
From: Bernd Schmidt @ 2015-10-19 14:33 UTC (permalink / raw)
To: Kyrill Tkachov, GCC Patches; +Cc: Eric Botcazou, Segher Boessenkool
On 10/19/2015 03:57 PM, Kyrill Tkachov wrote:
> This second patch teaches simplify_binary_operation to return the
> dereferenced
> constants from the constant pool in the binary expression if other
> simplifications failed.
>
> This, combined with the 1/2 patch for aarch64
> (https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01744.html) allow for:
>
> int
> foo (float a)
> {
> return a * 32.0f;
> }
>
> to generate the code:
> foo:
> fcvtzs w0, s0, #5
> ret
>
> because combine now successfully tries to match:
> (set (reg/i:SI 0 x0)
> (fix:SI (mult:SF (reg:SF 32 v0 [ a ])
> (const_double:SF 3.2e+1 [0x0.8p+6]))))
>
> whereas before it would not try the to use the const_double directly
> but rather its constant pool reference.
The only way I could see a problem with that if there are circumstances
where the memory variant would simplify further. That doesn't seem
highly likely, so...
> * simplify-rtx.c (simplify_binary_operation): If either operand was
> a constant pool reference use them if all other simplifications
> failed.
Ok.
Bernd
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops
2015-10-19 14:31 ` Segher Boessenkool
@ 2015-10-19 14:37 ` Kyrill Tkachov
0 siblings, 0 replies; 6+ messages in thread
From: Kyrill Tkachov @ 2015-10-19 14:37 UTC (permalink / raw)
To: Segher Boessenkool; +Cc: GCC Patches, Eric Botcazou
On 19/10/15 15:31, Segher Boessenkool wrote:
> Hi Kyrill,
Hi Segher,
>
> On Mon, Oct 19, 2015 at 02:57:54PM +0100, Kyrill Tkachov wrote:
>> because combine now successfully tries to match:
>> (set (reg/i:SI 0 x0)
>> (fix:SI (mult:SF (reg:SF 32 v0 [ a ])
>> (const_double:SF 3.2e+1 [0x0.8p+6]))))
>>
>> whereas before it would not try the to use the const_double directly
>> but rather its constant pool reference.
> What happens if the constant pool reference is actually the better
> code, do we still generate that?
In that case I think the previous calls to simplify_const_binary_operation and
simplify_binary_operation_1 should have returned a non-NULL rtx.
Kyrill
>
>
> Segher
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops
2015-10-19 14:33 ` Bernd Schmidt
@ 2015-10-19 14:42 ` Kyrill Tkachov
2015-10-20 16:17 ` Kyrill Tkachov
0 siblings, 1 reply; 6+ messages in thread
From: Kyrill Tkachov @ 2015-10-19 14:42 UTC (permalink / raw)
To: Bernd Schmidt, GCC Patches; +Cc: Eric Botcazou, Segher Boessenkool
Hi Bernd,
On 19/10/15 15:31, Bernd Schmidt wrote:
> On 10/19/2015 03:57 PM, Kyrill Tkachov wrote:
>> This second patch teaches simplify_binary_operation to return the
>> dereferenced
>> constants from the constant pool in the binary expression if other
>> simplifications failed.
>>
>> This, combined with the 1/2 patch for aarch64
>> (https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01744.html) allow for:
>>
>> int
>> foo (float a)
>> {
>> return a * 32.0f;
>> }
>>
>> to generate the code:
>> foo:
>> fcvtzs w0, s0, #5
>> ret
>>
>> because combine now successfully tries to match:
>> (set (reg/i:SI 0 x0)
>> (fix:SI (mult:SF (reg:SF 32 v0 [ a ])
>> (const_double:SF 3.2e+1 [0x0.8p+6]))))
>>
>> whereas before it would not try the to use the const_double directly
>> but rather its constant pool reference.
>
> The only way I could see a problem with that if there are circumstances where the memory variant would simplify further. That doesn't seem highly likely, so...
>
I that were the case, I'd expect the earlier call to simplify_binary_operation_1 have returned a non-NULL rtx,
and the code in this patch would not come into play.
>> * simplify-rtx.c (simplify_binary_operation): If either operand was
>> a constant pool reference use them if all other simplifications
>> failed.
>
> Ok.
Thanks,
I'll commit it when the first (aarch64-specific) patch is approved.
Kyrill
>
>
> Bernd
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops
2015-10-19 14:42 ` Kyrill Tkachov
@ 2015-10-20 16:17 ` Kyrill Tkachov
0 siblings, 0 replies; 6+ messages in thread
From: Kyrill Tkachov @ 2015-10-20 16:17 UTC (permalink / raw)
To: Bernd Schmidt, GCC Patches; +Cc: Eric Botcazou, Segher Boessenkool
[-- Attachment #1: Type: text/plain, Size: 2200 bytes --]
On 19/10/15 15:37, Kyrill Tkachov wrote:
> Hi Bernd,
>
> On 19/10/15 15:31, Bernd Schmidt wrote:
>> On 10/19/2015 03:57 PM, Kyrill Tkachov wrote:
>>> This second patch teaches simplify_binary_operation to return the
>>> dereferenced
>>> constants from the constant pool in the binary expression if other
>>> simplifications failed.
>>>
>>> This, combined with the 1/2 patch for aarch64
>>> (https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01744.html) allow for:
>>>
>>> int
>>> foo (float a)
>>> {
>>> return a * 32.0f;
>>> }
>>>
>>> to generate the code:
>>> foo:
>>> fcvtzs w0, s0, #5
>>> ret
>>>
>>> because combine now successfully tries to match:
>>> (set (reg/i:SI 0 x0)
>>> (fix:SI (mult:SF (reg:SF 32 v0 [ a ])
>>> (const_double:SF 3.2e+1 [0x0.8p+6]))))
>>>
>>> whereas before it would not try the to use the const_double directly
>>> but rather its constant pool reference.
>>
>> The only way I could see a problem with that if there are circumstances where the memory variant would simplify further. That doesn't seem highly likely, so...
>>
>
> I that were the case, I'd expect the earlier call to simplify_binary_operation_1 have returned a non-NULL rtx,
> and the code in this patch would not come into play.
>
>>> * simplify-rtx.c (simplify_binary_operation): If either operand was
>>> a constant pool reference use them if all other simplifications
>>> failed.
>>
>> Ok.
>
> Thanks,
> I'll commit it when the first (aarch64-specific) patch is approved.
>
This patch has already been ok'd, but I'd like to update the aarch64 test to use scan-assembler-times
rather that just scan-assembler in light of Marcus' feedback to another patch.
I committed this version to trunk with r229086.
Thanks,
Kyrill
2015-10-20 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* simplify-rtx.c (simplify_binary_operation): If either operand was
a constant pool reference use them if all other simplifications failed.
2015-10-20 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* gcc.target/aarch64/fmul_fcvt_1.c: Add multiply-by-32 cases.
> Kyrill
>
>>
>>
>> Bernd
>>
>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: simplify-rtx-constpool.patch --]
[-- Type: text/x-patch; name=simplify-rtx-constpool.patch, Size: 2338 bytes --]
Index: gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c
===================================================================
--- gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c (revision 229085)
+++ gcc/testsuite/gcc.target/aarch64/fmul_fcvt_1.c (working copy)
@@ -83,6 +83,16 @@
/* { dg-final { scan-assembler-times "fcvtzu\tx\[0-9\], d\[0-9\]*.*#4" 1 } } */
/* { dg-final { scan-assembler-times "fcvtzu\tw\[0-9\], d\[0-9\]*.*#4" 1 } } */
+FUNC_DEFS (32)
+FUNC_DEFD (32)
+/* { dg-final { scan-assembler-times "fcvtzs\tw\[0-9\], s\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzs\tx\[0-9\], s\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzs\tx\[0-9\], d\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzs\tw\[0-9\], d\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzu\tw\[0-9\], s\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzu\tx\[0-9\], s\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzu\tx\[0-9\], d\[0-9\]*.*#5" 1 } } */
+/* { dg-final { scan-assembler-times "fcvtzu\tw\[0-9\], d\[0-9\]*.*#5" 1 } } */
#define FUNC_TESTS(__a, __b) \
do \
@@ -120,10 +130,12 @@
FUNC_TESTS (4, i);
FUNC_TESTS (8, i);
FUNC_TESTS (16, i);
+ FUNC_TESTS (32, i);
FUNC_TESTD (4, i);
FUNC_TESTD (8, i);
FUNC_TESTD (16, i);
+ FUNC_TESTD (32, i);
}
return 0;
}
Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c (revision 229084)
+++ gcc/simplify-rtx.c (working copy)
@@ -2001,7 +2001,17 @@
tem = simplify_const_binary_operation (code, mode, trueop0, trueop1);
if (tem)
return tem;
- return simplify_binary_operation_1 (code, mode, op0, op1, trueop0, trueop1);
+ tem = simplify_binary_operation_1 (code, mode, op0, op1, trueop0, trueop1);
+
+ if (tem)
+ return tem;
+
+ /* If the above steps did not result in a simplification and op0 or op1
+ were constant pool references, use the referenced constants directly. */
+ if (trueop0 != op0 || trueop1 != op1)
+ return simplify_gen_binary (code, mode, trueop0, trueop1);
+
+ return NULL_RTX;
}
/* Subroutine of simplify_binary_operation. Simplify a binary operation
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-10-20 16:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-19 14:18 [PATCH][simplify-rtx][2/2] Use constants from pool when simplifying binops Kyrill Tkachov
2015-10-19 14:31 ` Segher Boessenkool
2015-10-19 14:37 ` Kyrill Tkachov
2015-10-19 14:33 ` Bernd Schmidt
2015-10-19 14:42 ` Kyrill Tkachov
2015-10-20 16:17 ` 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).