public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "core13 at gmx dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/99930] New: Failure to optimize floating point -abs(x) in nontrivial code at -O2/3 Date: Tue, 06 Apr 2021 10:38:17 +0000 [thread overview] Message-ID: <bug-99930-4@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2021-04-06 10:38 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-06 10:38 core13 at gmx dot net [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99930-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).