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

            Bug ID: 111217
           Summary: variant of cond-bool-2.c fails
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
static inline _Bool nand(_Bool a, _Bool b)
{
  _Bool t = 0;
  if (a) { if (b) t = 1; }
  return !t;
  //  return !(a && b);
}

_Bool f(int a, int b)
{
    return nand(nand(b, nand(a, a)), nand(a, nand(b, b)));
}
```

we get at ifcombine:
  <bb 2> [local count: 1073741824]:
  if (a_3(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870912]:
  if (b_2(D) != 0)
    goto <bb 6>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 536870912]:
  if (b_2(D) != 0)
    goto <bb 6>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 5> [local count: 536870912]:
  ...

  <bb 6> [local count: 536870912]:
  # iftmp.0_21 = PHI <1(3), 0(4)>

So we could swap these ifs around slighlty

 if (b_2(D) != 0) goto L1; else goto L2;
L1:
 if (a_3(D) != 0) goto L3; else goto L4;
L3: goto L4;
L4:
 iftmp.0_21 = PHI <1(3), 0(4)>
L1: goto bb5;

And then it will be optimized.

Reply via email to