https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118317
Bug ID: 118317
Summary: `len - (len != 0) + 1` should optimize to `len == 0 ?
1 : len`
Product: gcc
Version: 15.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:
```
unsigned bar(unsigned len)
{
unsigned t = len - (len != 0) + 1;
return t;
}
unsigned bar1(unsigned len)
{
return len == 0 ? 1 : len;
}
```
These 2 should produce the same code.
For unsigned, MAX_EXPR could be used.
Noticed while looking at PR 118316 on what LLVM was doing for the loop.