This repository was archived by the owner on Sep 2, 2018. It is now read-only.
This repository was archived by the owner on Sep 2, 2018. It is now read-only.
mul instruction is generated on ATtiny, even though it is not supported #216
Open
Description
Example code:
#include <avr/io.h>
void test(uint8_t *ptr, uint16_t index) {
ptr[index+index+index]=7;
}
Interestingly LLVM infers a multiplication from the triple addition. This may be beneficial on some architectures, but certainly is not so on AVR.
To make things worse, very inefficient code with 8x single bit shift and multiplications is generated even on the ATtiny, where it is not supported.
The same code is generated for ATmega, ATtiny, and the tiny core:
.text
.file "test2.c"
.globl test
.p2align 1
.type test,@function
test: ; @test
; BB#0: ; %entry
ldi r18, 3
muls r23, r18
mov r19, r0
eor r1, r1
mul r22, r18
mov r20, r1
eor r1, r1
add r20, r19
lsl r20
rol r21
lsl r20
rol r21
lsl r20
rol r21
lsl r20
rol r21
lsl r20
rol r21
lsl r20
rol r21
lsl r20
rol r21
lsl r20
rol r21
mov r26, r0
eor r27, r27
or r26, r20
or r27, r21
add r26, r24
adc r27, r25
ldi r24, 7
st X, r24
ret
.Lfunc_end0:
.size test, .Lfunc_end0-test