🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Peter Huebner Tue, 13 Oct 1992 18:54
Looks like a bug in the gcc optimizer
#1195
Author: 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
/**********************************************************************/ 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads