This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize initialization from compound literals (PR tree-optimization/33723)
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Jakub Jelinek" <jakub at redhat dot com>
- Cc: "Joseph Myers" <joseph at codesourcery dot com>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 29 Oct 2007 22:52:32 +0100
- Subject: Re: [PATCH] Optimize initialization from compound literals (PR tree-optimization/33723)
- References: <20071029213153.GJ5451@devserv.devel.redhat.com>
On 10/29/07, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> If the address of an compound literal is never taken and it is only
> used as initializer to some variable, I believe a conforming program
> can't find out whether we are first initializing some anonymous variable
> and then copying that anonymous variable to the user var, or initializing
> that user var directly. When SRA is not able to scalarize it (as shown
> by the testcase which is modelled from using e.g.
> mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
> condvar = (pthread_cond_t) PTHREAD_COND_INITIALIZER;
> or
> rwlock = (pthread_rwlock_t) PTHREAD_RWLOCK_INITIALIZER;
> with glibc), this then survives until assembly.
> The following patch optimizes this by initializing the variable to
> the initializer of the compound literal if it's address has never been
> taken. The generated assembly looks much better on x86_64-linux.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
This is ok.
Thanks,
Richard.
> 2007-10-29 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/33723
> * c-gimplify.c (c_gimplify_expr): Optimize INIT_EXPR or
> MODIFY_EXPR with non-addressable COMPOUND_LITERAL_EXPR as source.
>
> * gcc.c-torture/execute/20071029-1.c: New test.
> * gcc.dg/tree-ssa/pr33723.c: New test.