At -O and higher with -fwrapv, svn 136854 improperly compiles func_9 below into object code returning 0. static unsigned long mod_rhs (long int rhs) { return rhs; } unsigned g_8 = 0x0815898FL; int func_9 (void) { return ((0x0274952FL * g_8) % mod_rhs (0x0274952FL)); }
/* We have a special case here if we are doing something like (C * 8) % 4 since we know that's zero. */ if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR || code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR) && TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST && integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0))) return omit_one_operand (type, integer_zero_node, op0);
That is only true for where overflow is undefined IIRC. So if wrapping happens this is not true ...
Hm, but multiplication overflow behaves "sane".
*** Bug 37125 has been marked as a duplicate of this bug. ***
Mine.
Subject: Bug 36548 Author: rguenth Date: Fri Aug 22 12:43:49 2008 New Revision: 139450 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139450 Log: 2008-08-22 Richard Guenther <rguenther@suse.de> PR middle-end/36548 PR middle-end/37125 * fold-const.c (extract_muldiv_1): Optimize (X * C1) % C2 only if the multiplication does not overflow. * gcc.c-torture/execute/pr37125.c: New testcase. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr37125.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk.
4.3.2 is released, changing milestones to 4.3.3.
Fixed.
Subject: Bug 36548 Author: rguenth Date: Thu Aug 28 14:18:23 2008 New Revision: 139709 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139709 Log: 2008-08-28 Richard Guenther <rguenther@suse.de> PR middle-end/36548 PR middle-end/37125 * fold-const.c (extract_muldiv_1): Optimize (X * C1) % C2 only if the multiplication does not overflow. * gcc.c-torture/execute/pr37125.c: New testcase. Added: branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/pr37125.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
*** Bug 38817 has been marked as a duplicate of this bug. ***