From: Jakub Jelinek Date: Wed, 7 May 2014 16:08:28 +0000 (+0200) Subject: backport: re PR tree-optimization/59014 (wrong code at -Os and above on x86_64-linux... X-Git-Tag: releases/gcc-4.7.4~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4639ccb038a3a8e650834c626408f0f409f6c8a;p=thirdparty%2Fgcc.git backport: re PR tree-optimization/59014 (wrong code at -Os and above on x86_64-linux-gnu) Backported from mainline 2013-11-27 Jakub Jelinek PR tree-optimization/59014 * gcc.c-torture/execute/pr59014-2.c: New test. 2013-11-26 Jakub Jelinek PR tree-optimization/59014 * tree-vrp.c (register_edge_assert_for_1): Don't look through conversions from non-integral types or through narrowing conversions. * gcc.c-torture/execute/pr59014.c: New test. From-SVN: r210177 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 710550042a11..c32f18179fe9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,13 @@ 2014-05-07 Jakub Jelinek Backported from mainline + 2013-11-26 Jakub Jelinek + + PR tree-optimization/59014 + * tree-vrp.c (register_edge_assert_for_1): Don't look + through conversions from non-integral types or through + narrowing conversions. + 2013-11-14 Jakub Jelinek Uros Bizjak diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bc5ef8fe3f3d..4307f7197b1e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,16 @@ 2014-05-07 Jakub Jelinek Backported from mainline + 2013-11-27 Jakub Jelinek + + PR tree-optimization/59014 + * gcc.c-torture/execute/pr59014-2.c: New test. + + 2013-11-26 Jakub Jelinek + + PR tree-optimization/59014 + * gcc.c-torture/execute/pr59014.c: New test. + 2013-11-14 Jakub Jelinek PR target/59101 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c b/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c new file mode 100644 index 000000000000..18da0059eab1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/59014 */ + +__attribute__((noinline, noclone)) long long int +foo (long long int x, long long int y) +{ + if (((int) x | (int) y) != 0) + return 6; + return x + y; +} + +int +main () +{ + if (sizeof (long long) == sizeof (int)) + return 0; + int shift_half = sizeof (int) * __CHAR_BIT__ / 2; + long long int x = (3LL << shift_half) << shift_half; + long long int y = (5LL << shift_half) << shift_half; + long long int z = foo (x, y); + if (z != ((8LL << shift_half) << shift_half)) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr59014.c b/gcc/testsuite/gcc.c-torture/execute/pr59014.c new file mode 100644 index 000000000000..10bf81a462f2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr59014.c @@ -0,0 +1,25 @@ +/* PR tree-optimization/59014 */ + +int a = 2, b, c, d; + +int +foo () +{ + for (;; c++) + if ((b > 0) | (a & 1)) + ; + else + { + d = a; + return 0; + } +} + +int +main () +{ + foo (); + if (d != 2) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index a65266c27fad..1bb1775f6979 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4536,9 +4536,13 @@ register_edge_assert_for_1 (tree op, enum tree_code code, } else if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (op_def))) { - /* Recurse through the type conversion. */ - retval |= register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), - code, e, bsi); + /* Recurse through the type conversion, unless it is a narrowing + conversion or conversion from non-integral type. */ + tree rhs = gimple_assign_rhs1 (op_def); + if (INTEGRAL_TYPE_P (TREE_TYPE (rhs)) + && (TYPE_PRECISION (TREE_TYPE (rhs)) + <= TYPE_PRECISION (TREE_TYPE (op)))) + retval |= register_edge_assert_for_1 (rhs, code, e, bsi); } return retval;