This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR optimization/9325: Saturating FP-to-int overflow.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]