Files
clang-p2996/llvm/test/CodeGen/X86/fp-i129.ll
Freddy Ye 89f36dd8f3 [X86] Add ExpandLargeFpConvert Pass and enable for X86
As stated in
https://discourse.llvm.org/t/rfc-llc-add-expandlargeintfpconvert-pass-for-fp-int-conversion-of-large-bitint/65528,
this implementation is very similar to ExpandLargeDivRem, which expands
‘fptoui .. to’, ‘fptosi .. to’, ‘uitofp .. to’, ‘sitofp .. to’ instructions
with a bitwidth above a threshold into auto-generated functions. This is
useful for targets like x86_64 that cannot lower fp convertions with more
than 128 bits. The expanded nodes are referring from the IR generated by
`compiler-rt/lib/builtins/floattidf.c`, `compiler-rt/lib/builtins/fixdfti.c`,
and etc.

Corner cases:
1. For fp16: as there is no related builtins added in compliler-rt. So I
mainly utilized the fp32 <-> fp16 lib calls to implement.
2. For fp80: as this pass is soft fp emulation and no fp80 instructions can
help in this problem. I recommend users to deprecate this usage. For now, the
implementation uses fp128 as the temporary conversion type and inserts
fptrunc/ext at top/end of the function.
3. For bf16: as clang FE currently doesn't support bf16 algorithm operations
(convert to int, float, +, -, *, ...), this patch doesn't consider bf16 for
now.
4. For unsigned FPToI: since both default hardware behaviors and libgcc are
ignoring "returns 0 for negative input" spec. This pass follows this old way
to ignore unsigned FPToI. See this example:
https://gcc.godbolt.org/z/bnv3jqW1M

The end-to-end tests are uploaded at https://reviews.llvm.org/D138261

Reviewed By: LuoYuanke, mgehre-amd

Differential Revision: https://reviews.llvm.org/D137241
2022-12-01 13:47:43 +08:00

131 lines
2.9 KiB
LLVM

; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefixes=CHECK,X86
; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefixes=CHECK,X64
define i129 @fptosi_float(float %a) nounwind {
; CHECK-LABEL: fptosi_float:
; CHECK-NOT: call
%res = fptosi float %a to i129
ret i129 %res
}
define i129 @fptosi_double(double %a) nounwind {
; CHECK-LABEL: fptosi_double:
; CHECK-NOT: call
%res = fptosi double %a to i129
ret i129 %res
}
define i129 @fptosi_fp128(fp128 %a) nounwind {
; CHECK-LABEL: fptosi_fp128:
; CHECK-NOT: call
%res = fptosi fp128 %a to i129
ret i129 %res
}
define i129 @fptoui_float(float %a) nounwind {
; CHECK-LABEL: fptoui_float:
; CHECK-NOT: call
%res = fptoui float %a to i129
ret i129 %res
}
define i129 @fptoui_double(double %a) nounwind {
; CHECK-LABEL: fptoui_double:
; CHECK-NOT: call
%res = fptoui double %a to i129
ret i129 %res
}
define i129 @fptoui_fp128(fp128 %a) nounwind {
; CHECK-LABEL: fptoui_fp128:
; CHECK-NOT: call
%res = fptoui fp128 %a to i129
ret i129 %res
}
define float @sitofp_float(i129 %a) nounwind {
; CHECK-LABEL: sitofp_float:
; CHECK-NOT: call
%res = sitofp i129 %a to float
ret float %res
}
define double @sitofp_double(i129 %a) nounwind {
; CHECK-LABEL: sitofp_double:
; CHECK-NOT: call
%res = sitofp i129 %a to double
ret double %res
}
define fp128 @sitofp_fp128(i129 %a) nounwind {
; CHECK-LABEL: sitofp_fp128:
; CHECK-NOT: call
%res = sitofp i129 %a to fp128
ret fp128 %res
}
define float @uitofp_float(i129 %a) nounwind {
; CHECK-LABEL: uitofp_float:
; CHECK-NOT: call
%res = uitofp i129 %a to float
ret float %res
}
define double @uitofp_double(i129 %a) nounwind {
; CHECK-LABEL: uitofp_double:
; CHECK-NOT: call
%res = uitofp i129 %a to double
ret double %res
}
define fp128 @uitofp_fp128(i129 %a) nounwind {
; CHECK-LABEL: uitofp_fp128:
; CHECK-NOT: call
%res = uitofp i129 %a to fp128
ret fp128 %res
}
; higher sizes
define i257 @fptosi257_double(double %a) nounwind {
; CHECK-LABEL: fptosi257_double:
; CHECK-NOT: call
%res = fptosi double %a to i257
ret i257 %res
}
; half tests
define i257 @fptosi_half(half %a) nounwind {
; X86-LABEL: fptosi_half:
; X86: __gnu_h2f_ieee
;
; X64-LABEL: fptosi_half:
; X64: __extendhfsf2
%res = fptosi half %a to i257
ret i257 %res
}
define half @uitofp_half(i257 %a) nounwind {
; X86-LABEL: uitofp_half:
; X86: __gnu_f2h_ieee
;
; X64-LABEL: uitofp_half:
; X64: __truncsfhf2
%res = uitofp i257 %a to half
ret half %res
}
; x86_fp80 tests
define i257 @fptoui_x86_fp80(x86_fp80 %a) nounwind {
; CHECK-LABEL: fptoui_x86_fp80:
; CHECK: __extendxftf2
%res = fptoui x86_fp80 %a to i257
ret i257 %res
}
define x86_fp80 @sitofp_x86_fp80(i257 %a) nounwind {
; CHECK-LABEL: sitofp_x86_fp80:
; CHECK: __trunctfxf2
%res = sitofp i257 %a to x86_fp80
ret x86_fp80 %res
}