public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13704] New: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling)
@ 2004-01-15 22:31 oneill+gccbugs at cs dot hmc dot edu
  2004-01-15 22:40 ` [Bug c/13704] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: oneill+gccbugs at cs dot hmc dot edu @ 2004-01-15 22:31 UTC (permalink / raw)
  To: gcc-bugs

This bug a regression in 3.2.x and 3.3.x -- it is not in 3.0.x or 3.4 prereleases, but is in 3.2.x and 
3.3.x (including 3.3-20040112) -- it would be helpful to see it fixed in the 3.3.x series, since at 
present it means that 3.3.x cannot be used without patches for some configurations.

Consider the following code (setjmp-caller.c), which will be compiled with -mno-abicalls -fno-pic 
-ffreestanding

--- begin file: setjmp-caller.c ------------------
int setjmp(void *);

int foo()
{
    setjmp(0);
}
--- end file: setjmp-caller.c ------------------

With 3.0.4 and 3.4-20040114, we get the following CORRECT assembly output from a cross 
compiler (built with -nfp), from running:

  mips-linux-gcc-3.0.4 -mno-abicalls -fno-pic -ffreestanding -S -o setjmp-caller-3.0.4.s setjmp-
caller.c

  mips-linux-gcc-3.4-20040114 -mno-abicalls -fno-pic -ffreestanding -S -o setjmp-caller-3.4
-20040114.s setjmp-caller.c


--- begin file: setjmp-caller-3.0.4.s ------------------
	.file	1 "setjmp-caller.c"
	.text
	.align	2
	.globl	foo
	.ent	foo
		.type		 foo,@function
foo:
	.frame	$fp,24,$31		# vars= 0, regs= 2/0, args= 16, extra= 0
	.mask	0xc0000000,-4
	.fmask	0x00000000,0
	subu	$sp,$sp,24
	sw	$31,20($sp)
	sw	$fp,16($sp)
	move	$fp,$sp
	move	$4,$0
	jal	setjmp
	move	$sp,$fp
	lw	$31,20($sp)
	lw	$fp,16($sp)
	addu	$sp,$sp,24
	j	$31
	.end	foo
	.ident	"GCC: (GNU) 3.0.4"
--- end file: setjmp-caller-3.0.4.s ------------------
--- begin file: setjmp-caller-3.4-20040114.s ------------------
	.file	1 "setjmp-caller.c"
	.section .mdebug.abi32
	.previous
	.text
	.align	2
	.globl	foo
	.ent	foo
	.type	foo, @function
foo:
	.frame	$fp,24,$31		# vars= 0, regs= 2/0, args= 16, gp= 0
	.mask	0xc0000000,-4
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	
	addiu	$sp,$sp,-24
	sw	$31,20($sp)
	sw	$fp,16($sp)
	move	$fp,$sp
	move	$4,$0
	jal	setjmp
	nop

	move	$sp,$fp
	lw	$31,20($sp)
	lw	$fp,16($sp)
	addiu	$sp,$sp,24
	j	$31
	nop

	.set	macro
	.set	reorder
	.end	foo
	.ident	"GCC: (GNU) 3.4.0 20040114 (experimental)"
--- end file: setjmp-caller-3.4-20040114.s ------------------

With the other versions, we get a number of spurious register saves...  For example, with 3.3.2, we 
get:

--- begin file: setjmp-caller-3.3.2.s ------------------
	.file	1 "setjmp-caller.c"
	.section .mdebug.abi32
	.previous
	.text
	.align	2
	.globl	foo
	.ent	foo
	.type	foo, @function
foo:
	.frame	$fp,104,$31		# vars= 0, regs= 10/6, args= 16, extra= 0
	.mask	0xc0ff0000,-52
	.fmask	0xfff00000,-8
	subu	$sp,$sp,104
	sw	$31,52($sp)
	sw	$fp,48($sp)
	sw	$23,44($sp)
	sw	$22,40($sp)
	sw	$21,36($sp)
	sw	$20,32($sp)
	sw	$19,28($sp)
	sw	$18,24($sp)
	sw	$17,20($sp)
	sw	$16,16($sp)
	s.d	$f30,96($sp)
	s.d	$f28,88($sp)
	s.d	$f26,80($sp)
	s.d	$f24,72($sp)
	s.d	$f22,64($sp)
	s.d	$f20,56($sp)
	move	$fp,$sp
	move	$4,$0
	jal	setjmp
	move	$sp,$fp
	lw	$31,52($sp)
	lw	$fp,48($sp)
	lw	$23,44($sp)
	lw	$22,40($sp)
	lw	$21,36($sp)
	lw	$20,32($sp)
	lw	$19,28($sp)
	lw	$18,24($sp)
	lw	$17,20($sp)
	lw	$16,16($sp)
	l.d	$f30,96($sp)
	l.d	$f28,88($sp)
	l.d	$f26,80($sp)
	l.d	$f24,72($sp)
	l.d	$f22,64($sp)
	l.d	$f20,56($sp)
	addu	$sp,$sp,104
	j	$31
	.end	foo
	.ident	"GCC: (GNU) 3.3.2"
--- end file: setjmp-caller-3.3.2.s ------------------

Since the cross compiler was configured with --nfp, this is especially bad, it's emiting floating 
point instructions for a program that doesn't use fp, on a platform that doesn't support it.

I wrote the following bandaid for 3.3.2, but I can't say that it's the right fix, it was just a "make it 
stop!" solution...

--- begin file: gcc-3.3.3-setjmp.patch ------------------
--- gcc-3.3.2+cs161/gcc/reload1.c~	2003-06-06 22:30:09.000000000 -0700
+++ gcc-3.3.2+cs161/gcc/reload1.c	2004-01-13 21:55:37.000000000 -0800
@@ -760,7 +760,7 @@
 	  && GET_MODE (insn) != VOIDmode)
 	PUT_MODE (insn, VOIDmode);
 
-      if (GET_CODE (insn) == CALL_INSN
+      if (0 && GET_CODE (insn) == CALL_INSN
 	  && find_reg_note (insn, REG_SETJMP, NULL))
 	for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
 	  if (! call_used_regs[i])
--- end file: gcc-3.3.3-setjmp.patch ------------------

Best Regards,

    M.E. O'Neill.

P.S.  For what it's worth, in case you want to look into this and you want to know how I built the 
cross compilers, it was as follows 

Download
  binutils-2.14.tar.bz2
  gcc-core-3.0.4.tar.gz
  gcc-core-3.2.3.tar.bz2
  gcc-core-3.3-20040112.tar.bz2
  gcc-core-3.3.2.tar.bz2
  gcc-core-3.4-20040114.tar.bz2

And then, in csh:

set target = mips-linux
set base = `pwd`
set prefix = $base/test-gcc
mkdir -p $prefix/bin
set path = ($path $prefix/bin)
tar xjf binutils-2.14.tar.bz2 
mkdir binutils-2.14-build
cd binutils-2.14-build
../binutils-2.14/configure --nfp --target $target --prefix $prefix
make
make install

foreach vers (3.2.3 3.3.2 3.3-20040112 3.4-20040114)
  cd $base
  if (-e gcc-core-$vers.tar.gz) tar xzf gcc-core-$vers.tar.gz
  if (-e gcc-core-$vers.tar.bz2) tar xjf gcc-core-$vers.tar.bz2
  mkdir -p gcc-$vers-build
  cd gcc-$vers-build
  ../gcc-$vers/configure --nfp --disable-shared --disable-threads --target  $target --prefix 
$prefix
  make 
  make install
  cd $base
  mv $prefix/bin/mips-linux-gcc{,-$vers}
  mv $prefix/bin/mips-linux-cpp{,-$vers}
  rehash
  mips-linux-gcc-$vers -mno-abicalls -fno-pic -ffreestanding -S -o setjmp-caller-$vers.s 
setjmp-caller.c
end

(note that the 3.4-20040114 build will die [hey, it's a snapshot], but it's easy enough to fix by 
hand)

-- 
           Summary: Regression: Spurious register saves with setjmp on MIPS
                    (and others?) (crosscompiling)
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P1
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: oneill+gccbugs at cs dot hmc dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: mips-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13704


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/13704] Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling)
  2004-01-15 22:31 [Bug c/13704] New: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling) oneill+gccbugs at cs dot hmc dot edu
@ 2004-01-15 22:40 ` pinskia at gcc dot gnu dot org
  2004-01-15 23:18 ` oneill+gccbugs at cs dot hmc dot edu
  2004-01-16  8:40 ` rsandifo at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-15 22:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-15 22:40 -------
Note this is not going to be fixed for 3.3.3, as it really only pessimizes-code.  This is a dup of bug 
13133.

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

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |pessimizes-code
         Resolution|                            |DUPLICATE
   Target Milestone|---                         |3.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13704


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/13704] Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling)
  2004-01-15 22:31 [Bug c/13704] New: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling) oneill+gccbugs at cs dot hmc dot edu
  2004-01-15 22:40 ` [Bug c/13704] " pinskia at gcc dot gnu dot org
@ 2004-01-15 23:18 ` oneill+gccbugs at cs dot hmc dot edu
  2004-01-16  8:40 ` rsandifo at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: oneill+gccbugs at cs dot hmc dot edu @ 2004-01-15 23:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From oneill+gccbugs at cs dot hmc dot edu  2004-01-15 23:18 -------
NO, it isn't just a code pessimization issue.  As I said in my report, saving FP regs is an absolute 
no-no for platforms that don't have an FP unit and aren't using any FP code.

Anyway, it's good to know that my patch was (essentially) the right thing to do, and I can use that 
without worrying that it'll break something else.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13704


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/13704] Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling)
  2004-01-15 22:31 [Bug c/13704] New: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling) oneill+gccbugs at cs dot hmc dot edu
  2004-01-15 22:40 ` [Bug c/13704] " pinskia at gcc dot gnu dot org
  2004-01-15 23:18 ` oneill+gccbugs at cs dot hmc dot edu
@ 2004-01-16  8:40 ` rsandifo at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: rsandifo at redhat dot com @ 2004-01-16  8:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rsandifo at redhat dot com  2004-01-16 08:40 -------
Subject: Re:  New: Regression: Spurious register saves with
 setjmp on MIPS (and others?) (crosscompiling)

Thanks for the detailed bug report btw.  As Andrew says, the problem
of saving more registers than necessary won't be solved for 3.3.
However...

"oneill+gccbugs at cs dot hmc dot edu" <gcc-bugzilla@gcc.gnu.org> writes:
> Since the cross compiler was configured with --nfp, this is especially
> bad, it's emiting floating point instructions for a program that
> doesn't use fp, on a platform that doesn't support it.

Note that --nfp doesn't do anything for MIPS.  As the documentation says:

    @item --nfp
    Specify that the machine does not have a floating point unit.  This
    option only applies to @samp{m68k-sun-sunos@var{n}}.  On any other
    system, @option{--nfp} has no effect.

With 3.3 and earlier, there is no standard way of creating a "soft float
by default" configuration.  You either need to add a new configuration
triplet to config.gcc or pass -msoft-float each time you run the compiler.

With 3.4, you can configure using --with-float=soft, which is supported
for MIPS and for several other targets.

So you should be able to create correct, but still suboptimal,
code by passing -msoft-float to a stock version of 3.2 or 3.3.
If you don't do this, there's a danger the compiler could use
fprs in other contexts besides setjmp() calls.

Richard


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13704


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-16  8:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-15 22:31 [Bug c/13704] New: Regression: Spurious register saves with setjmp on MIPS (and others?) (crosscompiling) oneill+gccbugs at cs dot hmc dot edu
2004-01-15 22:40 ` [Bug c/13704] " pinskia at gcc dot gnu dot org
2004-01-15 23:18 ` oneill+gccbugs at cs dot hmc dot edu
2004-01-16  8:40 ` rsandifo at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).