Skip to content

Easy Optimization Win With the LCC Rules

February 26, 2018

This is no big deal but i’m counting it as an easy win. I often see the compiler copying one register to another before doing something with it. I would hesitate to clean it up with the peephole optimizer because i couldn’t be sure there wasn’t some other usage of the second register further down the code – hence my interest in liveness analysis. I decided to have a hard look at one instance though and correcting it was trivial.

;void comparulator(unsigned long x,unsigned long y){
;	unsigned int ix=x;
	cpy2 R11,RL6 
	st2 R11,'O',sp,(16+1)
;void comparulator(unsigned long x,unsigned long y){
;	unsigned int ix=x; 
	st2 RL6,'O',sp,(16+1)

The instruction patterns in the machine description record (.MD file) tell the compiler what assembler instructions to emit for a given intermediate code sequence. In this case it was using a LOADU2 pattern to get a value into a register and an ASGNU2(addr,reg) to put it into storage. By giving it a combination of ASGNU2(addr,LOADU2(reg)) it happily skipped the intermediate move. I think I have tried some of these combinations in the past with less success but I’m encouraged this time.

reg: LOADU2(reg)  "?\tcpy2 R%c,R%0\n"  move(a)+10
stmt: ASGNU2(addr,reg)  "\tst2 R%1,%0\n"  10

stmt: ASGNU2(addr,LOADU2(reg))  "\tst2 R%1,%0\n"  10

(note that i’ve cleaned up the assembly code and rules a bit – the real thing is sprinkled with debugging and tracking comments.)

Here’s an instance where optimizing out a load would get me in trouble though:

	ldI4 RL10,-11 ;loading a long integer constant
	cpy4 Rp1p2,RL10; LOADI4*
	st4 RL10,'O',sp,(4+1); arg+f**
	Ccall _scomparulator

You could certainly do something with it but it’s an instance where a temporary is being reused for its value and it’s not something that’s generated by the rules – the line with the arg+f** tag at the end is generated by my c code in the function() procedure.


From → Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: