<div>I'm bringing up this email in case it wasn't noticed or got lost in the depth of the mailing list. Please let me know if this issue requires openning a bug report or if it can be handled in another way.</div>
<div> </div>
<div>Thanks and congrats for the the new release!<br><br></div>
<div class="gmail_quote">2010/9/21 Borja Ferrer <span dir="ltr"><<a href="mailto:borja.ferav@gmail.com">borja.ferav@gmail.com</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Hello, I noticed that the following code could be improved a little bit further. If the optimization is too tricky for the compiler or something and it's done this way by design forgive me, but in any case i just wanted to point it out.<br>
<br>Consider the following C code:<br><br>extern int mcos(int a);<br>extern int msin(int a);<br>extern int mdiv(int a, int b);<br><br>int foo(int a, int b)<br>{<br>    int a4 = mdiv(mcos(a), msin(b));<br>    return a4;<br>
}<br><br>I noticed this while testing it for the backend i'm currently developing, but it produces exactly the same code for other targets:<br><br>march = msp430:<br>    push.w    r11<br>    push.w    r10<br>    push.w    r9<br>
    push.w    r8<br>    mov.w    r14, r11<br>    mov.w    r15, r10   ; store a<br>    mov.w    r13, r15<br>    mov.w    r12, r14   ; pass b<br>    call    #msin<br>    mov.w    r15, r9<br>    mov.w    r14, r8   ; store msin(b)<br>
    mov.w    r10, r15<br>    mov.w    r11, r14 ; pass a<br>    call    #mcos<br>    mov.w    r9, r13   ;  pass msin(b)<br>    mov.w    r8, r12<br>    call    #mdiv<br>    pop.w    r8<br>    pop.w    r9<br>    pop.w    r10<br>
    pop.w    r11<br>    ret<br><br>march = thumb<br>    push    {r4, r5, lr}<br>    mov    r4, r0<br>    mov    r0, r1<br>    bl    msin<br>    mov    r5, r0<br>    mov    r0, r4<br>    bl    mcos<br>    mov    r1, r5<br>
    bl    mdiv<br>    pop    {r4, r5, pc}<br><br>Using the MSP430 example above, it could have produced:<br><br>    push.w    r11<br>    push.w    r10<br>    mov.w    r14, r11<br>    mov.w    r15, r10   ; store a<br>    mov.w    r13, r15<br>
    mov.w    r12, r14   ; pass b<br>    call    #msin<br>   ; SWAP MSIN(B) AND ARGUMENT "a" USING R13:R12<br>    mov.w    r15, r13<br>    mov.w    r14, r12  : store msin(b)<br>    mov.w    r11, r14<br>    mov.w    r10, r15 ;  pass a<br>
    mov.w    r13, r11<br>    mov.w    r12, r10  ; save msin(b) into callee saved regs<br>    call    #mcos<br>    mov.w    r11, r13   ;  pass msin(b)<br>    mov.w    r10, r12<br>    call    #mdiv<br>    pop.w    r10<br>    pop.w    r11<br>
    ret<br><br>The basic explanation is that r13:r12 could be used as scratch registers after msin() is called to swap the result of msin(b) with the argument a. This saves pushing and popping r9 and r8, at the cost of using two extra moves, saving in total 2 instructions but saving 4 memory acceses.<br>
In the case of my backend which is targetted for an 8bit arch but supports 16bit moves it saves pushing and popping four 8bit regs which means saving 6 instructions, or in other words 8 memory accesses. In terms of speed it saves 14 cycles (2 cycles per push/pop).<br>
<br>As a side note GCC produces this same code.<br><br>Thanks.<br></blockquote></div><br>