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 int int 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)
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). Confirmed.
It is caused by revision 133479: http://gcc.gnu.org/ml/gcc-patches/2008-03/msg01393.html
(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.
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. :)
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 WARN_STRICT_OVERFLOW_MISC); 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 " "division"), WARN_STRICT_OVERFLOW_MISC); - 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
Mine.
Fixed, thanks for the bug report.
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 Log: 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. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr38590-1.c trunk/gcc/testsuite/gcc.c-torture/compile/pr38590-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog