This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Optimize initialization from compound literals (PR tree-optimization/33723)


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]