lrint/llrint are defined as rounding using the current rounding mode. Numbers that can't be converted raise FE_INVALID and an implementation defined value is returned. They may also write to errno. I believe this means we can use cvtss2si/cvtsd2si or fist to convert as long as -fno-math-errno is passed on the command line. Clang will leave them as libcalls if errno is enabled so they won't become ISD::LRINT/LLRINT in SelectionDAG. For 64-bit results on a 32-bit target we can't use cvtss2si/cvtsd2si but we can use fist since it can write to a 64-bit memory location. Though maybe we could consider using vcvtps2qq/vcvtpd2qq on avx512dq targets? gcc also does this optimization. I think we might be able to do this with STRICT_LRINT/LLRINT as well, but I've left that for future work. Differential Revision: https://reviews.llvm.org/D73859
51 lines
1.5 KiB
LLVM
51 lines
1.5 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s --check-prefixes=CHECK,SSE
|
|
; RUN: llc < %s -mtriple=x86_64-unknown -mattr=avx | FileCheck %s --check-prefixes=CHECK,AVX
|
|
; RUN: llc < %s -mtriple=x86_64-unknown -mattr=avx512f | FileCheck %s --check-prefixes=CHECK,AVX
|
|
|
|
define i64 @testmsxs(float %x) {
|
|
; SSE-LABEL: testmsxs:
|
|
; SSE: # %bb.0: # %entry
|
|
; SSE-NEXT: cvtss2si %xmm0, %rax
|
|
; SSE-NEXT: retq
|
|
;
|
|
; AVX-LABEL: testmsxs:
|
|
; AVX: # %bb.0: # %entry
|
|
; AVX-NEXT: vcvtss2si %xmm0, %rax
|
|
; AVX-NEXT: retq
|
|
entry:
|
|
%0 = tail call i64 @llvm.lrint.i64.f32(float %x)
|
|
ret i64 %0
|
|
}
|
|
|
|
define i64 @testmsxd(double %x) {
|
|
; SSE-LABEL: testmsxd:
|
|
; SSE: # %bb.0: # %entry
|
|
; SSE-NEXT: cvtsd2si %xmm0, %rax
|
|
; SSE-NEXT: retq
|
|
;
|
|
; AVX-LABEL: testmsxd:
|
|
; AVX: # %bb.0: # %entry
|
|
; AVX-NEXT: vcvtsd2si %xmm0, %rax
|
|
; AVX-NEXT: retq
|
|
entry:
|
|
%0 = tail call i64 @llvm.lrint.i64.f64(double %x)
|
|
ret i64 %0
|
|
}
|
|
|
|
define i64 @testmsll(x86_fp80 %x) {
|
|
; CHECK-LABEL: testmsll:
|
|
; CHECK: # %bb.0: # %entry
|
|
; CHECK-NEXT: fldt {{[0-9]+}}(%rsp)
|
|
; CHECK-NEXT: fistpll -{{[0-9]+}}(%rsp)
|
|
; CHECK-NEXT: movq -{{[0-9]+}}(%rsp), %rax
|
|
; CHECK-NEXT: retq
|
|
entry:
|
|
%0 = tail call i64 @llvm.lrint.i64.f80(x86_fp80 %x)
|
|
ret i64 %0
|
|
}
|
|
|
|
declare i64 @llvm.lrint.i64.f32(float) nounwind readnone
|
|
declare i64 @llvm.lrint.i64.f64(double) nounwind readnone
|
|
declare i64 @llvm.lrint.i64.f80(x86_fp80) nounwind readnone
|