public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact
@ 2022-11-16 19:37 kevinl at rivosinc dot com
  2022-11-16 19:50 ` [Bug middle-end/107723] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kevinl at rivosinc dot com @ 2022-11-16 19:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107723

            Bug ID: 107723
           Summary: RISC-V lround/ceil/floor with
                    -fno-fp-int-builtin-inexact
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kevinl at rivosinc dot com
  Target Milestone: ---

This was observed when solving
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605481.html. For
example, 

int ceil(double i)
{
  return __builtin_lceil(i);
}

-march=rv64gc -mabi=lp64d -fno-fp-int-builtin-inexact generates

ceil1:
        addi    sp,sp,-16
        sd      ra,8(sp)
        call    ceil
        ld      ra,8(sp)
        fcvt.l.d a0,fa0,rtz
        addi    sp,sp,16
        sext.w  a0,a0
        jr      ra

fcvt can possibly set the inexact exception flag, so this seems to be a
violation.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/107723] lround/ceil/floor with -fno-fp-int-builtin-inexact
  2022-11-16 19:37 [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact kevinl at rivosinc dot com
@ 2022-11-16 19:50 ` pinskia at gcc dot gnu.org
  2022-11-16 19:59 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 19:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107723

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|RISC-V lround/ceil/floor    |lround/ceil/floor with
                   |with                        |-fno-fp-int-builtin-inexact
                   |-fno-fp-int-builtin-inexact |
          Component|target                      |middle-end

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is not a target issue though.
As x86_64 produces:
ceilh:
        sub     rsp, 8
        call    ceil
        add     rsp, 8
        cvttsd2si       rax, xmm0
        ret

cvttsd2si will raise inexact also.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/107723] lround/ceil/floor with -fno-fp-int-builtin-inexact
  2022-11-16 19:37 [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact kevinl at rivosinc dot com
  2022-11-16 19:50 ` [Bug middle-end/107723] " pinskia at gcc dot gnu.org
@ 2022-11-16 19:59 ` pinskia at gcc dot gnu.org
  2022-11-16 20:45 ` kevinl at rivosinc dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 19:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107723

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, only lround is documented and the other two are not, I filed PR 107724 for
the missing documentation.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/107723] lround/ceil/floor with -fno-fp-int-builtin-inexact
  2022-11-16 19:37 [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact kevinl at rivosinc dot com
  2022-11-16 19:50 ` [Bug middle-end/107723] " pinskia at gcc dot gnu.org
  2022-11-16 19:59 ` pinskia at gcc dot gnu.org
@ 2022-11-16 20:45 ` kevinl at rivosinc dot com
  2023-11-17  4:06 ` xry111 at gcc dot gnu.org
  2023-12-12 11:22 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: kevinl at rivosinc dot com @ 2022-11-16 20:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107723

--- Comment #3 from Kevin Lee <kevinl at rivosinc dot com> ---
aarch64 also produces

ceil1:
        fcvtps  x0, d0
        ret

Since it has been changed to middle-end, I'll delete riscv as the target

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/107723] lround/ceil/floor with -fno-fp-int-builtin-inexact
  2022-11-16 19:37 [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact kevinl at rivosinc dot com
                   ` (2 preceding siblings ...)
  2022-11-16 20:45 ` kevinl at rivosinc dot com
@ 2023-11-17  4:06 ` xry111 at gcc dot gnu.org
  2023-12-12 11:22 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-17  4:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107723

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-11-17
                 CC|                            |xry111 at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
long x(double y)
{
        return __builtin_trunc(y);
}

In 005t.original (!) it's already "optimized" to

{
  return (long int) y;
}

Despite -fno-fp-int-builtin-inexact is set.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/107723] lround/ceil/floor with -fno-fp-int-builtin-inexact
  2022-11-16 19:37 [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact kevinl at rivosinc dot com
                   ` (3 preceding siblings ...)
  2023-11-17  4:06 ` xry111 at gcc dot gnu.org
@ 2023-12-12 11:22 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-12 11:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107723

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Xi Ruoyao <xry111@gcc.gnu.org>:

https://gcc.gnu.org/g:99182ea09f10beca8445396cbab491899536f5c3

commit r14-6455-g99182ea09f10beca8445396cbab491899536f5c3
Author: Xi Ruoyao <xry111@xry111.site>
Date:   Fri Nov 24 11:08:19 2023 +0800

    Only allow (int)trunc(x) to (int)x simplification with
-ffp-int-builtin-inexact [PR107723]

    With -fno-fp-int-builtin-inexact, trunc is not allowed to raise
    FE_INEXACT and it should produce an integral result (if the input is not
    NaN or Inf).  Thus FE_INEXACT should not be raised.

    But (int)x may raise FE_INEXACT when x is a non-integer, non-NaN, and
    non-Inf value.  C23 recommends to do so in a footnote.

    Thus we should not simplify (int)trunc(x) to (int)x if
    -fno-fp-int-builtin-inexact is in-effect.

    gcc/ChangeLog:

            PR middle-end/107723
            * convert.cc (convert_to_integer_1) [case BUILT_IN_TRUNC]: Break
            early if !flag_fp_int_builtin_inexact and flag_trapping_math.

    gcc/testsuite/ChangeLog:

            PR middle-end/107723
            * gcc.dg/torture/builtin-fp-int-inexact-trunc.c: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-12 11:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 19:37 [Bug target/107723] New: RISC-V lround/ceil/floor with -fno-fp-int-builtin-inexact kevinl at rivosinc dot com
2022-11-16 19:50 ` [Bug middle-end/107723] " pinskia at gcc dot gnu.org
2022-11-16 19:59 ` pinskia at gcc dot gnu.org
2022-11-16 20:45 ` kevinl at rivosinc dot com
2023-11-17  4:06 ` xry111 at gcc dot gnu.org
2023-12-12 11:22 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).