Index: llvm/lib/Target/AVR/AVRInstrInfo.td =================================================================== --- llvm/lib/Target/AVR/AVRInstrInfo.td +++ llvm/lib/Target/AVR/AVRInstrInfo.td @@ -213,7 +213,7 @@ def imm16 : Operand { let EncoderMethod = "encodeImm"; } // A 7-bit address (which can lead to an R_AVR_LDS_STS_16 relocation). -def imm7tiny : Operand { +def imm7tiny : Operand { let EncoderMethod = "encodeImm"; } @@ -1295,7 +1295,8 @@ // Load from data space into register, which is only available on AVRTiny. def LDSRdKTiny : FLDSSTSTINY<0b0, (outs LD8:$rd), (ins imm7tiny:$k), - "lds\t$rd, $k", []>, + "lds\t$rd, $k", + [(set i8:$rd, (load imm:$k))]>, Requires<[HasSRAM, HasTinyEncoding]>; // LDSW Rd+1:Rd, K+1:K @@ -1509,7 +1510,7 @@ // Store from register to data space, which is only available on AVRTiny. def STSKRrTiny : FLDSSTSTINY<0b1, (outs), (ins imm7tiny:$k, LD8:$rd), - "sts\t$k, $rd", []>, + "sts\t$k, $rd", [(store i8:$rd, imm:$k)]>, Requires<[HasSRAM, HasTinyEncoding]>; // STSW K+1:K, Rr+1:Rr @@ -2499,20 +2500,28 @@ (SUBIWRdK i16 : $src, tglobaladdr : $src2)>; +let Predicates = [HasNonTinyEncoding] in def : Pat<(i8(load(AVRWrapper tglobaladdr : $dst))), (LDSRdK tglobaladdr : $dst)>; +let Predicates = [HasTinyEncoding] in +def : Pat<(i8(load(AVRWrapper tglobaladdr:$dst))), + (LDSRdKTiny tglobaladdr:$dst)>; def : Pat<(i16(load(AVRWrapper tglobaladdr : $dst))), (LDSWRdK tglobaladdr : $dst)>; +let Predicates = [HasNonTinyEncoding] in def : Pat<(store i8 : $src, (i16(AVRWrapper tglobaladdr : $dst))), (STSKRr tglobaladdr : $dst, i8 : $src)>; +let Predicates = [HasTinyEncoding] in +def : Pat<(store i8:$src, (i16(AVRWrapper tglobaladdr:$dst))), + (STSKRrTiny tglobaladdr:$dst, i8:$src)>; def : Pat<(store i16 : $src, (i16(AVRWrapper tglobaladdr : $dst))), Index: llvm/test/CodeGen/AVR/directmem.ll =================================================================== --- llvm/test/CodeGen/AVR/directmem.ll +++ llvm/test/CodeGen/AVR/directmem.ll @@ -1,4 +1,6 @@ ; RUN: llc -mattr=sram,addsubiw < %s -march=avr | FileCheck %s +; RUN: llc -mattr=sram,addsubiw,tinyencoding < %s -march=avr +; | FileCheck --check-prefix=TINY @char = common global i8 0 @char.array = common global [3 x i8] zeroinitializer @@ -20,6 +22,10 @@ ; CHECK-LABEL: global8_store: ; CHECK: ldi [[REG:r[0-9]+]], 6 ; CHECK: sts char, [[REG]] +; +; TINY-LABEL: global8_store: +; TINY: ldi [[REG:r[0-9]+]], 6 +; TINY: sts char, [[REG]] store i8 6, i8* @char ret void } @@ -27,6 +33,9 @@ define i8 @global8_load() { ; CHECK-LABEL: global8_load: ; CHECK: lds r24, char +; +; TINY-LABEL: global8_load: +; TINY: lds r24, char %result = load i8, i8* @char ret i8 %result } @@ -39,6 +48,14 @@ ; CHECK: ldi [[REG2:r[0-9]+]], 2 ; CHECK: sts char.array+1, [[REG2]] ; CHECK: sts char.array, [[REG3]] +; +; TINY-LABEL: array8_store: +; TINY: ldi [[REG1:r[0-9]+]], 3 +; TINY: sts char.array+2, [[REG1]] +; TINY: ldi [[REG3:r[0-9]+]], 1 +; TINY: ldi [[REG2:r[0-9]+]], 2 +; TINY: sts char.array+1, [[REG2]] +; TINY: sts char.array, [[REG3]] store i8 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @char.array, i32 0, i64 0) store i8 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @char.array, i32 0, i64 1) store i8 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @char.array, i32 0, i64 2) @@ -48,6 +65,9 @@ define i8 @array8_load() { ; CHECK-LABEL: array8_load: ; CHECK: lds r24, char.array+2 +; +; TINY-LABEL: array8_load: +; TINY: lds r24, char.array+2 %result = load i8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @char.array, i32 0, i64 2) ret i8 %result } @@ -57,6 +77,11 @@ ; CHECK: lds r24, char.static ; CHECK: inc r24 ; CHECK: sts char.static, r24 +; +; TINY-LABEL: static8_inc: +; TINY: lds r24, char.static +; TINY: inc r24 +; TINY: sts char.static, r24 %1 = load i8, i8* @char.static %inc = add nsw i8 %1, 1 store i8 %inc, i8* @char.static