Bug 27139 - Optimize double INT->FP->INT conversions with -ffast-math
Summary: Optimize double INT->FP->INT conversions with -ffast-math
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2006-04-12 20:48 UTC by Uroš Bizjak
Modified: 2012-05-05 00:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-04-12 23:59:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2006-04-12 20:48:05 UTC
This testcase:

int test (int a)
{
        return (double) a;
}

Produces:

        cvtsi2sd        %edi, %xmm0
        cvttsd2si       %xmm0, %eax
        ret

However, following code does the same (at least for -ffast-math):
        movl    %edi, %eax
        ret
Comment 1 Andrew Pinski 2006-04-12 23:59:25 UTC
Confirmed, I doubt this shows up that much anyways.
Comment 2 Marc Glisse 2012-04-24 06:35:43 UTC
(In reply to comment #0)
> int test (int a)
> {
>         return (double) a;
> }

I just wrote the very same testcase today, extracted from my code...

> Produces:
> 
>         cvtsi2sd        %edi, %xmm0
>         cvttsd2si       %xmm0, %eax
>         ret

Still does. Did you have any idea how to handle it?

> However, following code does the same (at least for -ffast-math):
>         movl    %edi, %eax
>         ret

I don't think -ffast-math is relevant here, on x86 the int->double conversion is exact hence the reverse has to be as well.

(In reply to comment #1)
> Confirmed, I doubt this shows up that much anyways.

Just posting to mention that it does show up...
Comment 3 Richard Biener 2012-04-27 10:34:18 UTC
Author: rguenth
Date: Fri Apr 27 10:34:13 2012
New Revision: 186898

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186898
Log:
2012-04-27  Marc Glisse  <marc.glisse@inria.fr>

	PR middle-end/27139
	* tree-ssa-forwprop.c (combine_conversions): Handle INT->FP->INT.

	* gcc.dg/tree-ssa/forwprop-18.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/forwprop-18.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-forwprop.c
Comment 4 Marc Glisse 2012-05-01 09:32:25 UTC
Hello Uros,
is there any other case you think should be handled, or should we close the bug?
Comment 5 Marc Glisse 2012-05-05 00:20:08 UTC
Closing then.