Bug 45617 - optimize bit shift+compare at RTL level
Summary: optimize bit shift+compare at RTL level
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.6.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-09 17:48 UTC by Zdenek Sojka
Modified: 2010-09-13 21:10 UTC (History)
2 users (show)

See Also:
Host:
Target: x86(_64)-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Jakub's patch from PR20517 comment #6 (1.11 KB, patch)
2010-09-09 17:51 UTC, Zdenek Sojka
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2010-09-09 17:48:13 UTC
+++ This bug was initially created as a clone of Bug #20517 +++

From comment #4:

----- testcase.c -----
_Bool foo(unsigned i)
{
        return (i >> 5) > 10;
}

_Bool bar(unsigned i)
{
        return i > (10 << 5) + 31;
}

int fooi(unsigned i)
{
        return (i >> 5) > 10;
}

int bari(unsigned i)
{
        return i > (10 << 5) + 31;
}
----------------------

Compiled with:
$ gcc-4.6.0-pre9999 tst6.c -O3 -S -m32 -fomit-frame-pointer
(svn r162190)

Results in:
foo:
        movl    4(%esp), %eax
        shrl    $5, %eax
        cmpl    $10, %eax
        seta    %al
        ret
bar:
        cmpl    $351, 4(%esp)
        seta    %al
        ret
fooi:
        movl    4(%esp), %eax
        shrl    $5, %eax
        cmpl    $10, %eax
        seta    %al
        movzbl  %al, %eax
        ret
bari:
        xorl    %eax, %eax
        cmpl    $351, 4(%esp)
        seta    %al
        ret
Comment 1 Zdenek Sojka 2010-09-09 17:51:00 UTC
Created attachment 21756 [details]
Jakub's patch from PR20517 comment #6

gcc bootstrapped fine

The resulting code for foo() and fooi() is the same as for bar() and bari(), respectively.
Comment 2 Jakub Jelinek 2010-09-13 21:00:26 UTC
Subject: Bug 45617

Author: jakub
Date: Mon Sep 13 21:00:03 2010
New Revision: 164257

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164257
Log:
	PR rtl-optimization/45617
	* combine.c (simplify_comparison): Optimize (X >> N) {>,>=,<,<=} C
	even if low N bits of X aren't known to be zero.

	* gcc.target/i386/pr45617.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr45617.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Jakub Jelinek 2010-09-13 21:10:30 UTC
Committed.