Subject: toolchain/17550: -O2 optimization triggers internal error in gcc on m68k
To: None <gnats-bugs@gnats.netbsd.org>
From: Klaus Heinz <k.heinz.jul.zwei@onlinehome.de>
List: netbsd-bugs
Date: 07/10/2002 23:35:03
>Number:         17550
>Category:       toolchain
>Synopsis:       -O2 optimization triggers internal error in gcc on m68k
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 10 14:50:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Klaus Heinz
>Release:        NetBSD 1.6_BETA4 build 200207080000
>Organization:
none
>Environment:
System: NetBSD rainbow.homedns.org 1.6_BETA4 NetBSD 1.6_BETA4 (GENERIC) #0:
Tue Jul 9 04:02:40 UTC 2002 autobuild@tgm.daemon.org:/autobuild/amiga/OBJ/
autobuild/src/sys/arch/amiga/compile/GENERIC amiga
Architecture: m68k
Machine: amiga
Amiga 3000 (68060 rev.1 CPU/MMU/FPU)
>Description:
	Compiling gdk-pixbuf-0.17.0 (graphics/gdk-pixbuf) the compiler
	encountered an internal error processing the file
	gdk-pixbuf/pixops/pixops.c:


	pixops.c: In function `bilinear_quadrant':
	pixops.c:1349: internal error--unrecognizable insn:
	(insn 204 56 58 (set (reg:DF 17 %fp1)
	        (const_double:DF (mem/u:DF (symbol_ref/u:SI ("*.LC10")) 0) 0 [0x0] 0 [0x0] 0 [0x0])) -1 (nil)
	    (nil))
	gmake[3]: *** [pixops.lo] Error 1
	

	Fortunately, the error is located in the function 'bilinear_quadrant'
	mentioned above and can be reproduced without the framework of the
	package gdk-pixbuf.

	The error only occurs when '-O2' is specified together with '-fPIC'.
	Using '-O' / '-O3'  or omitting '-fPIC' lets the compiler proceed
	without errors.

	Gcc on NetBSD/amiga 1.5.2 can process the file with no trouble.
	
>How-To-Repeat:
	Compile the function below with the following command on an Amiga
	running NetBSD 1.6_BETA4 (probably any m68k port will do):

	$ cc -O2 -fPIC -c pixops.c 
	pixops.c: In function `bilinear_quadrant':
	pixops.c:56: internal error--unrecognizable insn:
	(insn 194 56 58 (set (reg:DF 17 %fp1)
	        (const_double:DF (mem/u:DF (symbol_ref/u:SI ("*.LC1")) 0) 0 [0x0] 0 [0x0] 0 [0x0])) -1 (nil)
	    (nil))

	pixops.c:
----- cut here ----------------------------------------------------------
static double
bilinear_quadrant (double bx0, double bx1, double by0, double by1)
{
  double ax0, ax1, ay0, ay1;
  double x0, x1, y0, y1;

  ax0 = 0.;
  ax1 = 1.;
  ay0 = 0.;
  ay1 = 1.;

  if (ax0 < bx0)
    {
      if (ax1 > bx0)
	{
	  x0 = bx0;
	  x1 = MIN (ax1, bx1);
	}
      else
	return 0;
    }
  else
    {
      if (bx1 > ax0)
	{
	  x0 = ax0;
	  x1 = MIN (ax1, bx1);
	}
      else
	return 0;
    }

  if (ay0 < by0)
    {
      if (ay1 > by0)
	{
	  y0 = by0;
	  y1 = MIN (ay1, by1);
	}
      else
	return 0;
    }
  else
    {
      if (by1 > ay0)
	{
	  y0 = ay0;
	  y1 = MIN (ay1, by1);
	}
      else
	return 0;
    }

  return 0.25 * (x1*x1 - x0*x0) * (y1*y1 - y0*y0);
}
----- cut here ----------------------------------------------------------
	
>Fix:
	Reducing the optimization level from '-O2' to '-O' does avoid the
	error message.
>Release-Note:
>Audit-Trail:
>Unformatted: