[backport gcc-4.8/trunk r195007, depends on vrp-uint128_t-range-checking patch ] Date: Mon, 7 Jan 2013 22:02:23 +0100 From: Jakub Jelinek Subject: [PATCH] Minor VRP simplify_float_conversion_using_ranges tweaks (PR tree-optimization/54120) List-Archive: Hi! As mentioned in the PR, the actual important bug has been fixed in range_fits_type_p by Richard Sandiford recently, so here are just two minor nits. An extension of a signed src_type to unsigned wider type is fine only if the vr doesn't have negative min or max, so always assuming we can extend is wrong (but not a very big deal, as we always pass unsigned_p = false when calling the function right now). The other change mattered in 4.7 where CODE_FOR_nothing is a big number, in 4.8 it is just a consistency issue when all the other can_float_p calls are compared with CODE_FOR_nothing (== 0). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? What about 4.7 (together with backport of Richard's http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194800 fix) after a while? gcc/ 2013-01-08 Jakub Jelinek PR tree-optimization/54120 * tree-vrp.c (range_fits_type_p): Don't allow src_precision < precision from signed vr to unsigned_p if vr->min or vr->max is negative. (simplify_float_conversion_using_ranges): Test can_float_p against CODE_FOR_nothing. --- gcc-4.7.2/gcc/tree-vrp.c.~1~ 2013-02-02 15:03:54.079100877 +0100 +++ gcc-4.7.2/gcc/tree-vrp.c 2013-02-02 15:11:11.617846147 +0100 @@ -7365,9 +7365,11 @@ range_fits_type_p (value_range_t *vr, un && !POINTER_TYPE_P (src_type)) return false; - /* An extension is always fine, so is an identity transform. */ + /* An extension is fine unless VR is signed and unsigned_p, + and so is an identity transform. */ src_precision = TYPE_PRECISION (TREE_TYPE (vr->min)); - if (src_precision < precision + if ((src_precision < precision + && !(unsigned_p && !TYPE_UNSIGNED (src_type))) || (src_precision == precision && TYPE_UNSIGNED (src_type) == unsigned_p)) return true; @@ -7425,7 +7427,7 @@ simplify_float_conversion_using_ranges ( mode = TYPE_MODE (TREE_TYPE (rhs1)); /* If we can do the conversion in the current input mode do nothing. */ else if (can_float_p (fltmode, TYPE_MODE (TREE_TYPE (rhs1)), - TYPE_UNSIGNED (TREE_TYPE (rhs1)))) + TYPE_UNSIGNED (TREE_TYPE (rhs1))) != CODE_FOR_nothing) return false; /* Otherwise search for a mode we can use, starting from the narrowest integer mode available. */