[LLVMdev] Register Pairing
Borja Ferrer
borja.ferav at gmail.com
Sun Dec 5 08:17:12 PST 2010
Hello Lang, thanks for the suggestion :) it's very interesting. I'll take a
read to the email you've pointed out there to understand how it works. Btw,
does this mean that only your allocator is able to handle or support this
type of constraint?
As a follow up to my previous email, the following code is a real example of
what i was explaining, Lang this example is exactly why i need the
constraints and how to combine instructions.
typedef short t;
extern t mcos(t a);
extern t mdiv(t a, t b);
t foo(t a, t b)
{
short p1 = mcos(b);
short p2 = mcos(a);
return mdiv(p1&p2, p1^p2);
}
This C code produces:
; a<- r25:r24 b<--r23:r22
mov r18, r24
mov r19, r25 <-- can be combined into a movw r19:r18, r25:r24
mov r25, r23
mov r24, r22 <-- can be combined into a movw r25:r24, r23:r22
call mcos
; here we have the case i was explaining, pairs dont match because they're
the other way round, function result is in r25:r24
; but it's storing the hi part in r20 instead of r21, so we cant insert a
movw
mov r20, r25
mov r21, r24 <--- should be mov r21, r25; mov r20, r24 to be able to
insert a movw
mov r25, r19
mov r24, r18 <-- can be combined into a movw r25:r24, r19:r18
call mcos
; same problem as above, again it's moving the hi part in r25 into r18
instead of r19 so we've lost another movw here
mov r18, r25 <-- should be mov r19, r25
and r18, r20
mov r19, r24 <-- should be mov r18, r24
and r19, r21
mov r23, r25 <-- this *
eor r23, r20
mov r22, r24 <-- * and this could be combined into movw r23:r22,
r25:r24
eor r22, r21
mov r25, r18
mov r24, r19 <-- because the result returned by the second call to
mcos is stored in r18:r19 (other way round)
; we've lost another movw
call mdiv
ret
As you can see there are three cases were we've lost the opportunity of
inserting a movw. This is a very important instruction because if we're able
to insert it everywhere it's possible we can reduce the code in 7
instructions and 7 cycles which is a huge gain. Ignoring these issues the
code produced is optimal. I hope this example make things more clearer.
Also, as i said in my previous email i wrote a function pass searching for 2
moves in a row and combining them into a movw since i dont know a better way
of combining machine instructions, however in this case it wouldnt work for
the second half of the program because there are "and" and "xor"
instructions in between the moves breaking the simple heuristic the function
pass has.
Thanks for the help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101205/4337dad7/attachment.html>
More information about the llvm-dev
mailing list