https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114502
Bug ID: 114502
Summary: Missed sccp final value with `a = -a`
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: ---
Inspired by PR 114485 and PR 114476. I noticed that SCCP is not figuring out
what happens when just doing negative of the value. These days we do handle
`^&|` so handling unary - should be in a similar way I suspect.
Testcase:
```
[[gnu::noipa]]
unsigned f(unsigned c) {
for (int i = 0; i < 1024; i ++) {
c *= -1;
}
return c;
}
```
Note non-constant loop bounds handling is in a different bug report even.
The above should be optimized to just `return -c;` for -O2; We do optimize it
at -O3 but that is because the complete loop unroller figures out the cost for
the loop is nothing.