Bug 14060 - An unused register is saved to the stack.
Summary: An unused register is saved to the stack.
Status: RESOLVED DUPLICATE of bug 39871
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
Keywords: missed-optimization, ra
Depends on:
Reported: 2004-02-07 06:25 UTC by Kazu Hirata
Modified: 2016-11-19 21:47 UTC (History)
2 users (show)

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


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 *);

foo (long z)
  long a[2];

  a[0] = z;

  while (1)
      if (bar (z, a))

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

	mov.l	er4,@-er7
	mov.l	er5,@-er7
	subs	#4,er7
	subs	#4,er7
	mov.l	er0,er4
	mov.l	er0,@er7
	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
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)

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


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?
Comment 3 Jeffrey A. Law 2016-11-19 21:47:08 UTC
Fixed long ago.

*** This bug has been marked as a duplicate of bug 39871 ***