From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27100 invoked by alias); 5 Sep 2012 13:05:50 -0000 Received: (qmail 27085 invoked by uid 22791); 5 Sep 2012 13:05:49 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_OV 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, 05 Sep 2012 13:05:36 +0000 From: "neleai at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/54491] New: interval membership optimization Date: Wed, 05 Sep 2012 13:05: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: neleai at seznam dot cz 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-09/txt/msg00363.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54491 Bug #: 54491 Summary: interval membership optimization Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: neleai@seznam.cz A common optimization to test range membership b \in [c,d] is to use integer overflow as in function range below. gcc does this optimization when both c and d are constants. However inlining disables this optimization. Same optimization can be automatically applied for c arbitrary expression and d=c+positive_constant unsigned int range(unsigned int b,unsigned int c){ if (b-c<=42) return c; return b; } unsigned int foo(unsigned int b,unsigned int c){ if (c<=b && b <=42+c) return c; return b; } unsigned int bar(unsigned int b){ return foo(b,42); } unsigned int baz(unsigned int b){ if (42<=b && b<=84) return 42; return b; } .file "a.c" .text .p2align 4,,15 .globl range .type range, @function range: .LFB0: .cfi_startproc movl %edi, %eax subl %esi, %eax cmpl $42, %eax movl %esi, %eax cmova %edi, %eax ret .cfi_endproc .LFE0: .size range, .-range .p2align 4,,15 .globl foo .type foo, @function foo: .LFB1: .cfi_startproc cmpl %edi, %esi movl %edi, %eax ja .L5 leal 42(%rsi), %edx cmpl %edx, %edi cmovbe %esi, %eax .L5: rep; ret .cfi_endproc .LFE1: .size foo, .-foo .p2align 4,,15 .globl bar .type bar, @function bar: .LFB2: .cfi_startproc cmpl $41, %edi movl %edi, %eax jbe .L10 cmpl $85, %edi movl $42, %edx cmovb %edx, %eax .L10: rep; ret .cfi_endproc .LFE2: .size bar, .-bar .p2align 4,,15 .globl baz .type baz, @function baz: .LFB3: .cfi_startproc leal -42(%rdi), %edx movl $42, %eax cmpl $42, %edx cmova %edi, %eax ret .cfi_endproc .LFE3: .size baz, .-baz .ident "GCC: (Debian 20120820-1) 4.8.0 20120820 (experimental) [trunk revision 190537]" .section .note.GNU-stack,"",@progbits