https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123009
Bug ID: 123009
Summary: (AArch64) Missed CSE on ((unsigned)x - y > x) pattern
on first instance of function
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: Explorer09 at gmail dot com
Target Milestone: ---
This common subexpression elimination miss is specific to AArch64 target of
GCC.
And it's interesting because, according to my testing, the miss only happens on
the _first_ instance of the function definition. If there are subsequent
function definitions with content identical to the first one, those subsequent
functions will get the optimizations as expected.
```c
unsigned int func1(unsigned int x, unsigned int y) {
if (x - y > x)
return 0;
return x - y;
}
unsigned int func1_second(unsigned int x, unsigned int y) {
if (x - y > x)
return 0;
return x - y;
}
```
https://godbolt.org/z/co41hf446
ARM64 GCC 15.2.0 with `-O2` option produces:
```assembly
func1:
sub w2, w0, w1
cmp w1, w0
csel w0, w2, wzr, ls
ret
func1_second:
subs w2, w0, w1
csel w0, w2, wzr, cs
ret
```