* [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1
@ 2015-03-20 17:03 Renlin Li
2015-04-16 4:49 ` Jeff Law
2015-06-16 13:35 ` Christophe Lyon
0 siblings, 2 replies; 5+ messages in thread
From: Renlin Li @ 2015-03-20 17:03 UTC (permalink / raw)
To: gcc-patches; +Cc: Ramana.Radhakrishnan, Richard.Earnshaw
[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]
Hi all,
This is a simple patch to enable two simplifications for UNSIGNED_FLOAT
expression.
For the following rtx patterns, they can be simplified when the integer
x can be
represented in float mode without precision loss:
float_truncate (float x) --> float x
float_extend (float x) --> float x
Those two simplifications are also applicable to UNSIGNED_FLOAT expression.
For example, compile the following code using aarch64-none-elf toolchain
with -O1 flag.
double
f1 (uint16_t x)
{
return (double)(float)x;
}
Before the change, the compiler generates the following code:
f1:
uxth w0, w0
ucvtf s0, w0
fcvt d0, s0
ret
After the change, the following simplified asm code snipts are generated.
f1:
uxth w0, w0
ucvtf d0, w0
ret
aarch64-none-elf regression test runs Okay. x86_64 bootstraps Okay.
Okay to commit?
gcc/ChangeLog:
2015-03-20 Renlin Li <renlin.li@arm.com>
* simplify-rtx.c (simplify_unary_operation_1): Fix a typo. Enable two
simplifications for UNSIGNED_FLOAT.
gcc/testsuite/ChangeLog:
2015-03-20 Renlin Li <renlin.li@arm.com>
* gcc.target/aarch64/unsigned-float.c: New.
* gcc.target/arm/unsigned-float.c: New.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 2.diff --]
[-- Type: text/x-patch; name=2.diff, Size: 2937 bytes --]
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 5d17498..4b18d3c 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -1171,7 +1171,7 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op)
= (float_truncate:SF foo:DF).
(float_truncate:DF (float_extend:XF foo:SF))
- = (float_extend:SF foo:DF). */
+ = (float_extend:DF foo:SF). */
if ((GET_CODE (op) == FLOAT_TRUNCATE
&& flag_unsafe_math_optimizations)
|| GET_CODE (op) == FLOAT_EXTEND)
@@ -1183,14 +1183,14 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op)
XEXP (op, 0), mode);
/* (float_truncate (float x)) is (float x) */
- if (GET_CODE (op) == FLOAT
+ if ((GET_CODE (op) == FLOAT || GET_CODE (op) == UNSIGNED_FLOAT)
&& (flag_unsafe_math_optimizations
|| (SCALAR_FLOAT_MODE_P (GET_MODE (op))
&& ((unsigned)significand_size (GET_MODE (op))
>= (GET_MODE_PRECISION (GET_MODE (XEXP (op, 0)))
- num_sign_bit_copies (XEXP (op, 0),
GET_MODE (XEXP (op, 0))))))))
- return simplify_gen_unary (FLOAT, mode,
+ return simplify_gen_unary (GET_CODE (op), mode,
XEXP (op, 0),
GET_MODE (XEXP (op, 0)));
@@ -1221,7 +1221,7 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op)
rounding can't happen.
*/
if (GET_CODE (op) == FLOAT_EXTEND
- || (GET_CODE (op) == FLOAT
+ || ((GET_CODE (op) == FLOAT || GET_CODE (op) == UNSIGNED_FLOAT)
&& SCALAR_FLOAT_MODE_P (GET_MODE (op))
&& ((unsigned)significand_size (GET_MODE (op))
>= (GET_MODE_PRECISION (GET_MODE (XEXP (op, 0)))
diff --git a/gcc/testsuite/gcc.target/aarch64/unsigned-float.c b/gcc/testsuite/gcc.target/aarch64/unsigned-float.c
new file mode 100644
index 0000000..c5ad680
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/unsigned-float.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+#include <stdint.h>
+
+double
+f1 (uint16_t x)
+{
+ return (double)(float)x;
+}
+
+float
+f2 (uint16_t x)
+{
+ return (float)(double)x;
+}
+
+/* { dg-final { scan-assembler-not "fcvt" } } */
diff --git a/gcc/testsuite/gcc.target/arm/unsigned-float.c b/gcc/testsuite/gcc.target/arm/unsigned-float.c
new file mode 100644
index 0000000..bb05c85
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/unsigned-float.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_vfp_ok } */
+/* { dg-options "-march=armv7-a -O1 -mfloat-abi=softfp" } */
+/* { dg-skip-if "need fp instructions" { *-*-* } { "-mfloat-abi=soft" } { "" } } */
+
+#include <stdint.h>
+
+double
+f1 (uint16_t x)
+{
+ return (double)(float)x;
+}
+
+float
+f2 (uint16_t x)
+{
+ return (float)(double)x;
+}
+
+/* { dg-final { scan-assembler-not "vcvt.(f32.f64|f64.f32)" } } */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1
2015-03-20 17:03 [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1 Renlin Li
@ 2015-04-16 4:49 ` Jeff Law
2015-06-16 13:35 ` Christophe Lyon
1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2015-04-16 4:49 UTC (permalink / raw)
To: Renlin Li, gcc-patches; +Cc: Ramana.Radhakrishnan, Richard.Earnshaw
On 03/20/2015 11:03 AM, Renlin Li wrote:
> Hi all,
>
> This is a simple patch to enable two simplifications for UNSIGNED_FLOAT
> expression.
>
> For the following rtx patterns, they can be simplified when the integer
> x can be
> represented in float mode without precision loss:
>
> float_truncate (float x) --> float x
> float_extend (float x) --> float x
>
> Those two simplifications are also applicable to UNSIGNED_FLOAT expression.
>
> For example, compile the following code using aarch64-none-elf toolchain
> with -O1 flag.
> double
> f1 (uint16_t x)
> {
> return (double)(float)x;
> }
> Before the change, the compiler generates the following code:
> f1:
> uxth w0, w0
> ucvtf s0, w0
> fcvt d0, s0
> ret
> After the change, the following simplified asm code snipts are generated.
> f1:
> uxth w0, w0
> ucvtf d0, w0
> ret
>
>
> aarch64-none-elf regression test runs Okay. x86_64 bootstraps Okay.
> Okay to commit?
>
> gcc/ChangeLog:
>
> 2015-03-20 Renlin Li <renlin.li@arm.com>
>
> * simplify-rtx.c (simplify_unary_operation_1): Fix a typo. Enable two
> simplifications for UNSIGNED_FLOAT.
>
> gcc/testsuite/ChangeLog:
>
> 2015-03-20 Renlin Li <renlin.li@arm.com>
>
> * gcc.target/aarch64/unsigned-float.c: New.
> * gcc.target/arm/unsigned-float.c: New.
OK for the trunk.
jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1
2015-03-20 17:03 [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1 Renlin Li
2015-04-16 4:49 ` Jeff Law
@ 2015-06-16 13:35 ` Christophe Lyon
2015-06-23 11:06 ` Renlin Li
1 sibling, 1 reply; 5+ messages in thread
From: Christophe Lyon @ 2015-06-16 13:35 UTC (permalink / raw)
To: Renlin Li; +Cc: gcc-patches, Ramana Radhakrishnan, Richard Earnshaw
On 20 March 2015 at 18:03, Renlin Li <renlin.li@arm.com> wrote:
> Hi all,
>
> This is a simple patch to enable two simplifications for UNSIGNED_FLOAT
> expression.
>
> For the following rtx patterns, they can be simplified when the integer x
> can be
> represented in float mode without precision loss:
>
> float_truncate (float x) --> float x
> float_extend (float x) --> float x
>
> Those two simplifications are also applicable to UNSIGNED_FLOAT expression.
>
> For example, compile the following code using aarch64-none-elf toolchain
> with -O1 flag.
> double
> f1 (uint16_t x)
> {
> return (double)(float)x;
> }
> Before the change, the compiler generates the following code:
> f1:
> uxth w0, w0
> ucvtf s0, w0
> fcvt d0, s0
> ret
> After the change, the following simplified asm code snipts are generated.
> f1:
> uxth w0, w0
> ucvtf d0, w0
> ret
>
>
> aarch64-none-elf regression test runs Okay. x86_64 bootstraps Okay.
> Okay to commit?
>
> gcc/ChangeLog:
>
> 2015-03-20 Renlin Li <renlin.li@arm.com>
>
> * simplify-rtx.c (simplify_unary_operation_1): Fix a typo. Enable two
> simplifications for UNSIGNED_FLOAT.
>
> gcc/testsuite/ChangeLog:
>
> 2015-03-20 Renlin Li <renlin.li@arm.com>
>
> * gcc.target/aarch64/unsigned-float.c: New.
> * gcc.target/arm/unsigned-float.c: New.
This new test fails on ARM targets defaulting to hard-float which have
no softfp multilib.
I'm not sure about the best way to fix this.
Note that dg-require-effective-target arm_vfp_ok passes, but the
testcase fails because it includes stdint.h, leading to:
sysroot-arm-none-linux-gnueabihf/usr/include/gnu/stubs.h:7:29: fatal
error: gnu/stubs-soft.h: No such file or directory
Christophe.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1
2015-06-16 13:35 ` Christophe Lyon
@ 2015-06-23 11:06 ` Renlin Li
2015-07-06 17:08 ` Kyrill Tkachov
0 siblings, 1 reply; 5+ messages in thread
From: Renlin Li @ 2015-06-23 11:06 UTC (permalink / raw)
To: Christophe Lyon; +Cc: gcc-patches, Ramana Radhakrishnan, Richard Earnshaw
[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]
Hi Christophe,
Yes, we have also noticed this failure.
Here I have a simple patch to remove the mfloat-abi option for
hard-float toolchain. The default abi is used.
For non-hardfloat toolchain, softfp abi is specified.
I have checked with arm-none-eabi and arm-none-linux-gnueabihf
toolchain, this problem should be resolved by this patch.
Okay to commit?
gcc/testsuite/ChangeLog:
2015-06-23 Renlin Li <renlin.li@arm.com>
* gcc.target/arm/unsigned-float.c: Different options for hf toolchain.
On 16/06/15 14:33, Christophe Lyon wrote:
> On 20 March 2015 at 18:03, Renlin Li <renlin.li@arm.com> wrote:
>> Hi all,
>>
>> This is a simple patch to enable two simplifications for UNSIGNED_FLOAT
>> expression.
>>
>> For the following rtx patterns, they can be simplified when the integer x
>> can be
>> represented in float mode without precision loss:
>>
>> float_truncate (float x) --> float x
>> float_extend (float x) --> float x
>>
>> Those two simplifications are also applicable to UNSIGNED_FLOAT expression.
>>
>> For example, compile the following code using aarch64-none-elf toolchain
>> with -O1 flag.
>> double
>> f1 (uint16_t x)
>> {
>> return (double)(float)x;
>> }
>> Before the change, the compiler generates the following code:
>> f1:
>> uxth w0, w0
>> ucvtf s0, w0
>> fcvt d0, s0
>> ret
>> After the change, the following simplified asm code snipts are generated.
>> f1:
>> uxth w0, w0
>> ucvtf d0, w0
>> ret
>>
>>
>> aarch64-none-elf regression test runs Okay. x86_64 bootstraps Okay.
>> Okay to commit?
>>
>> gcc/ChangeLog:
>>
>> 2015-03-20 Renlin Li <renlin.li@arm.com>
>>
>> * simplify-rtx.c (simplify_unary_operation_1): Fix a typo. Enable two
>> simplifications for UNSIGNED_FLOAT.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 2015-03-20 Renlin Li <renlin.li@arm.com>
>>
>> * gcc.target/aarch64/unsigned-float.c: New.
>> * gcc.target/arm/unsigned-float.c: New.
> This new test fails on ARM targets defaulting to hard-float which have
> no softfp multilib.
> I'm not sure about the best way to fix this.
>
> Note that dg-require-effective-target arm_vfp_ok passes, but the
> testcase fails because it includes stdint.h, leading to:
> sysroot-arm-none-linux-gnueabihf/usr/include/gnu/stubs.h:7:29: fatal
> error: gnu/stubs-soft.h: No such file or directory
>
> Christophe.
>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch; name=patch.diff, Size: 648 bytes --]
diff --git a/gcc/testsuite/gcc.target/arm/unsigned-float.c b/gcc/testsuite/gcc.target/arm/unsigned-float.c
index bb05c85..b9ed681 100644
--- a/gcc/testsuite/gcc.target/arm/unsigned-float.c
+++ b/gcc/testsuite/gcc.target/arm/unsigned-float.c
@@ -1,7 +1,8 @@
/* { dg-do compile } */
/* { dg-require-effective-target arm_vfp_ok } */
-/* { dg-options "-march=armv7-a -O1 -mfloat-abi=softfp" } */
/* { dg-skip-if "need fp instructions" { *-*-* } { "-mfloat-abi=soft" } { "" } } */
+/* { dg-options "-march=armv7-a -O1" } */
+/* { dg-additional-options "-mfloat-abi=softfp" { target { ! { arm_hf_eabi } } } } */
#include <stdint.h>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1
2015-06-23 11:06 ` Renlin Li
@ 2015-07-06 17:08 ` Kyrill Tkachov
0 siblings, 0 replies; 5+ messages in thread
From: Kyrill Tkachov @ 2015-07-06 17:08 UTC (permalink / raw)
To: Renlin Li, Christophe Lyon
Cc: gcc-patches, Ramana Radhakrishnan, Richard Earnshaw
On 23/06/15 11:43, Renlin Li wrote:
> Hi Christophe,
>
> Yes, we have also noticed this failure.
>
> Here I have a simple patch to remove the mfloat-abi option for
> hard-float toolchain. The default abi is used.
> For non-hardfloat toolchain, softfp abi is specified.
>
> I have checked with arm-none-eabi and arm-none-linux-gnueabihf
> toolchain, this problem should be resolved by this patch.
>
> Okay to commit?
Ok.
Thanks,
Kyrill
>
>
> gcc/testsuite/ChangeLog:
>
> 2015-06-23 Renlin Li <renlin.li@arm.com>
>
> * gcc.target/arm/unsigned-float.c: Different options for hf toolchain.
>
>
> On 16/06/15 14:33, Christophe Lyon wrote:
>> On 20 March 2015 at 18:03, Renlin Li <renlin.li@arm.com> wrote:
>>> Hi all,
>>>
>>> This is a simple patch to enable two simplifications for UNSIGNED_FLOAT
>>> expression.
>>>
>>> For the following rtx patterns, they can be simplified when the integer x
>>> can be
>>> represented in float mode without precision loss:
>>>
>>> float_truncate (float x) --> float x
>>> float_extend (float x) --> float x
>>>
>>> Those two simplifications are also applicable to UNSIGNED_FLOAT expression.
>>>
>>> For example, compile the following code using aarch64-none-elf toolchain
>>> with -O1 flag.
>>> double
>>> f1 (uint16_t x)
>>> {
>>> return (double)(float)x;
>>> }
>>> Before the change, the compiler generates the following code:
>>> f1:
>>> uxth w0, w0
>>> ucvtf s0, w0
>>> fcvt d0, s0
>>> ret
>>> After the change, the following simplified asm code snipts are generated.
>>> f1:
>>> uxth w0, w0
>>> ucvtf d0, w0
>>> ret
>>>
>>>
>>> aarch64-none-elf regression test runs Okay. x86_64 bootstraps Okay.
>>> Okay to commit?
>>>
>>> gcc/ChangeLog:
>>>
>>> 2015-03-20 Renlin Li <renlin.li@arm.com>
>>>
>>> * simplify-rtx.c (simplify_unary_operation_1): Fix a typo. Enable two
>>> simplifications for UNSIGNED_FLOAT.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 2015-03-20 Renlin Li <renlin.li@arm.com>
>>>
>>> * gcc.target/aarch64/unsigned-float.c: New.
>>> * gcc.target/arm/unsigned-float.c: New.
>> This new test fails on ARM targets defaulting to hard-float which have
>> no softfp multilib.
>> I'm not sure about the best way to fix this.
>>
>> Note that dg-require-effective-target arm_vfp_ok passes, but the
>> testcase fails because it includes stdint.h, leading to:
>> sysroot-arm-none-linux-gnueabihf/usr/include/gnu/stubs.h:7:29: fatal
>> error: gnu/stubs-soft.h: No such file or directory
>>
>> Christophe.
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-07-06 17:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20 17:03 [PATCH] Enable two UNSIGNED_FLOAT simplifications in simplify_unary_operation_1 Renlin Li
2015-04-16 4:49 ` Jeff Law
2015-06-16 13:35 ` Christophe Lyon
2015-06-23 11:06 ` Renlin Li
2015-07-06 17:08 ` 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).