Skip to content

Commit a5424de

Browse files
committed
[AVR] Use correct register class for mul instructions
A number of multiplication instructions (muls, mulsu, fmul, fmuls, fmulsu) had the wrong register class for an operand. This resulted in the wrong register being used for the instruction. Example: target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8" target triple = "avr-atmel-none" define i16 @sliceAppend(i16, i16, i16, i16, i16, i16) addrspace(1) { %d = mul i16 %0, %5 ret i16 %d } The first instruction would be muls r24, r31 before this patch. The r31 should have been r15 if you look at the intermediate forms during instruction selection / register allocation, but the generated instruction uses r31. After this patch, an extra movw is inserted to get %5 in range for muls. To make sure this bug is fixed everywhere, I checked all instructions and found that most multiplication instructions suffered from this bug, which I have fixed with this patch. No other instructions appear to be affected. Differential Revision: https://reviews.llvm.org/D74281
1 parent bee70bf commit a5424de

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

llvm/lib/Target/AVR/AVRInstrInfo.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,36 +555,36 @@ Defs = [R1, R0, SREG] in
555555

556556
def MULSRdRr : FMUL2RdRr<0,
557557
(outs),
558-
(ins GPR8:$lhs, GPR8:$rhs),
558+
(ins LD8:$lhs, LD8:$rhs),
559559
"muls\t$lhs, $rhs",
560560
[]>,
561561
Requires<[SupportsMultiplication]>;
562562
}
563563

564564
def MULSURdRr : FMUL2RdRr<1,
565565
(outs),
566-
(ins GPR8:$lhs, GPR8:$rhs),
566+
(ins LD8lo:$lhs, LD8lo:$rhs),
567567
"mulsu\t$lhs, $rhs",
568568
[]>,
569569
Requires<[SupportsMultiplication]>;
570570

571571
def FMUL : FFMULRdRr<0b01,
572572
(outs),
573-
(ins GPR8:$lhs, GPR8:$rhs),
573+
(ins LD8lo:$lhs, LD8lo:$rhs),
574574
"fmul\t$lhs, $rhs",
575575
[]>,
576576
Requires<[SupportsMultiplication]>;
577577

578578
def FMULS : FFMULRdRr<0b10,
579579
(outs),
580-
(ins GPR8:$lhs, GPR8:$rhs),
580+
(ins LD8lo:$lhs, LD8lo:$rhs),
581581
"fmuls\t$lhs, $rhs",
582582
[]>,
583583
Requires<[SupportsMultiplication]>;
584584

585585
def FMULSU : FFMULRdRr<0b11,
586586
(outs),
587-
(ins GPR8:$lhs, GPR8:$rhs),
587+
(ins LD8lo:$lhs, LD8lo:$rhs),
588588
"fmulsu\t$lhs, $rhs",
589589
[]>,
590590
Requires<[SupportsMultiplication]>;

0 commit comments

Comments
 (0)