<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80122>80122</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Simple condition fusion which works on scalars should work with vectors too
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Validark
</td>
</tr>
</table>
<pre>
If you have a function like this:
```zig
fn scalar(a: u64, b: u64) bool {
return 0 == a and 0 == b;
}
```
LLVM will optimize it to `0 == (a | b)`:
```asm
scalar:
or rdi, rsi
sete al
ret
```
Unfortunately, this seems not to be the case for vectors.
```zig
fn vec_unoptimized(vec1: Chunk, vec2: Chunk) bool {
return 0 == std.simd.countTrues(vec1 > @as(Chunk, @splat(0))) and
0 == std.simd.countTrues(vec2 > @as(Chunk, @splat(0)));
}
```
This x86-64 assembly is given:
```asm
vec_unoptimized:
vptest ymm0, ymm0
je .LBB0_3
xor eax, eax
vzeroupper
ret
.LBB0_3:
vptest ymm1, ymm1
sete al
vzeroupper
ret
```
I'd much rather have:
```asm
vec_optimized:
vpor ymm0, ymm1, ymm0
vptest ymm0, ymm0
sete al
vzeroupper
ret
```
[Godbolt link](https://zig.godbolt.org/z/aoKTcTW9h)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1z4jgQ_TXi0hWXLGFjH3wYhmVrarOnzc4ep2SpwRpki9IHhPz6LdmQhOwkYSkXDe1W9-vXr9TCe70dEBtSLEmxmokYOuua78JoJdxu1lp1ar5t4GQjdOKAIGATBxm0HcDoHULotCf8C6ErQi_fJZ2eJ72dPJsBvBRGOMIqQfgXiOWcsK_QPv-uobXWAFkspxMAAA5DdANQIHxF-AoEiEG9_G0JPweTxepN5ddw7u-__wlHbQzYfdC9fkLQAYIFUtLnZAkYkEWCxOqU4J2WhO8nz7mfSxicP9ZN1imdGnReX7_3GBCEuXY6DB_g_3vYWBfiIAKaU0qaKAeP2HsY7NhJm-aAIIVH2FgHB5TBOp99OpUDyh9xuPCiCKsOKPM0la9dHHap2gEle-W4ZVA-qMzrXmXSxiE8uIj-nBkI_w3InIrkeC5B5tTvjQiEVTTRPz5p2Nc0AdxQgv2PEjcK6CHx_ViVd-UchPfYt-YE2sNWH3D4VChvKX6rmMM-oA8Ap76nCelop4ifOIVk98sl_cGvzz2epYbiMR1L5jrvEzob93t0Z_-zyi7pPkCSn5Hkv1AvwIuA_1PkJkV_I2yhoI-yAydCh268Wm5i8iMeJ0Je8Zi_4fMDqt9r8FMyf9kgKZa_W9VaE8DoYUeKFWFVF8J-vCrZmrD1k95m2ykms26bPISthf3jQT78U3eE1TPVcFXzWsywyRe0LGte5XTWNVgpoQTSumWK0TwvFC6KoqULJllblHymG0bZnOY8pzUvC5pxxecFlZKWsuQVr8mcYi-0yYw59Kn8THsfsaloztjMiBaNHzcCYwMeYXxJGEsLwjXpzF0bt57MqdE--JcsQQeDzV-63xsEaQelx0WxiT6ZY6dlB0frdh7sZSN48J2NRo1-OOrQXW4vCNbOojPNNXFbHbrYZtL2hK1T5bO52zv7E2UgbD3i9YStx37-DQAA__-Ore4E">