http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12395
--- Comment #17 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-15
11:24:13 UTC ---
(In reply to comment #16)
> To optimize
>
> void foo() {
> extern int a;
> if(++a) ++a;
> }
>
> we need to have partial dead store elimination, basically sink the store
> to after the condition:
>
> void bar() {
> extern int a;
> int tmp = a;
> if (++tmp)
> ++tmp;
> a = tmp;
> }
>
> bar:
> movl a, %eax
> pushl %ebp
> movl %esp, %ebp
> movl %eax, %edx
> addl $1, %edx
> je .L5
> leal 2(%eax), %edx
> .L5:
> movl %edx, a
> popl %ebp
> ret
>
> we'd then assemble this to similar code as the testcase from comment #2.
>
> See also PR41490, though a working tree-ssa-sink would at most generate
>
> void foobar() {
> extern int a;
> int tmp = a;
> if (++tmp)
> {
> ++tmp;
> a = tmp;
> }
> else
> a = tmp;
> }
>
> Still an improvement as we'd propagate zero to the second store:
>
> foobar:
> movl a, %eax
> pushl %ebp
> movl %esp, %ebp
> cmpl $-1, %eax
> jne .L9
> movl $0, a
> popl %ebp
> ret
> .p2align 4,,7
> .p2align 3
> .L9:
> addl $2, %eax
> movl %eax, a
> popl %ebp
> ret
It now does this (for 4.7).