[Bug tree-optimization/112628] New: `~a < -a` can be optimized to `a != 0` for unsigned types

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Nov 19 17:38:47 GMT 2023


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

            Bug ID: 112628
           Summary: `~a < -a` can be optimized to `a != 0` for unsigned
                    types
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
unsigned fu(unsigned a)
{
  return (~a) < -a;
}
```

This can be optimized to just `a != 0` like it is on the RTL level due to
optizing to ADD_OVERFLOW which started in GCC 11.


More information about the Gcc-bugs mailing list