| Issue |
233279
|
| Summary |
[CGP][X86][AVX512] failed to fold isnan pattern into llvm.is.fpclass
|
| Labels |
backend:X86,
llvm:codegen,
missed-optimization
|
| Assignees |
|
| Reporter |
Andarwinux
|
```c++
typedef bool i1 [[clang::ext_vector_type(16)]];
typedef float f32 [[clang::ext_vector_type(16)]];
i1 foo(f32 &a){
i1 x;
for(int i=0;i<16;i++){
x[i]=__builtin_isinf(a[i]);
}
return x;
}
i1 bar(f32 &a){
i1 x;
for(int i=0;i<16;i++){
x[i]=__builtin_isnan(a[i]);
}
return x;
}
```
CGP / IR before codegen
```llvm
define dso_local noundef i16 @foo(ptr nofree noundef nonnull readonly align 64 captures(none) dereferenceable(64) %a) local_unnamed_addr {
entry:
%0 = load <16 x float>, ptr %a, align 64
%1 = call <16 x i1> @llvm.is.fpclass.v16f32(<16 x float> %0, /* (inf) */ i32 516)
%2 = bitcast <16 x i1> %1 to i16
ret i16 %2
}
define dso_local noundef i16 @bar(ptr nofree noundef nonnull readonly align 64 captures(none) dereferenceable(64) %a) local_unnamed_addr {
entry:
%0 = load <16 x float>, ptr %a, align 64
%1 = fcmp uno <16 x float> %0, zeroinitializer
%2 = bitcast <16 x i1> %1 to i16
ret i16 %2
}
```
codegen after #230281
```asm
.LCPI0_0:
.long 0x7fffffff
.LCPI0_1:
.long 0x7f800000
foo(float vector[16]&):
vfpclasspsz $24, (%rdi), %k0
kmovd %k0, %eax
retq
bar(float vector[16]&):
vmovaps zmm0, zmmword ptr [rdi]
vcmpunordps k0, zmm0, zmm0
kmovd eax, k0
vzeroupper
ret
```
After #230281, x86 will lower IS_FPCLASS to VFPCLASS, but since CGP didn't fold isnan pattern into IS_FPCLASS, isnan is still lowered to vcmpunordps instead of vfpclassps. The key difference is vcmpunordps is two-source operand, while vfpclassps is single-source operand, so vfpclassps can be fused with load but vcmpunordps cannot.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs