The following valid code snippet triggers an ICE since GCC 4.1.0 when compiled with "-O": ==================================================== int foo(__complex__ int z0, __complex__ int z1) { return z0 != 0 || z1 != 0; } ==================================================== bug.c: In function 'foo': bug.c:3: internal compiler error: in build_int_cst_wide, at tree.c:891 Please submit a full bug report, [etc.]
2005-12-22 Richard Guenther <rguenther@suse.de> * tree.c (tree_fold_gcd): Use build_int_cst where appropriate. * tree-ssa-loop-ivcanon.c (create_canonical_iv): Likewise. * varasm.c (array_size_for_constructor): Likewise. * fold-const.c (size_diffop, invert_truthvalue, optimize_bit_field_compare, make_range, build_range_check, fold_cond_expr_with_comparison, fold_truthop, fold_single_bit_test_into_sign_test, fold_binary): Likewise. Caused it though using BIT_IOR_EXPR on a complex type does not make sense does it? Anyways adding INTEGRAL_TYPE_P makes it work. Also I think there are some missed optimization due to a full equality check of the types rather than a weaker one, I will file them as seperate bugs. Mine, I am testing the obvious patch which adds the check for INTEGRAL_TYPE_P.
Here is the patch which I am testing: Index: fold-const.c =================================================================== --- fold-const.c (revision 133503) +++ fold-const.c (working copy) @@ -5357,7 +5357,8 @@ fold_truthop (enum tree_code code, tree if (code == TRUTH_OR_EXPR && lcode == NE_EXPR && integer_zerop (lr_arg) && rcode == NE_EXPR && integer_zerop (rr_arg) - && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg)) + && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) + && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))) return build2 (NE_EXPR, truth_type, build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), ll_arg, rl_arg), @@ -5367,7 +5368,8 @@ fold_truthop (enum tree_code code, tree if (code == TRUTH_AND_EXPR && lcode == EQ_EXPR && integer_zerop (lr_arg) && rcode == EQ_EXPR && integer_zerop (rr_arg) - && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg)) + && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) + && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))) return build2 (EQ_EXPR, truth_type, build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), ll_arg, rl_arg), Index: testsuite/gcc.c-torture/compile/complex-5.c =================================================================== --- testsuite/gcc.c-torture/compile/complex-5.c (revision 0) +++ testsuite/gcc.c-torture/compile/complex-5.c (revision 0) @@ -0,0 +1,9 @@ +int foo(__complex__ int z0, __complex__ int z1) +{ + return z0 != 0 || z1 != 0; +} + +int foo1(__complex__ int z0, __complex__ int z1) +{ + return z0 == 0 && z1 == 0; +}
Subject: Bug 35429 Author: pinskia Date: Thu Mar 27 08:55:50 2008 New Revision: 133631 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133631 Log: 2008-03-27 Andrew Pinski <pinskia@gmail.com> PR middle-end/35429 * fold-const.c (fold_truthop): Check for integeral types when folding a == 0 && b == 0 and a != 0 || b != 0 . 2008-03-27 Andrew Pinski <pinskia@gmail.com> PR middle-end/35429 * gcc.c-torture/compile/complex-5.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/compile/complex-5.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk, I will fix this on the other branches over the weekend.
Fixed also on the 4.3 branch.
Subject: Bug 35429 Author: pinskia Date: Wed Apr 2 07:19:01 2008 New Revision: 133823 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133823 Log: 2008-04-02 Andrew Pinski <pinskia@gmail.com> PR middle-end/35429 * fold-const.c (fold_truthop): Check for integeral types when folding a == 0 && b == 0 and a != 0 || b != 0 . 2008-04-02 Andrew Pinski <pinskia@gmail.com> PR middle-end/35429 * gcc.c-torture/compile/complex-5.c: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/complex-5.c - copied unchanged from r133631, trunk/gcc/testsuite/gcc.c-torture/compile/complex-5.c Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/fold-const.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Closing 4.1 branch.
No longer working on this one.
Closing 4.2 branch, fixed in 4.3.1 and 4.4.