https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128329
Bug ID: 128329
Summary: `(a == 0 ? b : 0) | a` -> `a == 0 ? b : a`
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64
Created attachment 66053
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66053&action=edit
testcase
This was found while looking into PR 127145 of trying to get a better
branchless involving the spaceship operator.
The attached testcase produces:
```
_3 = tmp_5(D) == 0;
tmp3_8 = _3 ? tmp1_7(D) : 0;
_9 = tmp_5(D) | tmp3_8;
```
But this is just:
```
_3 = tmp_5(D) == 0;
_9 = _3 ? _3 ? tmp1_7(D) : tmp_5(D)
```
For riscv (with zicond) this does not make a difference but for targets like
aarch64 or x86, there is an extra ior.
This should be an easy 2 match patterns.