Bug 14060 - An unused register is saved to the stack.
Summary: An unused register is saved to the stack.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, ra
Depends on:
Blocks:
 
Reported: 2004-02-07 06:25 UTC by Kazu Hirata
Modified: 2005-12-24 20:41 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: h8300-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-24 20:41:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2004-02-07 06:25:13 UTC
/* Use ./cc1 -mh -O2 -fomit-frame-pointer.  */

extern long bar (long, long *);

void
foo (long z)
{
  long a[2];

  a[0] = z;

  while (1)
    {
      if (bar (z, a))
	return;
    }
}

Note that er5 is saved but not used anywhere in the function.

_foo:
	mov.l	er4,@-er7
	mov.l	er5,@-er7
	subs	#4,er7
	subs	#4,er7
	mov.l	er0,er4
	mov.l	er0,@er7
.L2:
	mov.l	er7,er1
	mov.l	er4,er0
	jsr	@_bar
	mov.l	er0,er0
	beq	.L2
	adds	#4,er7
	adds	#4,er7
	mov.l	@er7+,er5
	mov.l	@er7+,er4
	rts
Comment 1 Kazu Hirata 2004-02-07 06:38:37 UTC
My guess is as follows:

Before the register allocation, we have this.

(insn 46 10 12 0 (set (reg/f:SI 20)
        (plus:SI (reg/f:SI 11 fp)
            (const_int -8 [0xfffffff8]))) 36 {*addsi_h8300hs} (nil)
    (nil))

There is no matching constraint for this insn
(because H8 is a two-address machine).
So the source is spilled.
But it turns out that (plus (reg:SI 11) (const_int -8)) is equal to (reg:SI sp).
So an addition instruction becomes a move instruction:

(set (reg:SI 20) (reg:SI sp))

But the reload or the register allocator doesn't go back and say that
the spill made above is not necessary anymore.

Before this patch

http://gcc.gnu.org/ml/gcc-patches/2004-01/msg03252.html

I used to see a use of er5 (although a stupid one).

eliminate_regs_in_insn() is called too late to notice that
the spill is not needed.
Comment 2 Steven Bosscher 2005-02-08 10:19:36 UTC
Kazu, is this still a problem?