Bug 42662 - [4.5 Regression] invalid rtl sharing found in the insn
Summary: [4.5 Regression] invalid rtl sharing found in the insn
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-01-08 18:09 UTC by David Binderman
Modified: 2010-01-13 10:07 UTC (History)
4 users (show)

See Also:
Host: x86_64-suse-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-01-11 09:25:27


Attachments
C source code (67.38 KB, text/plain)
2010-01-08 18:10 UTC, David Binderman
Details
gcc45-pr42662.patch (761 bytes, patch)
2010-01-11 09:46 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2010-01-08 18:09:30 UTC
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.
Comment 1 David Binderman 2010-01-08 18:10:39 UTC
Created attachment 19510 [details]
C source code
Comment 2 Jakub Jelinek 2010-01-09 17:25:16 UTC
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);
}
Comment 3 H.J. Lu 2010-01-09 20:35:31 UTC
It is caused by revision 153037:

http://gcc.gnu.org/ml/gcc-cvs/2009-10/msg00690.html
Comment 4 Jakub Jelinek 2010-01-11 09:25:27 UTC
Testing a patch.
Comment 5 Jie Zhang 2010-01-11 09:36:08 UTC
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.
Comment 6 Jakub Jelinek 2010-01-11 09:46:57 UTC
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.
Comment 7 Jie Zhang 2010-01-11 10:11:09 UTC
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.
Comment 8 Jakub Jelinek 2010-01-12 09:45:37 UTC
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

Comment 9 Jakub Jelinek 2010-01-12 09:47:22 UTC
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

Comment 10 Jakub Jelinek 2010-01-13 10:07:40 UTC
Fixed.