public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated
@ 2021-03-08 20:24 msebor at gcc dot gnu.org
  2021-03-08 21:36 ` [Bug tree-optimization/99473] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-08 20:24 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-06 23:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
2021-03-08 21:36 ` [Bug tree-optimization/99473] " pinskia at gcc dot gnu.org
2021-03-09  8:31 ` rguenth at gcc dot gnu.org
2021-04-26  9:01 ` cvs-commit at gcc dot gnu.org
2021-04-26  9:02 ` rguenth at gcc dot gnu.org
2023-05-06 23:17 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).