LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions
authorXi Ruoyao <xry111@xry111.site>
Sun, 6 Nov 2022 15:16:49 +0000 (23:16 +0800)
committerXi Ruoyao <xry111@xry111.site>
Sat, 12 Nov 2022 07:01:13 +0000 (15:01 +0800)
commit51a233b97cc9c51e63f03f2f5554e905f3f6c054
tree3f3ecbb25183cace4e422ef04da1adfcbada9fd6
parente468dd40150ad20fe87d315c2638c572ca44dc3b
LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions

This allows to optimize the following builtins if -fno-math-errno:

- __builtin_lrint{,f}
- __builtin_lfloor{,f}
- __builtin_lceil{,f}

Inspired by
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605287.html.

ANYFI is added so the compiler won't try ftint.l.s if -mfpu=32.  If we
simply used GPR here an ICE would be triggered with __builtin_lrintf
and -mfpu=32.

ftint{rm,rp} instructions may raise inexact exception, so they can't be
used if -fno-trapping-math -fno-fp-int-builtin-inexact.

Note that the .w.{s,d} variants are not tested because we don't support
ILP32 for now.

gcc/ChangeLog:

* config/loongarch/loongarch.md (UNSPEC_FTINT): New unspec.
(UNSPEC_FTINTRM): Likewise.
(UNSPEC_FTINTRP): Likewise.
(LRINT): New define_int_iterator.
(lrint_pattern): New define_int_attr.
(lrint_submenmonic): Likewise.
(lrint_allow_inexact): Likewise.
(ANYFI): New define_mode_iterator.
(lrint<ANYF><ANYFI>): New instruction template.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/ftint.c: New test.
* gcc.target/loongarch/ftint-no-inexact.c: New test.
gcc/config/loongarch/loongarch.md
gcc/testsuite/gcc.target/loongarch/ftint-no-inexact.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/ftint.c [new file with mode: 0644]