public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jmvalin at jmvalin dot ca" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59424] New: Optimization issue on min/max Date: Mon, 09 Dec 2013 06:01:00 -0000 [thread overview] Message-ID: <bug-59424-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59424 Bug ID: 59424 Summary: Optimization issue on min/max Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jmvalin at jmvalin dot ca gcc seems to be having problems optimizing float min/max code and behaves unpredictably. If I compile the following code on an x86-64 (SSE enabled): #include <math.h> float func1(float a, float b) { return (a < b ? a : b); } float func2(float a, float b) { return sqrtf(a < b ? a : b); } float func3(float a, float b) { return fabsf(a < b ? a : b); } I get the following disassembly: 0000000000000000 <func1>: func1(): 0: f3 0f 5d c1 minss %xmm1,%xmm0 4: c3 retq 5: 66 66 2e 0f 1f 84 00 data32 nopw %cs:0x0(%rax,%rax,1) c: 00 00 00 00 0000000000000010 <func2>: func2(): 10: f3 0f 5d c1 minss %xmm1,%xmm0 14: f3 0f 51 c0 sqrtss %xmm0,%xmm0 18: c3 retq 19: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 0000000000000020 <func3>: func3(): 20: 0f 2f c8 comiss %xmm0,%xmm1 23: 77 13 ja 38 <func3+0x18> 25: f3 0f 10 05 00 00 00 movss 0x0(%rip),%xmm0 # 2d <func3+0xd> 2c: 00 2d: 0f 54 c1 andps %xmm1,%xmm0 30: c3 retq 31: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 38: f3 0f 10 0d 00 00 00 movss 0x0(%rip),%xmm1 # 40 <func3+0x20> 3f: 00 40: 0f 54 c1 andps %xmm1,%xmm0 43: c3 retq So gcc is correctly using maxss in func1 and func2, but not in func2. In practice, I'm using MIN/MAX macros extensively in libopus and gcc is missing the optimization most of the time, slowing down the code.
next reply other threads:[~2013-12-09 6:01 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-12-09 6:01 jmvalin at jmvalin dot ca [this message] 2013-12-09 11:13 ` [Bug c/59424] " mpolacek at gcc dot gnu.org 2013-12-09 14:49 ` rguenth at gcc dot gnu.org 2013-12-09 17:05 ` jmvalin at jmvalin dot ca 2021-07-06 8:18 ` [Bug middle-end/59424] " pinskia at gcc dot gnu.org 2023-05-08 7:38 ` cvs-commit at gcc dot gnu.org 2023-05-08 7:41 ` 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-59424-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).