Bug 35429 - [4.2 regression] ICE with complex arithmetic
Summary: [4.2 regression] ICE with complex arithmetic
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P2 normal
Target Milestone: 4.3.1
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2008-03-03 19:57 UTC by Volker Reichelt
Modified: 2009-03-31 15:19 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.3.1 4.4.0
Known to fail: 4.2.5
Last reconfirmed: 2008-03-25 04:23:41


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2008-03-03 19:57:49 UTC
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.]
Comment 1 Andrew Pinski 2008-03-25 04:23:40 UTC
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.
Comment 2 Andrew Pinski 2008-03-25 04:34:57 UTC
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;
+}
Comment 3 Andrew Pinski 2008-03-27 08:56:35 UTC
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

Comment 4 Andrew Pinski 2008-03-27 08:56:37 UTC
Fixed on the trunk, I will fix this on the other branches over the weekend.
Comment 5 Andrew Pinski 2008-04-02 07:19:15 UTC
Fixed also on the 4.3 branch.
Comment 6 Andrew Pinski 2008-04-02 07:19:50 UTC
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

Comment 7 Joseph S. Myers 2008-07-04 22:35:16 UTC
Closing 4.1 branch.
Comment 8 Andrew Pinski 2008-07-15 14:19:17 UTC
No longer working on this one.
Comment 9 Joseph S. Myers 2009-03-31 15:19:31 UTC
Closing 4.2 branch, fixed in 4.3.1 and 4.4.