[llvm] 3730f13 - [AVR] Fix a bug in AsmPrinter when printing memory operands.
Ben Shi via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 22 17:42:50 PST 2022
Author: Ben Shi
Date: 2022-12-23T09:42:29+08:00
New Revision: 3730f134281375671a5eeeecec42eabe901c2379
URL: https://github.com/llvm/llvm-project/commit/3730f134281375671a5eeeecec42eabe901c2379
DIFF: https://github.com/llvm/llvm-project/commit/3730f134281375671a5eeeecec42eabe901c2379.diff
LOG: [AVR] Fix a bug in AsmPrinter when printing memory operands.
Reviewed By: aykevl
Differential Revision: https://reviews.llvm.org/D140383
Added:
llvm/test/CodeGen/AVR/inline-asm/loadstore.ll
Modified:
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
index 70fc90bf9eb5e..9128674ff4899 100644
--- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -161,10 +161,12 @@ bool AVRAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
// for registers.
if (MI->getOperand(OpNum).getReg() == AVR::R31R30) {
O << "Z";
- } else {
- assert(MI->getOperand(OpNum).getReg() == AVR::R29R28 &&
- "Wrong register class for memory operand.");
+ } else if (MI->getOperand(OpNum).getReg() == AVR::R29R28) {
O << "Y";
+ } else if (MI->getOperand(OpNum).getReg() == AVR::R27R26) {
+ O << "X";
+ } else {
+ assert(false && "Wrong register class for memory operand.");
}
// If NumOpRegs == 2, then we assume it is product of a FrameIndex expansion
@@ -173,6 +175,8 @@ bool AVRAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
unsigned NumOpRegs = InlineAsm::getNumOperandRegisters(OpFlags);
if (NumOpRegs == 2) {
+ assert(MI->getOperand(OpNum).getReg() != AVR::R27R26 &&
+ "Base register X can not have offset/displacement.");
O << '+' << MI->getOperand(OpNum + 1).getImm();
}
diff --git a/llvm/test/CodeGen/AVR/inline-asm/loadstore.ll b/llvm/test/CodeGen/AVR/inline-asm/loadstore.ll
new file mode 100644
index 0000000000000..9ec0906826c60
--- /dev/null
+++ b/llvm/test/CodeGen/AVR/inline-asm/loadstore.ll
@@ -0,0 +1,88 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=avr | FileCheck %s
+
+define i8 @loadx(i8* %0) {
+; CHECK-LABEL: loadx:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: mov r26, r24
+; CHECK-NEXT: mov r27, r25
+; CHECK-NEXT: ;APP
+; CHECK-NEXT: ld r24, X
+; CHECK-NEXT: ;NO_APP
+; CHECK-NEXT: ret
+ %2 = tail call i8 asm sideeffect "ld $0, ${1:a}", "=r,x"(i8* %0)
+ ret i8 %2
+}
+
+define i8 @loady(i8* %0) {
+; CHECK-LABEL: loady:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: push r28
+; CHECK-NEXT: push r29
+; CHECK-NEXT: mov r28, r24
+; CHECK-NEXT: mov r29, r25
+; CHECK-NEXT: ;APP
+; CHECK-NEXT: ld r24, Y
+; CHECK-NEXT: ;NO_APP
+; CHECK-NEXT: pop r29
+; CHECK-NEXT: pop r28
+; CHECK-NEXT: ret
+ %2 = tail call i8 asm sideeffect "ld $0, ${1:a}", "=r,y"(i8* %0)
+ ret i8 %2
+}
+
+define i8 @loadz(i8* %0) {
+; CHECK-LABEL: loadz:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: mov r30, r24
+; CHECK-NEXT: mov r31, r25
+; CHECK-NEXT: ;APP
+; CHECK-NEXT: ld r24, Z
+; CHECK-NEXT: ;NO_APP
+; CHECK-NEXT: ret
+ %2 = tail call i8 asm sideeffect "ld $0, ${1:a}", "=r,z"(i8* %0)
+ ret i8 %2
+}
+
+define void @storex(i8* %0, i8 %1) {
+; CHECK-LABEL: storex:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: mov r26, r24
+; CHECK-NEXT: mov r27, r25
+; CHECK-NEXT: ;APP
+; CHECK-NEXT: st X, r22
+; CHECK-NEXT: ;NO_APP
+; CHECK-NEXT: ret
+ tail call void asm sideeffect "st ${0:a}, $1", "x,r"(i8* %0, i8 %1)
+ ret void
+}
+
+define void @storey(i8* %0, i8 %1) {
+; CHECK-LABEL: storey:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: push r28
+; CHECK-NEXT: push r29
+; CHECK-NEXT: mov r28, r24
+; CHECK-NEXT: mov r29, r25
+; CHECK-NEXT: ;APP
+; CHECK-NEXT: st Y, r22
+; CHECK-NEXT: ;NO_APP
+; CHECK-NEXT: pop r29
+; CHECK-NEXT: pop r28
+; CHECK-NEXT: ret
+ tail call void asm sideeffect "st ${0:a}, $1", "y,r"(i8* %0, i8 %1)
+ ret void
+}
+
+define void @storez(i8* %0, i8 %1) {
+; CHECK-LABEL: storez:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: mov r30, r24
+; CHECK-NEXT: mov r31, r25
+; CHECK-NEXT: ;APP
+; CHECK-NEXT: st Z, r22
+; CHECK-NEXT: ;NO_APP
+; CHECK-NEXT: ret
+ tail call void asm sideeffect "st ${0:a}, $1", "z,r"(i8* %0, i8 %1)
+ ret void
+}
More information about the llvm-commits
mailing list