public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/105513] New: [9/10/11/12/13 Regression] Unnecessary SSE spill
@ 2022-05-07  8:24 amonakov at gcc dot gnu.org
  2022-05-09  6:50 ` [Bug rtl-optimization/105513] [9/10/11/12/13 Regression] Unnecessary SSE spill since r9-5748-g1d4b4f4979171ef0 marxin at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: amonakov at gcc dot gnu.org @ 2022-05-07  8:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105513

            Bug ID: 105513
           Summary: [9/10/11/12/13 Regression] Unnecessary SSE spill
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization, ra
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amonakov at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-*-* i?86-*-*

Minimized from PR 105504.

Compile with -O2 -mtune=haswell -mavx (other -mtune variants are affected too):

static int as_int(float x)
{
    return (union{float x; int i;}){x}.i;
}

float f(double y, float x)
{
    int i = as_int(x);
    if (__builtin_expect(i > 99, 0)) return 0;
    if (i*2u < 77) if (i==2) return 0;
    return y*x;
}

GCC moves 'x' to 'i' via stack and then reloads from stack again when computing
'y*x':

f:
        vmovss  DWORD PTR [rsp-4], xmm1
        mov     eax, DWORD PTR [rsp-4]
        cmp     eax, 99
        jg      .L5
        lea     edx, [rax+rax]
        cmp     edx, 76
        ja      .L6
        cmp     eax, 2
        je      .L5
.L6:
        vcvtss2sd       xmm1, xmm1, DWORD PTR [rsp-4]
        vmulsd  xmm0, xmm1, xmm0
        vcvtsd2ss       xmm0, xmm0, xmm0
        ret
.L5:
        vxorps  xmm0, xmm0, xmm0
        ret

This is a regression relative to gcc-8. Interestingly, flipping '0' to '1' in
__builtin_expect (i.e. making early exit likely) results in good code, so
perhaps RA costing takes block probabilities backwards somewhere?

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-02-21  4:52 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07  8:24 [Bug rtl-optimization/105513] New: [9/10/11/12/13 Regression] Unnecessary SSE spill amonakov at gcc dot gnu.org
2022-05-09  6:50 ` [Bug rtl-optimization/105513] [9/10/11/12/13 Regression] Unnecessary SSE spill since r9-5748-g1d4b4f4979171ef0 marxin at gcc dot gnu.org
2022-05-09  6:57 ` [Bug target/105513] " pinskia at gcc dot gnu.org
2022-05-09  8:05 ` rguenth at gcc dot gnu.org
2022-05-09 13:32 ` crazylht at gmail dot com
2022-05-10  7:24 ` ubizjak at gmail dot com
2022-05-13  7:10 ` crazylht at gmail dot com
2022-05-16  3:06 ` crazylht at gmail dot com
2022-05-20  8:29 ` crazylht at gmail dot com
2022-05-20  9:02 ` amonakov at gcc dot gnu.org
2022-05-20  9:12 ` crazylht at gmail dot com
2022-05-27  9:48 ` [Bug target/105513] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-08  3:24 ` cvs-commit at gcc dot gnu.org
2022-06-28 10:49 ` jakub at gcc dot gnu.org
2023-07-07 10:43 ` [Bug target/105513] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-02-21  4:52 ` pinskia at gcc dot gnu.org

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).