🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1195

Looks like a bug in the gcc optimizer

#1195
From: Peter Huebner
Date: Tue, 13 Oct 1992 18:54
155 lines
3506 bytes
I have compiled a program on a IBM-RS6000 with gcc -O2 (version 2.2.2)
twice with a constant kappa = 1.0 and kappa = 0.0, with which huge
expressions are multiplied. I was very surprised that the code for the
kappa = 0.0 case was longer then the one for the kappa = 1.0 case.  I
have included a short test program and the assembler codes produced
for both cases. For me as I am doing numerics it would be essential if
optimizing removed terms multiplied by zero. At least a option
enforcing this would be great.

Thanks a lot, Peter Huebner


Program:
/*********************************************************************/
#include <stdio.h>

#define kappa 0.0

main()
{
  double x, y;

  x = 2.0 + kappa*y*y*y*y*y*y;

  printf("%e\n",x);
}
/********************************************************************/

Assemblercode, generated with the command "gcc -O2 test.c -c" and kappa = 0.0:
/********************************************************************/
	.toc
gcc2_compiled.:
	.extern .__main
	.extern printf[DS]
	.extern .printf
	.csect _test.rw_c[RO]
	.align 2
LC..2:
	.byte "%e"
	.byte 10, 0
	.toc
LC..0:
	.tc FD_0_0[TC],0,0
LC..1:
	.tc FD_40000000_0[TC],1073741824,0
LC..3:
	.tc LC..2[TC],LC..2
.csect [PR]
	.align 2
	.globl main
	.globl .main
	.csect main[DS]
main:
	.long .main, TOC[tc0], 0
	.csect [PR]
.main:
	mflr 0
	stfd 31,-8(1)
	st 0,8(1)
	stu 1,-72(1)
	bl .__main
	cror 15,15,15
	lfd 1,LC..0(2)
	fm 1,31,1
	fm 1,1,31
	fm 1,1,31
	fm 1,1,31
	lfd 0,LC..1(2)
	fm 1,1,31
	fma 1,1,31,0
	l 3,LC..3(2)
	stfd 1,56(1)
	l 4,56(1)
	l 5,60(1)
	bl .printf
	cror 15,15,15
	ai 1,1,72
	l 0,8(1)
	mtlr 0
	lfd 31,-8(1)
	br
LT..main:
	.long 0
	.byte 0,0,34,65,129,0,0,0
	.long LT..main-.main
	.short 4
	.byte "main"
_section_.text:
.csect .data[RW]
	.long _section_.text
/***************************************************************/

Assemblercode, generated with the command "gcc -O2 test.c -c" and kappa = 1.0:
/***************************************************************/
	.toc
gcc2_compiled.:
	.extern .__main
	.extern printf[DS]
	.extern .printf
	.csect _test.rw_c[RO]
	.align 2
LC..2:
	.byte "%e"
	.byte 10, 0
	.toc
LC..0:
	.tc FD_0_0[TC],0,0
LC..1:
	.tc FD_40000000_0[TC],1073741824,0
LC..3:
	.tc LC..2[TC],LC..2
.csect [PR]
	.align 2
	.globl main
	.globl .main
	.csect main[DS]
main:
	.long .main, TOC[tc0], 0
	.csect [PR]
.main:
	mflr 0
	stfd 31,-8(1)
	st 0,8(1)
	stu 1,-72(1)
	bl .__main
	cror 15,15,15
	lfd 1,LC..0(2)
	fm 1,31,1
	fm 1,1,31
	fm 1,1,31
	fm 1,1,31
	lfd 0,LC..1(2)
	fm 1,1,31
	fma 1,1,31,0
	l 3,LC..3(2)
	stfd 1,56(1)
	l 4,56(1)
	l 5,60(1)
	bl .printf
	cror 15,15,15
	ai 1,1,72
	l 0,8(1)
	mtlr 0
	lfd 31,-8(1)
	br
LT..main:
	.long 0
	.byte 0,0,34,65,129,0,0,0
	.long LT..main-.main
	.short 4
	.byte "main"
_section_.text:
.csect .data[RW]
	.long _section_.text
/**********************************************************************/ 
Technical Details
Message-ID: <9210131854.AA61410@ibm-1.mpa.ipp-garching.mpg.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ibm-1.mpa.ipp-garching.mpg.de!pth

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ibm-1.mpa.ipp-garching.mpg.de!pth
From: pth@ibm-1.mpa.ipp-garching.mpg.de (Peter Huebner)
Subject: Looks like a bug in the gcc optimizer
Message-ID: <9210131854.AA61410@ibm-1.mpa.ipp-garching.mpg.de>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 13 Oct 1992 18:54:36 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 159