------- Comment #1 from ubizjak at gmail dot com  2008-06-09 11:39 -------
Created an attachment (id=15741)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15741&action=view)
Proposed patch

Following code:

--cut here--
void foo (void);

int test (int x, int n)
{
  if (x & (1 << n))
    foo ();

  return 0;
}
--cut here--

compiles using -O2 to:

test:
        subl    $12, %esp
        movl    16(%esp), %eax
        movl    20(%esp), %ecx
        sarl    %cl, %eax
        testb   $1, %al
        je      .L2
        call    foo
.L2:
        xorl    %eax, %eax
        addl    $12, %esp
        ret

With attached patch, following code is produced:

test:
        subl    $12, %esp
        movl    20(%esp), %edx
        movl    16(%esp), %eax
        btl     %edx, %eax
        jnc     .L2
        call    foo
.L2:
        xorl    %eax, %eax
        addl    $12, %esp
        ret

Attached patch doesn't have TARGET_USE_BT insn predicates, and it generates bt
instructions by default. It was used to bootstrap gcc on i686-pc-linux-gnu,
where it converts >1800 shift-and-test sequences into eqivalent bt instruction.

The patch as is was bootstrapped and regression tested on x86_64-pc-linux-gnu
as well as i686-pc-linux-gnu.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36473

Reply via email to