The following fixes PR66863. Bootstrapped and tested on x86_64-unknown-linux-gnu.
Richard. 2015-07-14 Richard Biener <rguent...@suse.de> PR tree-optimization/66863 * tree-vrp.c (register_edge_assert_for_2): Properly restrict what we record for conversion use stmt lhs inequalities. * gcc.dg/torture/pr66863.c: New testcase. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 225761) +++ gcc/tree-vrp.c (working copy) @@ -5381,7 +5381,17 @@ register_edge_assert_for_2 (tree name, e cst = int_const_binop (code, val, cst); } else if (CONVERT_EXPR_CODE_P (code)) - cst = fold_convert (TREE_TYPE (name2), val); + { + /* For truncating conversions require that the constant + fits in the truncated type if we are going to record + an inequality. */ + if (comp_code == NE_EXPR + && (TYPE_PRECISION (TREE_TYPE (name2)) + < TYPE_PRECISION (TREE_TYPE (name))) + && ! int_fits_type_p (val, TREE_TYPE (name2))) + continue; + cst = fold_convert (TREE_TYPE (name2), val); + } else continue; Index: gcc/testsuite/gcc.dg/torture/pr66863.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr66863.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr66863.c (working copy) @@ -0,0 +1,25 @@ +/* { dg-do run } */ + +int a, b; + +int +fn1 (int p1) +{ + if (p1 < -2147483647) + return 0; + else + return 1; +} + +int +fn2 (int p1, short p2) +{ + return p2 ? p1 % p2 : 0; +} + +int +main () +{ + b = fn2 (fn1 (a), a); + return 0; +}