From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22876 invoked by alias); 9 Dec 2013 06:01:29 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22860 invoked by uid 48); 9 Dec 2013 06:01:25 -0000 From: "jmvalin at jmvalin dot ca" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.7.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jmvalin at jmvalin dot ca X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-12/txt/msg00673.txt.bz2 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 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(): 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(): 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(): 20: 0f 2f c8 comiss %xmm0,%xmm1 23: 77 13 ja 38 25: f3 0f 10 05 00 00 00 movss 0x0(%rip),%xmm0 # 2d 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 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.