* [PATCH] Avoid tree NRV on is_gimple_reg_type result types (PR c/35739)
@ 2008-04-16 12:08 Jakub Jelinek
2008-04-16 12:13 ` Richard Guenther
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2008-04-16 12:08 UTC (permalink / raw)
To: gcc-patches
Hi!
If result is aggregate_value_p, but also a GIMPLE reg (e.g. when ABI
says it should be passed into memory), doing NRV optimization can result
in non-gimple - <result> isn't valid GIMPLE reg in that case, so NRV
can create non-GIMPLE like <result> = <result> + 3;
Also, in some cases it can hurt optimizations, as <result> must live
in memory wherever it will be replaced, but without NRV optimization
it is only stored at the end of function before returning to the <result>
memory slot.
Bootstrapped/regtested on x86_64-linux/trunk, bootstrap/regtest on 4
linux arches/4.3 is ongoing.
Ok for trunk/4.3?
2008-04-15 Jakub Jelinek <jakub@redhat.com>
PR c/35739
* tree-nrv.c (tree_nrv): Don't optimize if result_type is GIMPLE
reg type.
* gcc.dg/dfp/pr35739.c: New test.
--- gcc/tree-nrv.c.jj 2008-04-04 15:12:00.000000000 +0200
+++ gcc/tree-nrv.c 2008-04-15 20:00:07.000000000 +0200
@@ -1,5 +1,5 @@
/* Language independent return value optimizations
- Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
This file is part of GCC.
@@ -115,6 +115,11 @@ tree_nrv (void)
if (!aggregate_value_p (result, current_function_decl))
return 0;
+ /* If a GIMPLE type is returned in memory, finalize_nrv_r might create
+ non-GIMPLE. */
+ if (is_gimple_reg_type (result_type))
+ return 0;
+
/* Look through each block for assignments to the RESULT_DECL. */
FOR_EACH_BB (bb)
{
--- gcc/testsuite/gcc.dg/dfp/pr35739.c.jj 2008-04-15 20:02:55.000000000 +0200
+++ gcc/testsuite/gcc.dg/dfp/pr35739.c 2008-04-15 20:18:15.000000000 +0200
@@ -0,0 +1,16 @@
+/* PR c/35739 */
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O -fpreprocessed -fmudflap" } */
+
+_Decimal128
+foo (int n, ...)
+{
+ int i;
+ _Decimal128 j = 0;
+ __builtin_va_list ap;
+ __builtin_va_start (ap, n);
+ for (i = 0; i < n; i++)
+ j += __builtin_va_arg (ap, _Decimal128);
+ __builtin_va_end (ap);
+ return j;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Avoid tree NRV on is_gimple_reg_type result types (PR c/35739)
2008-04-16 12:08 [PATCH] Avoid tree NRV on is_gimple_reg_type result types (PR c/35739) Jakub Jelinek
@ 2008-04-16 12:13 ` Richard Guenther
0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2008-04-16 12:13 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Wed, Apr 16, 2008 at 12:59 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> If result is aggregate_value_p, but also a GIMPLE reg (e.g. when ABI
> says it should be passed into memory), doing NRV optimization can result
> in non-gimple - <result> isn't valid GIMPLE reg in that case, so NRV
> can create non-GIMPLE like <result> = <result> + 3;
> Also, in some cases it can hurt optimizations, as <result> must live
> in memory wherever it will be replaced, but without NRV optimization
> it is only stored at the end of function before returning to the <result>
> memory slot.
>
> Bootstrapped/regtested on x86_64-linux/trunk, bootstrap/regtest on 4
> linux arches/4.3 is ongoing.
>
> Ok for trunk/4.3?
Ok.
Thanks,
Richard.
> 2008-04-15 Jakub Jelinek <jakub@redhat.com>
>
> PR c/35739
> * tree-nrv.c (tree_nrv): Don't optimize if result_type is GIMPLE
> reg type.
>
> * gcc.dg/dfp/pr35739.c: New test.
>
> --- gcc/tree-nrv.c.jj 2008-04-04 15:12:00.000000000 +0200
> +++ gcc/tree-nrv.c 2008-04-15 20:00:07.000000000 +0200
> @@ -1,5 +1,5 @@
> /* Language independent return value optimizations
> - Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
> + Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
>
> This file is part of GCC.
>
> @@ -115,6 +115,11 @@ tree_nrv (void)
> if (!aggregate_value_p (result, current_function_decl))
> return 0;
>
> + /* If a GIMPLE type is returned in memory, finalize_nrv_r might create
> + non-GIMPLE. */
> + if (is_gimple_reg_type (result_type))
> + return 0;
> +
> /* Look through each block for assignments to the RESULT_DECL. */
> FOR_EACH_BB (bb)
> {
> --- gcc/testsuite/gcc.dg/dfp/pr35739.c.jj 2008-04-15 20:02:55.000000000 +0200
> +++ gcc/testsuite/gcc.dg/dfp/pr35739.c 2008-04-15 20:18:15.000000000 +0200
> @@ -0,0 +1,16 @@
> +/* PR c/35739 */
> +/* { dg-do compile { target *-*-linux* } } */
> +/* { dg-options "-O -fpreprocessed -fmudflap" } */
> +
> +_Decimal128
> +foo (int n, ...)
> +{
> + int i;
> + _Decimal128 j = 0;
> + __builtin_va_list ap;
> + __builtin_va_start (ap, n);
> + for (i = 0; i < n; i++)
> + j += __builtin_va_arg (ap, _Decimal128);
> + __builtin_va_end (ap);
> + return j;
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-04-16 11:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-16 12:08 [PATCH] Avoid tree NRV on is_gimple_reg_type result types (PR c/35739) Jakub Jelinek
2008-04-16 12:13 ` Richard Guenther
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).