This patch enables control flow optimization for variations of BBIT instruction. In this case optimization removes unnecessary branch after BBIT instruction.
Example:
void foo(long long var) {
if ((var) & 0x2) { printf("\ntest"); }
}
Without patch:
0000000000000000 <foo>:
0: 67bdfff0 daddiu sp,sp,-16 4: ffbf0008 sd ra,8(sp) 8: ffbc0000 sd gp,0(sp) c: 3c010000 lui at,0x0 10: c881000b bbit0 a0,0x1,40 <foo+0x40> 14: 0039102d daddu v0,at,t9 18: 10000001 b 20 <foo+0x20> 1c: 00000000 nop 20: 645c0000 daddiu gp,v0,0 24: df810000 ld at,0(gp) 28: 64240000 daddiu a0,at,0 2c: 3c010000 lui at,0x0 30: 003c082d daddu at,at,gp 34: dc390000 ld t9,0(at) 38: 0320f809 jalr t9 3c: 00000000 nop 40: dfbc0000 ld gp,0(sp) 44: dfbf0008 ld ra,8(sp) 48: 03e00008 jr ra 4c: 67bd0010 daddiu sp,sp,16
With the patch:
0000000000000000 <foo>:
0: 67bdfff0 daddiu sp,sp,-16 4: ffbf0008 sd ra,8(sp) 8: ffbc0000 sd gp,0(sp) c: 3c010000 lui at,0x0 10: c8810009 bbit0 a0,0x1,38 <foo+0x38> 14: 0039102d daddu v0,at,t9 18: 645c0000 daddiu gp,v0,0 1c: df810000 ld at,0(gp) 20: 64240000 daddiu a0,at,0 24: 3c010000 lui at,0x0 28: 003c082d daddu at,at,gp 2c: dc390000 ld t9,0(at) 30: 0320f809 jalr t9 34: 00000000 nop 38: dfbc0000 ld gp,0(sp) 3c: dfbf0008 ld ra,8(sp) 40: 03e00008 jr ra 44: 67bd0010 daddiu sp,sp,16
This looks incorrect. Shouldn't the opposite of bbit0 be bbit1?