The current gcc trunk miscompiles the following code on x86_64-linux-gnu at -Os and above in both 32-bit and 64-bit modes. This is a regression from 4.8.x. $ gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror --enable-checking=release --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk Thread model: posix gcc version 4.9.0 20131105 (experimental) [trunk revision 204388] (GCC) $ $ gcc-trunk -O1 small.c; a.out 2 $ gcc-4.8.2 -Os small.c; a.out 2 $ gcc-trunk -Os small.c; a.out 0 $ $ --------------------------------- int printf (const char *, ...); int a = 2, b, c, d; int foo () { for (;; c++) if ((b > 0) | (a & 1)) ; else { d = a; return 0; } } int main () { foo (); printf ("%d\n", d); return 0; }
Confirmed.
I'd say this is .vrp1. In .mergephi2, we have <bb 4>: a.1_11 = a.1_5; d = a.1_11; return 0; but in .vrp1: <bb 4>: a.1_13 = 0; a.1_11 = 0; d = 0; return 0; And yeah, the bug goes away with -fno-tree-vrp.
And, it's not related to -Os; the bug triggers exactly when VRP is run.
It seems we create wrong ASSERT_EXPR: a.1_5 = a; _7 = (_Bool) a.1_5; _8 = _4 | _7; if (_8 != 0) goto <bb 5>; else goto <bb 6>; <bb 6>: a.1_15 = ASSERT_EXPR <a.1_5, a.1_5 == 0>; Why does it think that a.1_5 must be 0?
(In reply to Marek Polacek from comment #4) > Why does it think that a.1_5 must be 0? That's because VRP is innocent here after all, it's the forwprop1 what does - _6 = a.1_5 & 1; - _7 = (_Bool) _6; + _7 = (_Bool) a.1_5; More (hopefully) tomorrow...
if (TREE_CODE (rhs_def_operand1) == SSA_NAME && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs_def_operand1) && TREE_CODE (rhs_def_operand2) == INTEGER_CST && operand_equal_p (rhs_def_operand2, build_low_bits_mask (TREE_TYPE (rhs_def_operand2), TYPE_PRECISION (lhs_type)), 0)) in simplify_conversion_from_bitmask in tree-ssa-forwprop.c will need some tweaking
Author: jakub Date: Tue Nov 26 21:29:30 2013 New Revision: 205417 URL: http://gcc.gnu.org/viewcvs?rev=205417&root=gcc&view=rev Log: 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. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr59014.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-vrp.c
Fixed.
Reopening, as the bug exists also on 4.7/4.8.
Created attachment 31310 [details] gcc49-pr59014-test.patch Testcase that reproduces also on 4.8 and 4.7. I'll bootstrap/regtest both patches now on 4.8.
Author: jakub Date: Wed Nov 27 17:03:27 2013 New Revision: 205454 URL: http://gcc.gnu.org/viewcvs?rev=205454&root=gcc&view=rev Log: PR tree-optimization/59014 * gcc.c-torture/execute/pr59014-2.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c Modified: trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Wed Nov 27 17:05:21 2013 New Revision: 205456 URL: http://gcc.gnu.org/viewcvs?rev=205456&root=gcc&view=rev Log: Backported from mainline 2013-11-26 Jakub Jelinek <jakub@redhat.com> 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. Added: branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr59014.c Modified: branches/gcc-4_8-branch/gcc/ChangeLog branches/gcc-4_8-branch/gcc/testsuite/ChangeLog branches/gcc-4_8-branch/gcc/tree-vrp.c
Author: jakub Date: Wed Nov 27 17:06:44 2013 New Revision: 205457 URL: http://gcc.gnu.org/viewcvs?rev=205457&root=gcc&view=rev Log: PR tree-optimization/59014 * gcc.c-torture/execute/pr59014-2.c: New test. Added: branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c Modified: branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Author: jakub Date: Wed May 7 16:08:28 2014 New Revision: 210177 URL: http://gcc.gnu.org/viewcvs?rev=210177&root=gcc&view=rev Log: Backported from mainline 2013-11-27 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/59014 * gcc.c-torture/execute/pr59014-2.c: New test. 2013-11-26 Jakub Jelinek <jakub@redhat.com> 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. Added: branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr59014-2.c branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr59014.c Modified: branches/gcc-4_7-branch/gcc/ChangeLog branches/gcc-4_7-branch/gcc/testsuite/ChangeLog branches/gcc-4_7-branch/gcc/tree-vrp.c