public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: richard@wetafx.co.nz
To: gcc-gnats@gcc.gnu.org
Subject: optimization/9641: const double arguments and -ffloat-store do not work together
Date: Mon, 10 Feb 2003 07:56:00 -0000	[thread overview]
Message-ID: <20030210075320.24402.qmail@sources.redhat.com> (raw)


>Number:         9641
>Category:       optimization
>Synopsis:       const double arguments and -ffloat-store do not work together
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 10 07:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     richard@wetafx.co.nz
>Release:        gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)
>Organization:
>Environment:
Linux 2.4.18-xfssmp #1 SMP i686
>Description:
//////////main.c
double rightfunc(double);
double wrongfunc(double);
int
main(void)
{
  rightfunc(0.75);
  wrongfunc(0.25);
}
//////////funcs.c
double rightfunc(double t) { return t; }
double wrongfunc(const double t) { return t; }
//////////GNUmakefile
all:    wrong right
right:  main.c funcs.c; gcc -O3 -o $@ main.c funcs.c
wrong:  main.c funcs.c; gcc -O3 -ffloat-store -o $@ main.c funcs.c
>How-To-Repeat:
With the three supplied files, use gmake to build.

The generated 'right' file works properly, but the
generated 'wrong' file generates incorrect code for
the 'wrongfunc' function:

0x8048474 <wrongfunc>:  push   %ebp
0x8048475 <wrongfunc+1>:        mov    %esp,%ebp
0x8048477 <wrongfunc+3>:        sub    $0x8,%esp
0x804847a <wrongfunc+6>:        fldl   0xfffffff8(%ebp)
0x804847d <wrongfunc+9>:        leave  
0x804847e <wrongfunc+10>:       ret    
0x804847f <wrongfunc+11>:       nop    

Basically, the code uses memory that has not be set
to the value passed as a 'const double' argument.

Note that rightfunc() has a double argument, while
wrongfunc() has a const double argument.  Otherwise
they are the same.

The 'wrong' file is built with -ffloat-store while
the 'right' file is built without.
>Fix:
I can avoid 'const double' arguments, but this may
mean some sifting through large code bases.

I can avoid using -ffloat-store, but then I run into
other code generation issues because of the broken
nature how the optimizer handles comparisons with
floats and doubles on Intel.
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-02-10  7:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-10  7:56 richard [this message]
2003-02-10 22:55 ehrhardt
2003-02-10 23:26 Richard Addison-Wood
2003-02-11  9:43 ehrhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030210075320.24402.qmail@sources.redhat.com \
    --to=richard@wetafx.co.nz \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).