This is an archive of the discontinued LLVM Phabricator instance.

[Mips] Fix for BBIT octeon instruction
ClosedPublic

Authored by spetrovic on Jul 13 2017, 8:41 AM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

spetrovic created this revision.Jul 13 2017, 8:41 AM
sdardis added inline comments.Jul 14 2017, 6:20 AM
lib/Target/Mips/MipsSEInstrInfo.cpp
454–457 ↗(On Diff #106433)

This looks incorrect. Shouldn't the opposite of bbit0 be bbit1?

spetrovic updated this revision to Diff 106872.Jul 17 2017, 8:00 AM
spetrovic marked an inline comment as done.
spetrovic added inline comments.
lib/Target/Mips/MipsSEInstrInfo.cpp
454–457 ↗(On Diff #106433)

Yes, my mistake.

sdardis accepted this revision.Jul 19 2017, 9:40 AM

LGTM with some test fixes. My inlined comment about adding not test for 'j' and dropping the regexes applies to all the changes after the comment.

test/CodeGen/Mips/octeon.ll
95–96 ↗(On Diff #106872)

You can drop the regexes for matching the basic block labels, as they're not matching anything.

96 ↗(On Diff #106872)

Add 'OCTEON-NOT: j'

This revision is now accepted and ready to land.Jul 19 2017, 9:40 AM
spetrovic updated this revision to Diff 108042.Jul 25 2017, 3:36 AM
spetrovic marked an inline comment as done.
spetrovic marked 2 inline comments as done.
This revision was automatically updated to reflect the committed changes.