I just tried to compile the package cross-avr-gcc44 with the GNU C compiler version 4.5 snapshot 20100107 and the compiler said ../../gcc/real.c:2486:1: error: invalid rtl sharing found in the insn (debug_insn 287 285 289 22 ../../gcc/real.c:291 (var_location:QI D#65 (ltu:QI (plus:DI (mult:DI (reg:DI 520 [ ai ]) (const_int 2 [0x2])) (reg:DI 277 [ D.25377 ])) (mult:DI (reg:DI 520 [ ai ]) (const_int 2 [0x2])))) -1 (nil)) ../../gcc/real.c:2486:1: error: shared rtx (mult:DI (reg:DI 520 [ ai ]) (const_int 2 [0x2])) ../../gcc/real.c:2486:1: internal compiler error: internal consistency failure Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. Preprocessed source code attached. Flags -g -O3 required.
Created attachment 19510 [details] C source code
Smaller testcase that ICEs at -g -O2: struct S { unsigned long s[17]; }; static inline void foo (struct S *r, struct S *a, unsigned n) { unsigned b = n / 8; r->s[0] = (b >= 1 ? : a->s[1 - b]); } static inline void bar (struct S *r, struct S *a) { r->s[0] = a->s[0] << 1; } static inline void baz (struct S *r, struct S *a, struct S *b) { unsigned c = 0; int i; for (i = 0; i < 3; ++i) { unsigned long d = a->s[i]; long e = d + b->s[i]; if (c) ++e == 0; c = e < d; r->s[i] = e; } } void test (struct S *r, int s, int d) { struct S u; if (s) { bar (&u, r); foo (r, r, 3); baz (r, r, &u); } u.s[0] = d; baz (r, r, &u); }
It is caused by revision 153037: http://gcc.gnu.org/ml/gcc-cvs/2009-10/msg00690.html
Testing a patch.
I just submitted a patch several days ago: http://gcc.gnu.org/ml/gcc-patches/2010-01/msg00130.html I think it might be able to fix this bug.
Created attachment 19537 [details] gcc45-pr42662.patch Fix. Regarding the above mentioned patch, it looks like a big hammer, which will create a lot of garbage. Are you sure you have investigated where exactly the sharing originates from? On the line this patch is fixing XEXP (op0, 0) is used twice, once inside the plus and once as the second comparison operand. So it is clearly where the bug is introduced. Another place which also introduces something similar (x*x scalar floating optimization) already uses properly copy_rtx.
Sorry, I should have checked my patch with the test code you posted before I added that comment. My patch does not fix this one.
Subject: Bug 42662 Author: jakub Date: Tue Jan 12 09:45:19 2010 New Revision: 155831 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155831 Log: PR debug/42662 * simplify-rtx.c (simplify_relational_operation_1): Avoid invalid rtx sharing when canonicalizing ({lt,ge}u (plus a b) b). * gcc.dg/pr42662.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr42662.c Modified: trunk/gcc/ChangeLog trunk/gcc/simplify-rtx.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 42662 Author: jakub Date: Tue Jan 12 09:47:07 2010 New Revision: 155832 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155832 Log: PR debug/42662 * simplify-rtx.c (simplify_relational_operation_1): Avoid invalid rtx sharing when canonicalizing ({lt,ge}u (plus a b) b). * gcc.dg/pr42662.c: New test. Added: branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr42662.c Modified: branches/gcc-4_4-branch/gcc/ChangeLog branches/gcc-4_4-branch/gcc/simplify-rtx.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Fixed.