<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111431>111431</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AVX-512] Identify opportunities for `kunpckdq`
</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>
```zig
export fn foo(a: @Vector(32, u8), b: @Vector(32, u8), c: @Vector(32, u8)) u64 {
const b1: u32 = @bitCast(a == b);
const b2: u32 = @bitCast(a == c);
return (@as(u64, b1) << 32) | b2;
}
```
```llvm
define dso_local i64 @foo(<32 x i8> %0, <32 x i8> %1, <32 x i8> %2) local_unnamed_addr {
Entry:
%3 = icmp eq <32 x i8> %0, %1
%4 = bitcast <32 x i1> %3 to i32
%5 = icmp eq <32 x i8> %0, %2
%6 = bitcast <32 x i1> %5 to i32
%7 = zext i32 %4 to i64
%8 = shl nuw i64 %7, 32
%9 = zext i32 %6 to i64
%10 = or disjoint i64 %8, %9
ret i64 %10
}
```
This compiles like so: ([Godbolt link](https://zig.godbolt.org/z/daeo4GWhr))
```asm
foo:
vpcmpeqb k0, ymm0, ymm1
kmovd ecx, k0
vpcmpeqb k0, ymm0, ymm2
kmovd eax, k0
shl rcx, 32
or rax, rcx
vzeroupper
ret
```
I would think it should be:
```asm
foo:
vpcmpeqb k0, ymm0, ymm1
vpcmpeqb k1, ymm0, ymm2
kunpckdq k0, k0, k1
kmovd rax, k0
vzeroupper
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU1zqzoM_TXKRtOMkflcsGiTmzt3_6bv7TqAncQ3gKlt-vXr39iQpmna3m4ukwkg6RzJxxKurFW7XsoSkhtI1otqdHttytuqVaIyh0WtxXMJKZt-L2oHbA3sWj4N2jjc9rjVGiivgF8jxOxWNk4boJwT0ArHHKjwD_Uf_M2X_gLHN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