User account creation filtered due to spam.

Bug 9967 - Some standard C function calls should not be replaced when optimizing for size
Summary: Some standard C function calls should not be replaced when optimizing for size
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2003-03-05 14:26 UTC by Arpad Beszedes
Modified: 2010-10-27 16:59 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arpad Beszedes 2003-03-05 14:26:00 UTC
GCC replaces calls with special parameters to some standard C functions to equivalent ones in order to increase performance. E.g. fputs with string parameter -> fwrite.
However, some of these calls take more instructions, which is not good if we optimize for size. These replacements should be avoided depending on the optimization switches. (See example below.)

Release:
gcc version 3.3 20030224 (prerelease)

Environment:
BUILD & HOST: Linux 2.4.20 i686 unknown
TARGET: arm-unknown-elf

How-To-Repeat:
This simple program demonstrates that fprintf is replaced by calling fwrite in the assembly output (arm-elf target with newlib library):

#include <stdio.h>
void foo ()
{
  fprintf(stderr, "Comment"); // fprintf->fwrite
}

ldr r3, .L2
ldr r3, [r3, #0]
ldr r0, .L2+4
ldr r3, [r3, #12]
mov r1, #1
mov r2, #7
b fwrite

However, calling fprintf would require two instructions less:

ldr r3, .L2
ldr r3, [r3, #0]
ldr r1, .L2+4
ldr r0, [r3, #12]
b fprintf
Comment 1 Eric Botcazou 2003-03-28 10:45:51 UTC
State-Changed-From-To: open->closed
State-Changed-Why: On submitter's request.
Comment 2 beszedes 2003-03-28 11:13:17 UTC
From: Arpad Beszedes <beszedes@cc.u-szeged.hu>
To: gcc-gnats@gcc.gnu.org,  gcc-bugs@gcc.gnu.org,  nobody@gcc.gnu.org, 
 gcc-prs@gcc.gnu.org,  beszedes@rgai.hu,  ghazi@caip.rutgers.edu
Cc:  
Subject: Re: middle-end/9967: Some standard C function calls should not be
 replaced when optimizing for size
Date: Fri, 28 Mar 2003 11:13:17 +0100

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9967
 
 This PR can be closed, because a patch has been implemented and applied 
 to 3.3 and mainline:
 
 http://gcc.gnu.org/ml/gcc-patches/2003-03/threads.html#00425
 
 Thanks,
    Arpad Beszedes
 
Comment 3 Kaveh Ghazi 2003-03-29 23:49:33 UTC
From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
To: beszedes@cc.u-szeged.hu, beszedes@rgai.hu, gcc-bugs@gcc.gnu.org,
        gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: middle-end/9967: Some standard C function calls should not be replaced when optimizing for size
Date: Sat, 29 Mar 2003 23:49:33 -0500 (EST)

 > From: Arpad Beszedes <beszedes@cc.u-szeged.hu>
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9967
 > 
 > This PR can be closed, because a patch has been implemented and applied 
 > to 3.3 and mainline:
 > 
 > http://gcc.gnu.org/ml/gcc-patches/2003-03/threads.html#00425
 
 FYI, Gaby approved it for 3.2.3 via private email, and I've just
 applied the patch there too.
 --
 Kaveh R. Ghazi			ghazi@caip.rutgers.edu