public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math
       [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
@ 2021-10-27 13:09 ` rguenth at gcc dot gnu.org
  2021-10-27 13:28 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-27 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2018-02-15 00:00:00         |2021-10-27

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
In this bug the issue is int-to-real conversion.  Note that apart from
fold_convert_const via build_real_from_int_cst also RTL forwprop
via simplify_const_unary_operation folds this in the wrong way.

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

* [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math
       [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
  2021-10-27 13:09 ` [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math rguenth at gcc dot gnu.org
@ 2021-10-27 13:28 ` rguenth at gcc dot gnu.org
  2021-10-27 17:16 ` joseph at codesourcery dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-27 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 51676
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51676&action=edit
patch

Testing for exact real-to-int / int-to-real conversions is a bit awkward but
maybe I am missing interesting details in real.c that could be exercised here.

Also a question is the behavior on overflow when converting a real to an
integer (IIRC the behavior here is undefined, but we constant fold to the
largest/smallest integer here).

For integer to float conversions is the overflow considered before or after
applying the rounding?  That is, are there integer values that invoke
undefined behavior when converted to a real dependent on the rounding mode?

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

* [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math
       [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
  2021-10-27 13:09 ` [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math rguenth at gcc dot gnu.org
  2021-10-27 13:28 ` rguenth at gcc dot gnu.org
@ 2021-10-27 17:16 ` joseph at codesourcery dot com
  2021-10-28  9:29 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: joseph at codesourcery dot com @ 2021-10-27 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Wed, 27 Oct 2021, rguenth at gcc dot gnu.org via Gcc-bugs wrote:

> Also a question is the behavior on overflow when converting a real to an
> integer (IIRC the behavior here is undefined, but we constant fold to the
> largest/smallest integer here).

We follow Annex F here (so unspecified value rather than undefined - as 
discussed in other bugs, any given execution of the conversion in the 
abstract machine needs to act as if it does return some value of the 
type).

> For integer to float conversions is the overflow considered before or after
> applying the rounding?  That is, are there integer values that invoke
> undefined behavior when converted to a real dependent on the rounding mode?

It's fully defined regardless of the value (the appropriately rounded 
result is returned, which might be an infinity in case of overflow, or the 
largest finite value depending on the rounding mode).

Whether the conversion overflows can indeed depend on the rounding mode 
(overflow occurs when a conversion in that rounding mode, with infinite 
exponent range, would produce a result with an exponent too large to 
represent in the floating-point format).  For the IEEE formats and integer 
types supported by GCC, the only cases where overflow is possible are for 
conversions to _Float16, and from unsigned __int128 to float.

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

* [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math
       [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-10-27 17:16 ` joseph at codesourcery dot com
@ 2021-10-28  9:29 ` rguenth at gcc dot gnu.org
  2021-10-28 13:45 ` cvs-commit at gcc dot gnu.org
  2021-10-28 13:46 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-28  9:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84407
Bug 84407 depends on bug 57245, which changed state.

Bug 57245 Summary: Floating-point constant truncation ignores -frounding-math
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57245

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

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

* [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math
       [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2021-10-28  9:29 ` rguenth at gcc dot gnu.org
@ 2021-10-28 13:45 ` cvs-commit at gcc dot gnu.org
  2021-10-28 13:46 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-28 13:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:81342e95827f77c0917dd7a9fd54ac9729439c8e

commit r12-4767-g81342e95827f77c0917dd7a9fd54ac9729439c8e
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Oct 28 11:38:32 2021 +0200

    middle-end/84407 - honor -frounding-math for int to float conversion

    This makes us honor -frounding-math for integer to float conversions
    and avoid constant folding when such conversion is not exact.

    2021-10-28  Richard Biener  <rguenther@suse.de>

            PR middle-end/84407
            * fold-const.c (fold_convert_const): Avoid int to float
            constant folding with -frounding-math and inexact result.
            * simplify-rtx.c (simplify_const_unary_operation): Likewise
            for both float and unsigned_float.

            * gcc.dg/torture/fp-uint64-convert-double-1.c: New testcase.
            * gcc.dg/torture/fp-uint64-convert-double-2.c: Likewise.

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

* [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math
       [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2021-10-28 13:45 ` cvs-commit at gcc dot gnu.org
@ 2021-10-28 13:46 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-28 13:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
The testcase now is fixed on x86_64.

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

end of thread, other threads:[~2021-10-28 13:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-84407-4@http.gcc.gnu.org/bugzilla/>
2021-10-27 13:09 ` [Bug tree-optimization/84407] incorrect constant propagation with -frounding-math rguenth at gcc dot gnu.org
2021-10-27 13:28 ` rguenth at gcc dot gnu.org
2021-10-27 17:16 ` joseph at codesourcery dot com
2021-10-28  9:29 ` rguenth at gcc dot gnu.org
2021-10-28 13:45 ` cvs-commit at gcc dot gnu.org
2021-10-28 13:46 ` rguenth 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).