new port/wrong compilation of a mult with small values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am working on a new port for GCC.

Generally, assembly generated by target-gcc is alright. But I am
facing a problem:

source : toto.c
___________________________________________
void toto (int a)
{
 a *= 10;
}
___________________________________________

assembly generated:
[prologue]
 move  a,r0   ; R0 = a
 add r0,r0      ; R0 = 2 * a
 rla r0           ; R0 = 4 * a
 rla r0           ; R0 = 8 * a
 move  r0,r1  ; R1 = R0 = 8 * a
 move  r0,r2  ; R2 = R1 = R0 = 8 * a
 add r1,r2     ; R2 = 16 * a
 move  r2,a   ; a *= 16
[epilogue]

So target-gcc computes a *= 16 instead of a *= 10. The result would be
right if the instruction "move  r0,r1" were placed just after "add
r0,r0".
I tried with other values, sometimes the result is right and sometimes
it is wrong.

Here is the dump of the expand:
;; Function toto (toto)


;; Generating RTL for tree basic block 2

;; a = a * 10
(insn 5 4 6 toto.c:4 (set (reg:HI 13)
        (mem/c/i:HI (reg/f:HI 8 virtual-incoming-args) [0 a+0 S2
A16])) -1 (nil))

(insn 6 5 7 toto.c:4 (set (reg:HI 14)
        (reg:HI 13)) -1 (nil))

(insn 7 6 8 toto.c:4 (set (reg:HI 15)
        (plus:HI (reg:HI 14)
            (reg:HI 14))) -1 (expr_list:REG_EQUAL (mult:HI (reg:HI 13)
            (const_int 2 [0x2]))
        (nil)))

(insn 8 7 9 toto.c:4 (set:HI (reg:HI 15)
        (ashift:HI (reg:HI 15)
            (const_int 1 [0x1]))) -1 (nil))

(insn 9 8 10 toto.c:4 (set:HI (reg:HI 15)
        (ashift:HI (reg:HI 15)
            (const_int 1 [0x1]))) -1 (nil))

(insn 10 9 11 toto.c:4 (set (reg:HI 16)
        (reg:HI 15)) -1 (expr_list:REG_EQUAL (ashift:HI (reg:HI 15)
            (const_int 2 [0x2]))
        (nil)))

(insn 11 10 0 toto.c:4 (set (mem/c/i:HI (reg/f:HI 8
virtual-incoming-args) [0 a+0 S2 A16])
        (plus:HI (reg:HI 15)
            (reg:HI 16))) -1 (expr_list:REG_EQUAL (mult:HI (reg:HI 13)
            (const_int 10 [0xa]))
        (nil)))


For me, it does not give a clue.

Has someone an idea ?
Thanks.

Regards.

Florent


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux