public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm
@ 2013-11-13  2:20 ian at airs dot com
  2013-11-13 14:48 ` [Bug rtl-optimization/59099] " hjl.tools at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ian at airs dot com @ 2013-11-13  2:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

            Bug ID: 59099
           Summary: Erroneous register allocation on 32-bit x86 using
                    regparm
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian at airs dot com
                CC: vmakarov at redhat dot com

The appended test case should run without error and return 0.  When I compile
it with  -O2 -fPIC -m32 for 32-bit x86, it crashes at runtime with a
segmentation violation.

The generated code is incorrect.  The loop is entered like this:

    movl    12(%esp), %eax
    leal    4(%esi), %ecx
    movl    %edi, 64(%esp)
    xorl    %esi, %esi
    subl    $1, %eax
    movl    %eax, 20(%esp)
    jmp    .L7


Note that %eax holds a value stored in 20(%esp), which as we will see is used
to terminate the loop.  At .L7 we see this:

.L7:
    movl    4(%esp), %edi
    testl    %edi, %edi
    jne    .L5
    cmpl    %edx, 20(%esp)
    jne    .L5

Note that nothing changes %eax.  Note the comparison with 20(%esp).

At .L5 we see this:

.L5:
    movl    64(%esp), %edi
    movl    (%eax), %eax

Note that we are loading a value from %eax.  But at this point it still holds
the value it was given before the loop, which is a counter, not a pointer.

I have not tried to track down the problem, but superficially it appears that
the register allocator has decided to rematerialize the pointer p from the
register parameter, without realizing that the register has changed since the
start of the function.

This is reduced from code in the libgo library.  The libgo code does not use
regparm, but the function in question is a static function and the optimizers
assign it regparm ((1)).

void (*pfn)(void);

struct s
{
  void** q;
  int h;
  int t;
  int s;
};


void* f (struct s *, struct s *) __attribute__ ((noinline, regparm(1)));

void*
__attribute__ ((regparm(1)))
f (struct s *p, struct s *p2)
{
  void *gp, *gp1;
  int t, h, s, t2, h2, c, i;

  if (p2->h == p2->t)
    return 0;

  (*pfn) ();

  h = p->h;
  t = p->t;
  s = p->s;

  h2 = p2->h;
  t2 = p2->t;

  gp = p2->q[h2++];

  c = (t2 - h2) / 2;
  for (i = 0; i != c; i++)
    {
      if (t == h || (h == 0 && t == s - 1))
    break;
      gp1 = p2->q[h2++];
      p->q[t++] = gp1;
      if (t == s)
    t = 0;
    }

  p2->h = h2;
  return gp;
}

static void fn () { }

int
main()
{
  struct s s1, s2;
  void *q[10];

  pfn = fn;

  s1.q = q;
  s1.h = 0;
  s1.t = 2;
  s1.s = 4;

  s2.q = q;
  s2.h = 0;
  s2.t = 4;
  s2.s = 2;

  f (&s1, &s2);

  return 0;
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
@ 2013-11-13 14:48 ` hjl.tools at gmail dot com
  2013-11-13 15:50 ` [Bug rtl-optimization/59099] [4.9 Regression] " jamborm at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2013-11-13 14:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jamborm at gcc dot gnu.org
   Target Milestone|---                         |4.9.0

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
It is caused by r204698.  I also saw:

FAIL: gcc.dg/ira-shrinkwrap-prep-1.c scan-rtl-dump ira "Split live-range of
register"
FAIL: gcc.dg/ira-shrinkwrap-prep-1.c scan-rtl-dump ira "Will split live ranges
of parameters"
FAIL: gcc.dg/ira-shrinkwrap-prep-1.c scan-rtl-dump pro_and_epilogue "Performing
shrink-wrapping"
FAIL: gcc.dg/ira-shrinkwrap-prep-2.c scan-rtl-dump ira "Split live-range of
register"
FAIL: gcc.dg/ira-shrinkwrap-prep-2.c scan-rtl-dump ira "Will split live ranges
of parameters"
FAIL: gcc.dg/ira-shrinkwrap-prep-2.c scan-rtl-dump pro_and_epilogue "Performing
shrink-wrapping"

on x86-64.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] [4.9 Regression] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
  2013-11-13 14:48 ` [Bug rtl-optimization/59099] " hjl.tools at gmail dot com
@ 2013-11-13 15:50 ` jamborm at gcc dot gnu.org
  2013-11-14 18:24 ` jamborm at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-11-13 15:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-11-13
           Assignee|unassigned at gcc dot gnu.org      |jamborm at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Martin Jambor <jamborm at gcc dot gnu.org> ---
The test failures should be resolved by
http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01461.html

The original problem is another matter and I will have a look into it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] [4.9 Regression] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
  2013-11-13 14:48 ` [Bug rtl-optimization/59099] " hjl.tools at gmail dot com
  2013-11-13 15:50 ` [Bug rtl-optimization/59099] [4.9 Regression] " jamborm at gcc dot gnu.org
@ 2013-11-14 18:24 ` jamborm at gcc dot gnu.org
  2013-11-15 17:04 ` jamborm at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-11-14 18:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

--- Comment #3 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Hi, I have to leave today but I've posted some information about my
progress with an untested fix to the mailing list:

http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01649.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] [4.9 Regression] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
                   ` (2 preceding siblings ...)
  2013-11-14 18:24 ` jamborm at gcc dot gnu.org
@ 2013-11-15 17:04 ` jamborm at gcc dot gnu.org
  2013-11-19 15:09 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-11-15 17:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-p
                   |                            |atches/2013-11/msg01820.htm
                   |                            |l

--- Comment #4 from Martin Jambor <jamborm at gcc dot gnu.org> ---
I've proposed a patch to fix this on the mailing list:

http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01820.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] [4.9 Regression] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
                   ` (3 preceding siblings ...)
  2013-11-15 17:04 ` jamborm at gcc dot gnu.org
@ 2013-11-19 15:09 ` rguenth at gcc dot gnu.org
  2013-11-19 23:11 ` jamborm at gcc dot gnu.org
  2013-11-20  0:06 ` ian at airs dot com
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-11-19 15:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] [4.9 Regression] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
                   ` (4 preceding siblings ...)
  2013-11-19 15:09 ` rguenth at gcc dot gnu.org
@ 2013-11-19 23:11 ` jamborm at gcc dot gnu.org
  2013-11-20  0:06 ` ian at airs dot com
  6 siblings, 0 replies; 8+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-11-19 23:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Fixed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug rtl-optimization/59099] [4.9 Regression] Erroneous register allocation on 32-bit x86 using regparm
  2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
                   ` (5 preceding siblings ...)
  2013-11-19 23:11 ` jamborm at gcc dot gnu.org
@ 2013-11-20  0:06 ` ian at airs dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ian at airs dot com @ 2013-11-20  0:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59099

--- Comment #7 from Ian Lance Taylor <ian at airs dot com> ---
Thanks, Martin.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-11-20  0:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-13  2:20 [Bug rtl-optimization/59099] New: Erroneous register allocation on 32-bit x86 using regparm ian at airs dot com
2013-11-13 14:48 ` [Bug rtl-optimization/59099] " hjl.tools at gmail dot com
2013-11-13 15:50 ` [Bug rtl-optimization/59099] [4.9 Regression] " jamborm at gcc dot gnu.org
2013-11-14 18:24 ` jamborm at gcc dot gnu.org
2013-11-15 17:04 ` jamborm at gcc dot gnu.org
2013-11-19 15:09 ` rguenth at gcc dot gnu.org
2013-11-19 23:11 ` jamborm at gcc dot gnu.org
2013-11-20  0:06 ` ian at airs dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).