This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A question about redudant load elimination
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Jiangning Liu <jiangning dot liu at arm dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 16 Nov 2011 12:00:55 +0100
- Subject: Re: A question about redudant load elimination
- References: <4ec0cb02.a424440a.6fba.ffffb618SMTPIN_ADDED@mx.google.com>
On Mon, Nov 14, 2011 at 9:01 AM, Jiangning Liu <jiangning.liu@arm.com> wrote:
> Hi,
>
> For this test case,
>
> int x;
> extern void f(void);
>
> void g(int *a)
> {
> ? ? ? ?a[x] = 1;
> ? ? ? ?if (x == 100)
> ? ? ? ? ? ? ? ?f();
> ? ? ? ?a[x] = 2;
> }
>
> For trunk, the x86 assembly code is like below,
>
> ? ? ? ?movl ? ?x, %eax
> ? ? ? ?movl ? ?16(%esp), %ebx
> ? ? ? ?movl ? ?$1, (%ebx,%eax,4)
> ? ? ? ?movl ? ?x, %eax ? // Is this a redundant one?
> ? ? ? ?cmpl ? ?$100, %eax
> ? ? ? ?je ? ? ?.L4
> ? ? ? ?movl ? ?$2, (%ebx,%eax,4)
> ? ? ? ?addl ? ?$8, %esp
> ? ? ? ?.cfi_remember_state
> ? ? ? ?.cfi_def_cfa_offset 8
> ? ? ? ?popl ? ?%ebx
> ? ? ? ?.cfi_restore 3
> ? ? ? ?.cfi_def_cfa_offset 4
> ? ? ? ?ret
> ? ? ? ?.p2align 4,,7
> ? ? ? ?.p2align 3
> .L4:
> ? ? ? ?.cfi_restore_state
> ? ? ? ?call ? ?f
> ? ? ? ?movl ? ?x, %eax
> ? ? ? ?movl ? ?$2, (%ebx,%eax,4)
> ? ? ? ?addl ? ?$8, %esp
> ? ? ? ?.cfi_def_cfa_offset 8
> ? ? ? ?popl ? ?%ebx
> ? ? ? ?.cfi_restore 3
> ? ? ? ?.cfi_def_cfa_offset 4
> ? ? ? ?Ret
>
> Is the 2nd "movl x, %eax" is a redundant one for single thread programming
> model? If yes, can this be optimized away?
f() may change the value of x, so you cannot optimize away the load on that
execution path.
> Thanks,
> -Jiangning
>
>
>
>