Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

thumb2 bit test optimization opportunity #14326

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR14305
Status NEW
Importance P enhancement
Reported by Brian G. Lucas (bagel99@gmail.com)
Reported on 2012-11-09 16:16:28 -0800
Last modified on 2012-11-09 20:28:02 -0800
Version trunk
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, pawel@32bitmicro.com
Fixed by commit(s)
Attachments bittest.ll (410 bytes, application/octet-stream)
Blocks
Blocked by
See also
Created attachment 9515
bit test example

This is a missing optimization for Thumb2 code.
A bit test on a dead variable is now done with a "tst.w reg,#bit", with
conditions EQ,NE.  It could be done with a "lsls reg,#shf" to shift the bit
into the sign bit, with conditions PL,MI.

The test program generates (on the trunk):

bittest:
    mov     r1, r0
    movs    r0, #0
    tst.w   r1, #128
    it          eq
    moveq   r0, #42
    bx      lr

It could generate, 2 bytes smaller:

bittest:
    mov     r1, r0
    movs    r0, #0
    lsls    r1, #24
    it          pl
    movpl   r0, #42
    bx      lr

Even better would be, 4 bytes smaller:

bittest:
    lsls    r0, #24
    ite     pl
    movpl   r0, #42
    movmi   r0, #0
    bx      lr
Quuxplusone commented 11 years ago

Attached bittest.ll (410 bytes, application/octet-stream): bit test example