https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127502
Bug ID: 127502
Summary: `neg (a ? x : 0)` -> (a ? -x : 0) not happening on the
rtl level
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, missed-optimization
Severity: enhancement
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
Take:
```
signed
f (signed x, signed tt)
{
int t = 0;
if (tt != 10)
t = 1;
return -(x * t);
}
```
Currently this forms:
```
cmp w1, 10
csel w0, w0, wzr, ne
neg w0, w0
```
This is because we don't prop the neg into the conditional which we can do.
That is:
```
Trying 9 -> 10:
9: r107:SI={(cc:CC!=0)?r109:SI:0}
REG_DEAD r109:SI
REG_DEAD cc:CC
10: r106:SI=-r107:SI
REG_DEAD r107:SI
Failed to match this instruction:
(set (reg:SI 106 [ _5 ])
(neg:SI (if_then_else:SI (ne (reg:CC 66 cc)
(const_int 0 [0]))
(reg:SI 109 [ xD.4512 ])
(const_int 0 [0]))))
```
The neg can go around the `reg:SI 109`. Though the question becomes which
version is Canonical. So maybe this is a target issue. Either way it is an
easy fix (add a pattern or add a simplify-rtx code to do the prop only if the
second operand is 0).