From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26334 invoked by alias); 25 Apr 2012 14:21:29 -0000 Received: (qmail 26323 invoked by uid 22791); 25 Apr 2012 14:21:28 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_JN X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Apr 2012 14:21:15 +0000 From: "vermaelen.wouter at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' Date: Wed, 25 Apr 2012 14:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: vermaelen.wouter at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-04/txt/msg02256.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53117 Bug #: 53117 Summary: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: rtl-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: vermaelen.wouter@gmail.com void f1(int* p) { p[1] -= 5; if (p[1] < 0) p[2] += 3; } void f2(int* p) { p[1] -= 5; if (p[1] <= 0) p[2] += 3; } The only difference between f1() and f2() is the comparison ('<' vs '<='). On x86_64 (and x86) gcc revision trunk@186808 generates more efficient code for f1() than for f2(). Here's the assembler output when compiled with -Os (but -O2 and -O3) show a similar difference: 0000000000000000 <_Z2f1Pi>: 0: 83 6f 04 05 subl $0x5,0x4(%rdi) 4: 79 04 jns a <_Z2f1Pi+0xa> 6: 83 47 08 03 addl $0x3,0x8(%rdi) a: c3 retq 000000000000000b <_Z2f2Pi>: b: 8b 47 04 mov 0x4(%rdi),%eax e: 83 e8 05 sub $0x5,%eax 11: 85 c0 test %eax,%eax 13: 89 47 04 mov %eax,0x4(%rdi) 16: 7f 04 jg 1c <_Z2f2Pi+0x11> 18: 83 47 08 03 addl $0x3,0x8(%rdi) 1c: c3 retq gcc-4.6.1 generates the less efficient variant for both functions.