This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CMP of the register to zero.


On Mon, Jun 8, 2009 at 11:54 AM, Valdimir Volynsky<vvv@ru.ru> wrote:
> Hi, all!
>
> Sometimes current trunk generate CMP of the register
> to zero, but better to use a TEST the register with itself.
> It's faster and shorter (at least for Intel CPU).
>
> # cat test.c
> int foo(int m)
> {
> if(m>0) {return(m);}
> if(m<0) {return(0);}
> }
>
> # gcc -o test test.c -c -O2
> # objdump -d test
>
> 0000000000000000 <foo>:
> ? 0: ? 83 ff 00 ? ? ? ? ? ? ? ?cmp ? ?$0x0,%edi ? <----
> ? 3: ? 7e 0b ? ? ? ? ? ? ? ? ? jle ? ?10 <int_int+0x10>
> ? 5: ? 89 f8 ? ? ? ? ? ? ? ? ? mov ? ?%edi,%eax
> ? 7: ? c3 ? ? ? ? ? ? ? ? ? ? ?retq
> ? 8: ? 0f 1f 84 00 00 00 00 ? ?nopl ? 0x0(%rax,%rax,1)
> ? f: ? 00
> ?10: ? 75 06 ? ? ? ? ? ? ? ? ? jne ? ?18 <int_int+0x18>
> ?12: ? f3 c3 ? ? ? ? ? ? ? ? ? repz retq
> ?14: ? 0f 1f 40 00 ? ? ? ? ? ? nopl ? 0x0(%rax)
> ?18: ? 31 ff ? ? ? ? ? ? ? ? ? xor ? ?%edi,%edi
> ?1a: ? eb e9 ? ? ? ? ? ? ? ? ? jmp ? ?5 <int_int+0x5>
>
> Two questions:
> What is the best place for patch?
> What about non Intel CPU?
>

Since gcc generares cmp RTL with full CC FLAGS, we can't use test.

-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]