This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Totally bogus string optimizations
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: Totally bogus string optimizations
- From: Bernd Schmidt <bernds at redhat dot co dot uk>
- Date: Sat, 28 Oct 2000 19:06:54 +0100 (BST)
I just found out that on ia64, the simple test program
#include <string.h>
char *p;
int main ()
{
strcpy (p, "Foobar");
}
causes _horrendous_ assembly code to be generated. Apparently, for a machine
that does not define _STRING_ARCH_unaligned, /usr/include/bits/string2.h
contains totally bogus code.
I've compiled this on i386 with 2.95.2 just to see whether this could be a
gcc code quality regression that has crept in since this release. The result
is below, and you can see, it's definitely the strcpy macro that's broken,
and just by looking at the preprocessor output you can see why this sort of
nonsense is happening - we construct eight constant arrays and then use one
of them as the source of the copy.
My suggestion: don't try to "optimize" string functions. Delete string2.h.
What's the point anyway? The compiler should know how to do these
optimizations properly. Besides, you'll save compile time because the
preprocessor and parser no longer have to evaluate the resulting monster
expressions.
Guess I'll be running my SPEC tests with -D__NO_STRING_INLINES from now.
Maybe even submit a gcc patch to put that in the specs file. Grumble...
Bernd
.file "tst.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "Foobar"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl p,%ecx
movl %esp,%ebp
subl $88,%esp
movb $70,-56(%ebp)
movb $111,-55(%ebp)
movl -56(%ebp),%eax
movw %ax,-44(%ebp)
movb $70,-64(%ebp)
movb $111,-63(%ebp)
movb $111,-62(%ebp)
movb $98,-61(%ebp)
movl -64(%ebp),%eax
movl %eax,-36(%ebp)
movb $70,-72(%ebp)
movb $111,-71(%ebp)
movb $111,-70(%ebp)
movb $98,-69(%ebp)
movl -72(%ebp),%eax
movb $97,-68(%ebp)
movb $0,-67(%ebp)
movl %eax,-28(%ebp)
movl -68(%ebp),%eax
movb $70,-80(%ebp)
movb $111,-79(%ebp)
movb $111,-78(%ebp)
movb $98,-77(%ebp)
movl -80(%ebp),%edx
movb $0,-54(%ebp)
movb $0,-42(%ebp)
movb $0,-60(%ebp)
movb $0,-32(%ebp)
movw %ax,-24(%ebp)
movb $97,-76(%ebp)
movb $114,-75(%ebp)
movb $0,-74(%ebp)
movl %edx,-20(%ebp)
movl -76(%ebp),%eax
movw %ax,-16(%ebp)
movb $0,-14(%ebp)
movl %edx,(%ecx)
movl -16(%ebp),%eax
movw %ax,4(%ecx)
movb -14(%ebp),%al
movb %al,6(%ecx)
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size main,.Lfe1-main
.comm p,4,4
.ident "GCC: (GNU) 2.95.2 19991024 (release)"