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

            Bug ID: 123103
           Summary: missed optimization for redundant conditional
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, when compiling the following reduced code with -O3, GCC generates
redundant instructions that could be optimized away.

Reduced code (from ABC project
https://github.com/berkeley-abc/abc/blob/362661f00d0ee8b8f15feb6dd2d14c10c4c03640/src/aig/gia/giaPf.c#L777):

https://godbolt.org/z/6rh39hrPd
typedef struct a b;
struct a {
  unsigned aa;
  int c[]
};
int t1, t2, t3;
int ab(b *d) {
  int e=t1, f=t2;
  if (d->c[e])
    return 0;
  if (f)
    return 1;
}
int g(b **h) {
  int i=t3;
  for (;;)
    if (h && ab(h[i]))
      h[i]->aa = 1;
}

Assembly generated by GCC -O3 includes the following block:
.L8:
        movl    t2(%rip), %eax
        testl   %eax, %eax
        jne     .L10
        movl    $1, %eax
        testl   %eax, %eax
        je      .L14
.L10:
        movl    $1, (%rcx)
        movl    t1(%rip), %edx
.L14:

This block is functionally equivalent to a much simpler sequence:
.L8:
        movl    $1, (%rcx)
        movl    t1(%rip), %edx
.L14:

Reply via email to