Skip to content

[X86] lowerFPToIntToFP - handle UI2FP on AVX512VL targets and i64 types on AVX512DQ targets #160111

@RKSimon

Description

@RKSimon

https://zig.godbolt.org/z/v3rqr86P1

We attempt to vectorize scalar fp->int->fp round trips to avoid transfer from the FPU to the GPRs and back again:

define double @scvtf64_i32(double %a0) {
    %ii = fptosi double %a0 to i32
    %ff = sitofp i32 %ii to double
    ret double %ff
}
define float @scvtf32_i32(float %a0) {
    %ii = fptosi float %a0 to i32
    %ff = sitofp i32 %ii to float
    ret float %ff
}
scvtf64_i32: # @scvtf64_i32
  vcvttpd2dq %xmm0, %xmm0
  vcvtdq2pd %xmm0, %xmm0
  retq
scvtf32_i32: # @scvtf32_i32
  vcvttps2dq %xmm0, %xmm0
  vcvtdq2ps %xmm0, %xmm0
  retq

This is currently only performed for f64/32 <-> i32 legal SSE2+ FP_TO_SINT/SINT_TO_FP conversions.

AVX512VL could handle this for FP_TO_UINT/UINT_TO_FP conversions as well (AVX512F if we widen to 512-bits instead of 128-bit).

AV512DQ+AVX512VL could handle this for f64/32 <-> i64 SINT and UINT conversions as well.

This will require adjusting lowerFPToIntToFP to recognize FP_TO_UINT/UINT_TO_FP patterns on AVX512VL targets and i64 scalars on AV512DQ+AVX512VL targets, along with any additional test coverage that we don't already have.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions