| Issue |
202344
|
| Summary |
[X86] Failure to create BLSI instruction from integer reprensentable as i8
|
| Labels |
backend:X86,
missed-optimization
|
| Assignees |
|
| Reporter |
RKSimon
|
Splatting the first set bit of a comparison mask:
```c
#include <x86intrin.h>
__m128i idx(__m128 x) {
x = _mm_cmpgt_ps(x,_mm_setzero_ps());
int r = _mm_movemask_ps(x);
return _mm_set1_epi8(_blsi_u32(r));
}
```
-O3 -march=x860-64-v3
```ll
define <2 x i64> @idx(<4 x float> %x) {
entry:
%0 = fcmp ogt <4 x float> %x, zeroinitializer
%1 = bitcast <4 x i1> %0 to i4
%2 = zext i4 %1 to i8
%sub.i = sub nsw i8 0, %2
%and.i = and i8 %2, %sub.i
%vecinit.i = insertelement <16 x i8> poison, i8 %and.i, i64 0
%vecinit15.i = shufflevector <16 x i8> %vecinit.i, <16 x i8> poison, <16 x i32> zeroinitializer
%3 = bitcast <16 x i8> %vecinit15.i to <2 x i64>
ret <2 x i64> %3
}
```
results in
```asm
idx:
vxorps %xmm1, %xmm1, %xmm1
vcmpltps %xmm0, %xmm1, %xmm0
vmovmskps %xmm0, %eax
movl %eax, %ecx
negb %cl
andb %al, %cl
vmovd %ecx, %xmm0
vpbroadcastb %xmm0, %xmm0
retq
```
but could be:
```asm
idx:
vxorps %xmm1, %xmm1, %xmm1
vcmpltps %xmm0, %xmm1, %xmm0
vmovmskps %xmm0, %eax
blsil %eax, %eax
vmovd %eax, %xmm0
vpbroadcastb %xmm0, %xmm0
retq
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs