While my last change involving signed types was correct it wasn't optimal. We can avoid the modulo constraints if the conversion is widening (thus all values fit in the new type).
Bootstrapped and tested on x86_64-unknown-linux-gnu, ok? Thanks, Richard. 2017-10-04 Richard Biener <rguent...@suse.de> * graphite-sese-to-poly.c (extract_affine): For casts increasing precision do not perform modulo reduction. Index: gcc/graphite-sese-to-poly.c =================================================================== --- gcc/graphite-sese-to-poly.c (revision 253336) +++ gcc/graphite-sese-to-poly.c (working copy) @@ -299,11 +299,18 @@ extract_affine (scop_p s, tree e, __isl_ return res; CASE_CONVERT: - res = extract_affine (s, TREE_OPERAND (e, 0), space); - /* signed values, even if overflow is undefined, get modulo-reduced. */ - if (! TYPE_UNSIGNED (type)) - res = wrap (res, TYPE_PRECISION (type) - 1); - break; + { + tree itype = TREE_TYPE (TREE_OPERAND (e, 0)); + res = extract_affine (s, TREE_OPERAND (e, 0), space); + /* Signed values, even if overflow is undefined, get modulo-reduced. + But only if not all values of the old type fit in the new. */ + if (! TYPE_UNSIGNED (type) + && ((TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (e, 0))) + && TYPE_PRECISION (type) <= TYPE_PRECISION (itype)) + || TYPE_PRECISION (type) < TYPE_PRECISION (itype))) + res = wrap (res, TYPE_PRECISION (type) - 1); + break; + } case NON_LVALUE_EXPR: res = extract_affine (s, TREE_OPERAND (e, 0), space);