Bug 38590 - [4.4 Regression] ice: verify_gimple failed
Summary: [4.4 Regression] ice: verify_gimple failed
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-checking, ice-on-valid-code, patch
Depends on:
Reported: 2008-12-21 02:09 UTC by John Regehr
Modified: 2008-12-23 16:21 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2008-12-21 10:14:51


Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2008-12-21 02:09:30 UTC
regehr@john-home:~/volatile/tmp83$ current-gcc -c -O2 -Wall small.c
small.c: In function ‘func_75’:
small.c:3: warning: statement with no effect
small.c:1: error: type mismatch in binary expression


unsigned int

D.1235 = -1 / p_76.1;

small.c:1: internal compiler error: verify_gimple failed
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

regehr@john-home:~/volatile/tmp83$ cat small.c

void func_75 (int p_76) 
  (1 / (int) -(unsigned int)p_76) < -1 ? 1 : p_76;

regehr@john-home:~/volatile/tmp83$ current-gcc -v

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --program-prefix=current- --enable-languages=c,c++ --prefix=/home/regehr : (reconfigured) ../configure --program-prefix=current- --enable-languages=c,c++ --prefix=/home/regehr : (reconfigured) ../configure --program-prefix=current- --enable-languages=c,c++ --prefix=/home/regehr : (reconfigured) ../configure --program-prefix=current- --prefix=/home/regehr --enable-languages=c,c++ --no-create --no-recursion : (reconfigured) ../configure --program-prefix=current- --prefix=/home/regehr --enable-languages=c,c++ --no-create --no-recursion : (reconfigured) ../configure --program-prefix=current- --prefix=/home/regehr --enable-languages=c,c++ --no-create --no-recursion
Thread model: posix
gcc version 4.4.0 20081220 (experimental) (GCC)
Comment 1 Andrew Pinski 2008-12-21 10:14:51 UTC
This is caused by the optimization which converts C/-a into -C/a for strict overflow which is why it only happens at -O2 and above (or with -fstrict-overflow).

Comment 2 H.J. Lu 2008-12-21 18:00:06 UTC
It is caused by revision 133479:

Comment 3 Andrew Pinski 2008-12-21 19:13:33 UTC
(In reply to comment #2)
> It is caused by revision 133479:
> http://gcc.gnu.org/ml/gcc-patches/2008-03/msg01393.html

Not really caused, just exposed, in fact it was caused by:
r107575 | pinskia | 2005-11-27 16:31:36 -0500 (Sun, 27 Nov 2005) | 13 lines

2005-11-27  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24575
        * fold-const.c (negate_expr_p): Add case for signed divides if overflow
        is undefined.
        (negate_expr): Likewise.
2005-11-27  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24575
        * gcc.dg/tree-ssa/divide-3.c: New test.
        * gcc.dg/tree-ssa/divide-4.c: New test.


Yes it is my bug.  See sometimes pointing out the patch which exposes the ICE is not always correct as you need to look into what the patch is doing.  The patch which HJL pointed out is just the patch which enables the checking and not the patch which enabled the optimization in the first place.
Comment 4 Andrew Pinski 2008-12-21 22:04:03 UTC
Anyways I have a simple fix, just use fold_convert in some places in fold-const.c for the folding of -A / -B into A/B.

Note it was really caused by:
r107543 | pinskia | 2005-11-26 17:18:04 -0500 (Sat, 26 Nov 2005) | 13 lines

2005-11-26  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/23669
        * fold-const.c (fold_binary): Convert -A/-B to A/B for signed types
        when overflow is undefined.
2005-11-26  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/23669
        * gcc.dg/tree-ssa/divide-1.c: New test.
        * gcc.dg/tree-ssa/divide-2.c: New test.

Comment 5 Andrew Pinski 2008-12-21 22:16:11 UTC
The obvious patch which I am testing right now:
Index: fold-const.c
--- fold-const.c        (revision 142867)
+++ fold-const.c        (working copy)
@@ -11678,7 +11678,7 @@ fold_binary (enum tree_code code, tree t
          return fold_build2 (code, type,
                              fold_convert (type, TREE_OPERAND (arg0, 0)),
-                             negate_expr (arg1));
+                             fold_convert (type, negate_expr (arg1)));
       if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
          && TREE_CODE (arg1) == NEGATE_EXPR
@@ -11689,8 +11689,9 @@ fold_binary (enum tree_code code, tree t
                                    "when distributing negation across "
-         return fold_build2 (code, type, negate_expr (arg0),
-                             TREE_OPERAND (arg1, 0));
+         return fold_build2 (code, type,
+                             fold_convert (type, negate_expr (arg0)),
+                             fold_convert (type, TREE_OPERAND (arg1, 0)));
       /* If arg0 is a multiple of arg1, then rewrite to the fastest div
Comment 6 Andrew Pinski 2008-12-21 22:28:26 UTC
Comment 7 Andrew Pinski 2008-12-23 16:21:41 UTC
Fixed, thanks for the bug report.
Comment 8 Andrew Pinski 2008-12-23 16:22:56 UTC
Subject: Bug 38590

Author: pinskia
Date: Tue Dec 23 16:21:32 2008
New Revision: 142906

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142906
2008-12-23  Andrew Pinski  <pinski@gmail.com>

        PR middle-end/38590
        * fold-const.c (fold_binary): Call fold_convert on arguments to
        fold_build2 for negative divide optimization.

2008-12-23  Andrew Pinski  <pinskia@gmail.com>

        PR middle-end/38590
        * gcc.c-torture/compile/pr38590-1.c: New testcase.
        * gcc.c-torture/compile/pr38590-2.c: New testcase.