This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR optimization/9325: Saturating FP-to-int overflow.
- From: "Zack Weinberg" <zack at codesourcery dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Tom Tromey <tromey at redhat dot com>
- Date: Tue, 30 Sep 2003 12:29:41 -0700
- Subject: Re: [PATCH] PR optimization/9325: Saturating FP-to-int overflow.
- References: <Pine.LNX.4.44.0309291953580.22888-100000@www.eyesopen.com>
Roger Sayle <roger@eyesopen.com> writes:
> The following patch resolves PR optimization/9325 and PR java/6391.
> Tom Tromey suggested that I investigate the latter as an example of
> the middle-end not respecting java semantics, which turned out to be
> identical to PR9325 which is reported against the C-like front-ends.
...
> The solution for the middle-end is to perform constant folding using
> the Java semantics, i.e. saturating overflow, as allowed by the C and
> C++ language standards. Indeed PR9325 isn't actually a "bug" at all,
> it invokes unspecified C/C++ behaviour that produces surprising results.
> Implementing saturating overflow semantics, at compile-time atleast,
> produces less surprising results.
...
> PR optimization/9325, PR java/6391
> * fold-const.c (fold_convert): For floating point to integer
> conversions, return the maximum/minimum representable integer
> value if the real constant overflows the destination type.
> * tree.c (real_value_from_int_cst): Allow the type to be NULL,
> meaning don't truncate the result to a floating point mode.
> Simplify the logic by calling real_from_integer directly.
> * simplify-rtx.c (simplify_unary_operation): Implement the
> same semantics for folding floating point to integer conversions
> in RTL.
I would say that this is OK provided that you document in the source
code that the middle-end implements the Java semantics for these
operations, which is also acceptable for C and C++. If you want to be
thorough, check what the Ada standard says about these operations. In
any case please wait 24 hours for the numerical folks to weigh in.
zw