Bug 81516 - Wrong code with -m32 -O2 on x86_64-linux-gnu
Summary: Wrong code with -m32 -O2 on x86_64-linux-gnu
Status: RESOLVED DUPLICATE of bug 80706
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2017-07-22 17:36 UTC by Davin McCall
Modified: 2017-07-23 17:05 UTC (History)
2 users (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
reduced test case (274 bytes, text/plain)
2017-07-22 17:36 UTC, Davin McCall
Details
alternate, further reduced test case (198 bytes, text/plain)
2017-07-22 19:54 UTC, mednafen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Davin McCall 2017-07-22 17:36:42 UTC
Created attachment 41809 [details]
reduced test case

Attached file (reduced test case from string-to-double conversion routine in Firefox 54.0.1) aborts when compiled with:

  gcc -m32 -O2 wrong-code.c

It's fine when compiled with -O1 or without -m32.
Comment 1 Davin McCall 2017-07-22 17:39:56 UTC
(triggers with -march=prescott|haswell, not with -march=i686)
Comment 2 mednafen 2017-07-22 19:54:28 UTC
Created attachment 41811 [details]
alternate, further reduced test case

bug occurs with: -O2 -m32 -march=i686 -msse2 -mfpmath=387
but not with: -O2 -m32 -march=i686 -msse2 -mfpmath=sse
Comment 3 Andrew Pinski 2017-07-22 19:58:08 UTC
Most likely a dup of bug 323.
Comment 4 Davin McCall 2017-07-22 20:05:37 UTC
(In reply to Andrew Pinski from comment #3)
> Most likely a dup of bug 323.

I don't think so, unless I'm misunderstanding something. There's no rounding in the test case, just a store of an int value to a double variable, and furthermore the result is _completely_ wrong, not just off by a bit.
Comment 5 mednafen 2017-07-22 20:08:58 UTC
Generated assembly looks like it's grabbing garbage off the stack and writing it to b:

a:
        subl    $20, %esp
        fildl   24(%esp)
        movsd   (%esp), %xmm1
        movsd   %xmm1, b
        [...]
Comment 6 Uroš Bizjak 2017-07-22 20:21:08 UTC
(In reply to mednafen from comment #2)
> Created attachment 41811 [details]
> alternate, further reduced test case

Works OK for me with:

-O2 -m32 -march=i686 -msse2 -mfpmath=387

a:
        subl    $20, %esp
        fildl   24(%esp)
        cmpl    $10, 24(%esp)
        fstpl   (%esp)
        movq    (%esp), %xmm0
        movsd   (%esp), %xmm1
        movq    %xmm0, 8(%esp)
        movsd   %xmm1, b
        jg      .L1
        xorl    %eax, %eax
        movl    %eax, 12(%esp)
        movsd   8(%esp), %xmm2
        movsd   %xmm2, (%esp)
.L1:
        fldl    (%esp)
        addl    $20, %esp
        ret

        .ident  "GCC: (GNU) 7.1.1 20170718 [gcc-7-branch revision 250314]"
Comment 7 Davin McCall 2017-07-22 23:07:41 UTC
(In reply to Uroš Bizjak from comment #6)
> 
> Works OK for me with:
> 
>         .ident  "GCC: (GNU) 7.1.1 20170718 [gcc-7-branch revision 250314]"

Reported against 7.1.0. It may well be fixed already on the branch/trunk; in that case I would suggest adding a regression test if it is not otherwise a known bug and closing as resolved.
Comment 8 Davin McCall 2017-07-23 13:45:36 UTC
This problem disappears when I apply the fix for #80706 (as applied to GCC 7 branch). Possibly this is a duplicate of that issue.
Comment 9 Andrew Pinski 2017-07-23 17:05:13 UTC
Dup of bug 80706 then.

*** This bug has been marked as a duplicate of bug 80706 ***