This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Another m68k bug in gcc


There appears to be a register allocation pressure related bug in at least
gcc version 2.95 19990728 (release) on Linux/m68k kernel 2.2.10.
I compiled glibc-2.1.2pre1 with it, that worked fine but it failed running
'make check'. Some investigation showed the following code in one of the
test programs:

...
	lea random,%a5
	lea (-14000,%a6),%a4
	lea (-12000,%a6),%a3
	move.l %a6,%d6
	add.l #-10000,%d6
	move.l %a4,%d5
	.align 	2
.L7:
	jbsr (%a5)                    <-- function call, clobbers d0,d1,a0,a1
	move.l %d2,%d1
	lsl.l #2,%d1
	moveq.l #19,%d3
	divsl.l %d3,%d3:%d0
	move.l %d3,(%a0,%d1.l)        <-- a0 is used (still clobbered!)
	move.l %d5,%a0                <-- a0 is reloaded
	move.l %d2,%d0
	moveq.l #20,%d3
	muls.l %d3,%d0
	add.l %d6,%d0
...

Later on in the function a0 is used again.
As you see, a0 is reloaded AFTER it's used. The code would work if those 2
lines were swapped around. It DOES seem aware that the register is clobbered.
This might be easy to fix, but I have no idea where to look for it.

The program in question:
------------------------------------------------------------------------------
int
compare (const void *a, const void *b)
{
  return strcmp (*(char **) a, *(char **) b);
}

int
main (void)
{
  char bufs[500][20];
  char *lines[500];
  int lens[500];
  int i, j;

  srandom (1);

  for (i = 0; i < 500; ++i)
    {
      lens[i] = random() % 19;
      lines[i] = bufs[i];
      for (j = 0; j < lens[i]; ++j)
	lines[i][j] = random() % 26 + 'a';
      lines[i][j] = '\0';
    }

  qsort (lines, 500, sizeof (char *), compare);

  for (i = 0; i < 500 && lines[i] != 0; ++i)
    puts (lines[i]);

  return 0;
}
------------------------------------------------------------------------------

Compiled with: gcc -g -O2 -m68060 -fno-strict-aliasing -o testsort
The bug doesn't trigger if I add -fno-function-cse to the flags (because it
uses a5 instead of a0 then).

Kars.
-- 
------------------------------------------------------------------------------
Kars de Jong             Signaalkamp rules the waves!       Turrican@Discworld
--------======]**-----|      jongk@cs.utwente.nl      |-----**[======---------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]