This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/2433: wrong function param handling in UltraSPARC optimized code
- To: gcc-gnats at gcc dot gnu dot org
- Subject: optimization/2433: wrong function param handling in UltraSPARC optimized code
- From: gawrilow at math dot tu-berlin dot de
- Date: 30 Mar 2001 09:38:47 -0000
- Reply-To: gawrilow at math dot tu-berlin dot de
>Number: 2433
>Category: optimization
>Synopsis: wrong function param handling in UltraSPARC optimized code
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Mar 30 01:46:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Ewgenij Gawrilow, Technical University Berlin
>Release: gcc version 2.95.3 20010315 (release)
>Organization:
>Environment:
sun-sparc-solaris2.7
gcc taken unchanged from the distribution tarball,
configured with --enable-shared --enable-version-specific-runtime-libs
--enable-languages=f77,c++
>Description:
The bug shows up in the prologue of C/C++ functions
having at least 6 parameters, the trailing one requiring
double word alignment, compiled with -O2 -mcpu=ultrasparc.
Without optimization, the trailing double parameter is
retrieved from the caller's stack frame word by word, then
stored at the properly aligned location in the callee's
local frame, and finally loaded into the FP register:
save %sp, -136, %sp
...
ld [%fp + 92], %o0
ld [%fp + 96], %o1
std %o0, [%fp - 32]
ldd [%fp - 32], %f2
The optimized version tries to accelerate this step
and loads the FP register directly from the outgoing
parameter area in the caller's stack frame:
add %sp, -120, %sp
...
ldd [%sp + 212], %f0
However, according to the SPARC ABI, a double parameter is
passed just in the next available pair of adjacent registers
or stack words, so that its location in the caller's stack
frame is not necessarily double-word aligned.
As a consequence, the program terminates with BUS ERROR.
>How-To-Repeat:
Compile the attached source file with -O2 -mcpu=ultrasparc.
Disassemble the code of the foo() function. Or just run
the executable - it dies with BUS ERROR.
>Fix:
A nasty workaround is to reorder the function parameters,
forcing the proper alignment of stack arguments. However,
we can't apply it in our concrete case, as we are using
a library developed externally which we may not alter.
The best possible optimization is crucial for our project,
however.
Thus we'd very much appreciate to be notified as soon
as a patch applicable to the 2.95.3 source is available.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="float_param.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="float_param.c"
ZG91YmxlIGZvbyhpbnQgYSwgaW50IGIsIGludCBjLCBpbnQgZCwgZG91YmxlIGUsIGRvdWJsZSBm
KSB7CiAgIGRvdWJsZSBnOwogICBhPWE7CiAgIGI9YjsKICAgYz1jOwogICBkPWQ7CiAgIGU9ZTsK
ICAgaWYgKGY8MCkKICAgICAgZz1lK2Y7CiAgIGVsc2UKICAgICAgZz1lLWY7CiAgIHJldHVybiBn
Owp9CgppbnQgbWFpbigpIHsKICAgaW50IGE9MCwgYj0wLCBjPTAsIGQ9MDsKICAgZG91YmxlIGU9
MSwgZj0yLCBnOwogICBnPWZvbyhhLGIsYyxkLGUsZik7CiAgIHJldHVybiBnPjA7Cn0K