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

            Bug ID: 127819
           Summary: `a == CST & (a + CST2 < CST3)` should be optimized
                    before reassociation
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: easyhack, 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 g();
void src(unsigned char x)
{
  unsigned char offset = x + 1;
  if (offset < 3u)
   {
    if (x == 0xff)
      g();
   }
}
```

I would have thought ifcombine would have optimized this into just `x==255` but
it takes into reassociation to do the optimization.

This comes originally from https://github.com/llvm/llvm-project/issues/230800
but since reassociation is able to optimize this, this is not as important but
optimizing it earlier can allow other optimizations to happen too.

Reply via email to