[Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 8 20:24:43 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473

            Bug ID: 99473
           Summary: redundant conditional zero-initialization not
                    eliminated
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

All three functions below should result in equivalently optimal code (and,
ideally IL) but only g1() and g3() result in the same assembly, and only g1()
result in optimal, branchless GIMPLE.

$ cat x.c && gcc -O2 -S -Wall -o/dev/stdout x.c
void f (int*);

void g1 (int i)
{
  int x;
  if (i)
    x = i;
  else
    x = 0;
  f (&x);
}


void g2 (int i)
{
  int x;
  if (i) {
    x = i;
    f (&x);
  }
  else {
    x = 0;
    f (&x);
  }
}

void g3 (int i)
{
  int x = 0;
  if (i)
    x = i;
  f (&x);
}
        .file   "x.c"
        .text
        .p2align 4
        .globl  g1
        .type   g1, @function
g1:
.LFB0:
        .cfi_startproc
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        movl    %edi, 12(%rsp)
        leaq    12(%rsp), %rdi
        call    f
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE0:
        .size   g1, .-g1
        .p2align 4
        .globl  g2
        .type   g2, @function
g2:
.LFB1:
        .cfi_startproc
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        testl   %edi, %edi
        je      .L5
        movl    %edi, 12(%rsp)
        leaq    12(%rsp), %rdi
        call    f
        addq    $24, %rsp
        .cfi_remember_state
        .cfi_def_cfa_offset 8
        ret
        .p2align 4,,10
        .p2align 3
.L5:
        .cfi_restore_state
        leaq    12(%rsp), %rdi
        movl    $0, 12(%rsp)
        call    f
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE1:
        .size   g2, .-g2
        .p2align 4
        .globl  g3
        .type   g3, @function
g3:
.LFB2:
        .cfi_startproc
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        movl    %edi, 12(%rsp)
        leaq    12(%rsp), %rdi
        call    f
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE2:
        .size   g3, .-g3
        .ident  "GCC: (GNU) 11.0.1 20210308 (experimental)"
        .section        .note.GNU-stack,"",@progbits


More information about the Gcc-bugs mailing list