public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/99930] New: Failure to optimize floating point -abs(x) in nontrivial code at -O2/3
@ 2021-04-06 10:38 core13 at gmx dot net
  2021-04-06 11:57 ` [Bug rtl-optimization/99930] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: core13 at gmx dot net @ 2021-04-06 10:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99930
           Summary: Failure to optimize floating point -abs(x) in
                    nontrivial code at -O2/3
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: core13 at gmx dot net
  Target Milestone: ---

Expected compiler output for -abs(x) is an orps setting the sign bit.


It works as expected with trivial code at -O1/2/3 optimization levels:

float q(float p)
{
    return -std::abs(p);
}

orps    xmm0, XMMWORD PTR .LC1[rip]
ret


With more complex code the compiler uses orps at -O1 but andps + xorps at
-O2/3:

bool t(float n[2], float m)
{
    for (int i = 0; i < 2; i++)
        if (m > -std::abs(n[i]))
            return true;
    return false;
}

-O1
movss   xmm1, DWORD PTR [rdi]
orps    xmm1, XMMWORD PTR .LC1[rip]
comiss  xmm0, xmm1
ja      .L3
movss   xmm1, DWORD PTR [rdi+4]
orps    xmm1, XMMWORD PTR .LC1[rip]
comiss  xmm0, xmm1
seta    al
ret

-O2/3
movss   xmm1, DWORD PTR [rdi]
movss   xmm3, DWORD PTR .LC0[rip]
movss   xmm2, DWORD PTR .LC1[rip]
andps   xmm1, xmm3
xorps   xmm1, xmm2
comiss  xmm0, xmm1
ja      .L3
movss   xmm1, DWORD PTR [rdi+4]
andps   xmm1, xmm3
xorps   xmm1, xmm2
comiss  xmm0, xmm1
seta    al
ret

https://godbolt.org/z/5ch5ceEj7

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

end of thread, other threads:[~2023-12-24 23:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 10:38 [Bug target/99930] New: Failure to optimize floating point -abs(x) in nontrivial code at -O2/3 core13 at gmx dot net
2021-04-06 11:57 ` [Bug rtl-optimization/99930] " rguenth at gcc dot gnu.org
2021-04-06 12:00 ` rguenth at gcc dot gnu.org
2021-04-06 17:31 ` segher at gcc dot gnu.org
2021-04-07 10:04 ` jakub at gcc dot gnu.org
2021-04-07 10:06 ` jakub at gcc dot gnu.org
2021-04-07 10:14 ` ubizjak at gmail dot com
2021-04-07 10:27 ` crazylht at gmail dot com
2021-04-07 16:32 ` segher at gcc dot gnu.org
2021-04-08  9:48 ` crazylht at gmail dot com
2021-04-08 22:46 ` segher at gcc dot gnu.org
2021-07-25  1:30 ` pinskia at gcc dot gnu.org
2023-12-24 23:16 ` [Bug middle-end/99930] " 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).