[PATCH] bfd sparc64 fixes and tail call optimizations

Jakub Jelinek jakub@redhat.com
Thu May 18 07:21:00 GMT 2000


Hi!

Attached are three patches. The first one was posted two month ago to this
list but is still not commited, the latter two are new.
The latter two implement tail call optimization in gas/ld for sparc:

the usual way of doing tail call on SPARC is:

call foo
restore ...

or

mov %o7, %g1
call foo
mov %g1, %o7

or

sethi %hi(foo), %g1
jmpl %g1 + %lo(foo), %g0
...

I have no idea how can I safely optimize the last one (perhaps I'll just
teach gcc to always emit 2nd one), but for the first two, the call can be
replaced by branch always instruction. The advantage of doing so is to avoid
clobbering return address stack on Ultra (because due to the tail call all
things from that point on will be mispredicted on RAS) and I believe even
for other CPUs ba is more pairable than call.
The optimization can be done if:

call's destination is close (at most +-8M, the usual case)
call's delay slot is either restore instruction which does not use %o7 in
rs1/rs2 or some instruction which overwrites %o7 and does not use it.
For simplicity I only implemented the optimization if there is restore or
{add,and,or,xor,sub,andn,orn,xnor}cc *,*,%o7
(and the delay slot obviously does not use %o7 in rs1/rs2).
The only program visible difference between ba and call is setting %o7 to
%pc (unless someone reads instructions as data), so if we're sure the
instruction in its delay slot will kill that value, this optimization is
safe.

	Jakub


More information about the Binutils mailing list