Skip to content
Snippets Groups Projects
Commit 21da32d9 authored by Jakub Jelinek's avatar Jakub Jelinek
Browse files

range-op-float: Fix up -frounding-math frange_arithmetic +- handling [PR110755]

IEEE754 says that x + (-x) and x - x result in +0 in all rounding modes
but rounding towards negative infinity, in which case the result is -0
for all finite x.  x + x and x - (-x) if it is zero retain sign of x.
Now, range_arithmetic implements the normal rounds to even rounding,
and as the addition or subtraction in those cases is exact, we don't do any
further rounding etc. and e.g. on the testcase below distilled from glibc
compute a range [+0, +INF], which is fine for -fno-rounding-math or
if we'd have a guarantee that those statements aren't executed with rounding
towards negative infinity.

I believe it is only +- which has this problematic behavior and I think
it is best to deal with it in frange_arithmetic; if we know -frounding-math
is on, it is x + (-x) or x - x and we are asked to round to negative
infinity (i.e. want low bound rather than high bound), change +0 result to
-0.

2023-07-26  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/110755
	* range-op-float.cc (frange_arithmetic): Change +0 result to -0
	for PLUS_EXPR or MINUS_EXPR if -frounding-math, inf is negative and
	it is exact op1 + (-op1) or op1 - op1.

	* gcc.dg/pr110755.c: New test.
parent 96a83923
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment