[Bug tree-optimization/87415] [9 Regression] wrong code at -O1 and above on x86_64-linux-gnu
aldyh at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Sep 26 09:23:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87415
--- Comment #3 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Created attachment 44753
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44753&action=edit
untested patch
1-bit signed fields are weird in that 0 - (-MIN) is still -MIN. In any other
world, it is an impossible result. For instance, in an 8-bit signed world, 0 -
(-128) is invalid.
One option would be to treat signed bit fields as TYPE_OVERFLOW wraps, since
they seem to have wrapping properties, but I'm afraid such a heavy handed
approach would yield latent bugs across the compiler. What VRP seems to
currently be doing in set_and_canonicalize_value_range(), is just special
casing the wrapping of 1-bit fields:
/* Wrong order for min and max, to swap them and the VR type we need
to adjust them. */
if (tree_int_cst_lt (max, min))
{
tree one, tmp;
/* For one bit precision if max < min, then the swapped
range covers all values, so for VR_RANGE it is varying and
for VR_ANTI_RANGE empty range, so drop to varying as well. */
if (TYPE_PRECISION (TREE_TYPE (min)) == 1)
{
set_value_range_to_varying (vr);
return;
}
...
}
I've done the same in set_value_range_with_overflow(). The attached untested
patch fixes the problem on my end.
More information about the Gcc-bugs
mailing list