https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113176
Bug ID: 113176
Summary: `(n / 4) ? n / 4 : 0` is not optimized to just `n /4`
Product: gcc
Version: 14.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:
```
int unopt(int n) {
if (n / 4)
return n / 4;
else
return 0;
}
int unopt1(int n) {
return (n / 4) ? n / 4 : 0;
}
int opt(int n) {
return n / 4;
}
```
I would have expected unopt be transformed into opt but currently it is not.
This is because GCC decides to transform `(n / 4) != 0` into `(unsigned int) n
+ 3 > 6`.