🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6246

[2.7.2] Suboptimal code

#6246
From: Andreas Schwab
Date: Fri, 22 Dec 1995 00:00
87 lines
2137 bytes
For the following example gcc generates suboptimal code on the m68k
(and probably on other cpu's as well).

-------------------- opt1.c
test (int n, int m)
{
  m = m * 2 + 1;
  foo (n);
  foo (m);
}
--------------------

Compiled with `gcc -O2 -S -b m68k-linux':

	.file	"opt1.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 	2
.globl test
	.type	 test,@function
test:
	link.w %a6,#0
	move.l %a2,-(%sp)
	move.l %d2,-(%sp)
	move.l 12(%a6),%d2
	move.l %d2,%d0		<----
	add.l %d0,%d0		<----
	move.l %d0,%d2		<----
	addq.l #1,%d2
	move.l 8(%a6),-(%sp)
	lea foo,%a2
	jbsr (%a2)
	move.l %d2,-(%sp)
	jbsr (%a2)
	move.l -8(%a6),%d2
	move.l -4(%a6),%a2
	unlk %a6
	rts
.Lfe1:
	.size	 test,.Lfe1-test
	.ident	"GCC: (GNU) 2.7.2"

The three marked instructions can be replaced by add.l %d2,%d2.

The following similar example does not have this problem:

-------------------- opt2.c
test (int n, int m)
{
  m = m * 2;
  foo (n);
  foo (m);
}
--------------------

-------------------- opt2.s
	.file	"opt2.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 	2
.globl test
	.type	 test,@function
test:
	link.w %a6,#0
	move.l %a2,-(%sp)
	move.l %d2,-(%sp)
	move.l 12(%a6),%d2
	add.l %d2,%d2		<----
	move.l 8(%a6),-(%sp)
	lea foo,%a2
	jbsr (%a2)
	move.l %d2,-(%sp)
	jbsr (%a2)
	move.l -8(%a6),%d2
	move.l -4(%a6),%a2
	unlk %a6
	rts
.Lfe1:
	.size	 test,.Lfe1-test
	.ident	"GCC: (GNU) 2.7.2"
--------------------

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
Technical Details
Message-ID: <9512221026.AA00900@lamothe.informatik.uni-dortmund.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,da169660e96c6b01,start
X-Google-Attributes: gid113d02,public
From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab)
Subject: [2.7.2] Suboptimal code
Date: 1995/12/22
Message-ID: <9512221026.AA00900@lamothe.informatik.uni-dortmund.de>
X-Deja-AN: 122686095
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: GNUs Not Usenet
reply-to: schwab@issan.informatik.uni-dortmund.de
newsgroups: gnu.gcc.bug