Bug 41462 - redundant instructions with long double returned value
Summary: redundant instructions with long double returned value
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-24 17:23 UTC by Yuri
Modified: 2009-09-25 08:04 UTC (History)
1 user (show)

See Also:
Host:
Target: i?86-*-*
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 Yuri 2009-09-24 17:23:58 UTC
When I compile this function:
double f(long double i) {return (i);}
with gcc flags -S -O3, I get the assembly below.

There are two redundant FPU instructions there. double value is already in FPU after fldt. No need to store it and load it back since difference between double and long double is only in memory representation, and in FPU registers they are the same.

---- asm output (relevant part) ----
f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp   <---- redundant related stack adjustment
        fldt    8(%ebp)    
        fstpl   -8(%ebp)   <---- redundant STORE
        fldl    -8(%ebp)   <---- redundant LOAD
        leave
        ret
Comment 1 Yuri 2009-09-24 17:25:06 UTC
Forgot to mention: 32-bit mode on i586 CPU.
Comment 2 Uroš Bizjak 2009-09-25 08:04:50 UTC
(In reply to comment #0)

> There are two redundant FPU instructions there. double value is already in FPU
> after fldt. No need to store it and load it back since difference between
> double and long double is only in memory representation, and in FPU registers
> they are the same.

No, they are not. These instructions implement FP truncation from long-double to double.  Try to compile your code with -ffast-math.