From ef3b59ace9400afc4beba51f7ca91a1dfcc3ca38 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 16 Jul 2015 11:27:34 +0000 Subject: [PATCH] re PR tree-optimization/66894 (wrong code at -Os and above on x86_64-linux-gnu) 2015-07-16 Richard Biener PR tree-optimization/66894 * tree-vrp.c (register_edge_assert_for_2): Fix bad assumption about deriving NE_EXPR from truncated values. * gcc.dg/torture/pr66894.c: New testcase. From-SVN: r225870 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr66894.c | 21 +++++++++++++++++++++ gcc/tree-vrp.c | 6 ++---- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr66894.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e945a28d26f..1d5434c3bb9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-07-16 Richard Biener + + PR tree-optimization/66894 + * tree-vrp.c (register_edge_assert_for_2): Fix bad assumption + about deriving NE_EXPR from truncated values. + 2015-07-16 Martin Liska * alloc-pool.h diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8bc93412998..9bace80590d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-07-16 Richard Biener + + PR tree-optimization/66894 + * gcc.dg/torture/pr66894.c: New testcase. + 2015-07-16 Richard Biener * gcc.dg/tree-ssa/pr21031.c: Adjust. diff --git a/gcc/testsuite/gcc.dg/torture/pr66894.c b/gcc/testsuite/gcc.dg/torture/pr66894.c new file mode 100644 index 00000000000..b54494002b6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr66894.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ + +short a, b; + +int +main () +{ + for (; a != 1; a += 3) + { + int c = 0; + for (; c < 2; c++) + if (a) + { + char d = a; + b = d ? 1 / d : 0; + } + else + break; + } + return 0; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 795b02728ae..d96268314c4 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -5382,13 +5382,11 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi, } else if (CONVERT_EXPR_CODE_P (code)) { - /* For truncating conversions require that the constant - fits in the truncated type if we are going to record + /* For truncating conversions we cannot 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))) + < TYPE_PRECISION (TREE_TYPE (name)))) continue; cst = fold_convert (TREE_TYPE (name2), val); } -- 2.30.2