[Bug tree-optimization/122181] New: CSE of phi nodes during phiopt

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 6 21:31:50 GMT 2025


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

            Bug ID: 122181
           Summary: CSE of phi nodes during phiopt
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
void f(bool *c, int d)
{
  if (d)
  {
    c[0] = 1;
    c[1] = 1;
  }
  else
  {
    c[0] = 0;
    c[1] = 0;
  }
}
```

With approved (but not applied when this bug was filed) patches in phiopt1 we
get:
```
  <bb 2> :
  if (d_4(D) != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  goto <bb 5>; [INV]

  <bb 4> :

  <bb 5> :
  # cstore_1 = PHI <1(3), 0(4)>
  # cstore_11 = PHI <1(3), 0(4)>
```

But since cstore_1 and cstore_11 are the same type and values we should be able
to optimize this to just:
cstore_1 = d_4(D) != 0;

This requires to CSEing of the phi nodes.

This was mentioned in the review of a related but different patch:
https://gcc.gnu.org/pipermail/gcc-patches/2025-October/696728.html


More information about the Gcc-bugs mailing list