------- Comment #16 from rguenth at gcc dot gnu dot org  2010-02-13 10:23 
-------
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


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
  BugsThisDependsOn|                            |41490


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12395

Reply via email to