From 195b4c507f3c0552ac78530513e4da5d227215c6 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 27 Jun 2012 11:32:30 +0000 Subject: re PR middle-end/53676 (empty loop is not always removed now) 2012-06-27 Richard Guenther PR middle-end/53676 * tree-chrec.c (chrec_convert_1): Represent truncation to a type with undefined overflow as truncation to an unsigned type converted to the type with undefined overflow. * tree-scalar-evolution.c (interpret_rhs_expr): For computing the scalar evolution of a truncated widened operation avoid looking at the non-existing evolution of the widened operation result. * gcc.dg/tree-ssa/scev-6.c: New testcase. From-SVN: r189013 --- gcc/tree-chrec.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'gcc/tree-chrec.c') diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c index 38dca4ab1dd..82c3771b8a5 100644 --- a/gcc/tree-chrec.c +++ b/gcc/tree-chrec.c @@ -1365,6 +1365,23 @@ keep_cast: res = fold_build2 (TREE_CODE (chrec), type, fold_convert (type, TREE_OPERAND (chrec, 0)), fold_convert (type, TREE_OPERAND (chrec, 1))); + /* Similar perform the trick that (signed char)((int)x + 2) can be + narrowed to (signed char)((unsigned char)x + 2). */ + else if (use_overflow_semantics + && TREE_CODE (chrec) == POLYNOMIAL_CHREC + && TREE_CODE (ct) == INTEGER_TYPE + && TREE_CODE (type) == INTEGER_TYPE + && TYPE_OVERFLOW_UNDEFINED (type) + && TYPE_PRECISION (type) < TYPE_PRECISION (ct)) + { + tree utype = unsigned_type_for (type); + res = build_polynomial_chrec (CHREC_VARIABLE (chrec), + fold_convert (utype, + CHREC_LEFT (chrec)), + fold_convert (utype, + CHREC_RIGHT (chrec))); + res = chrec_convert_1 (type, res, at_stmt, use_overflow_semantics); + } else res = fold_convert (type, chrec); -- cgit v1.2.1