[PATCH] D73859: [X86] Add custom lowering for lrint/llrint to either cvtss2si/cvtsd2si or fist.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 2 16:47:42 PST 2020


craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel.
Herald added subscribers: jfb, hiraditya.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73859

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/lib/Target/X86/X86InstrAVX512.td
  llvm/lib/Target/X86/X86InstrFPStack.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/test/CodeGen/X86/llrint-conv.ll
  llvm/test/CodeGen/X86/lrint-conv-i32.ll
  llvm/test/CodeGen/X86/lrint-conv-i64.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73859.241952.patch
Type: text/x-patch
Size: 29950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200203/7a84eeff/attachment-0001.bin>


More information about the llvm-commits mailing list