Skip to content

Commit 681e652

Browse files
committed
[MSP430] Print add x,x as rla x
1 parent 1ce6b1d commit 681e652

5 files changed

Lines changed: 47 additions & 10 deletions

File tree

src/llvm/lib/Target/MSP430/InstPrinter/MSP430InstPrinter.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,47 @@ using namespace llvm;
2727
#define PRINT_ALIAS_INSTR
2828
#include "MSP430GenAsmWriter.inc"
2929

30+
static bool isRLAmInstruction(const MCInst *MI) {
31+
// add x,x == rla x
32+
unsigned Opc = MI->getOpcode();
33+
if (Opc != MSP430::ADD8mm && Opc != MSP430::ADD16mm &&
34+
Opc != MSP430::ADDC8mm && Opc != MSP430::ADDC16mm)
35+
return false;
36+
37+
// Check operands pairs are equal
38+
const MCOperand &Op1 = MI->getOperand(0);
39+
const MCOperand &Op2 = MI->getOperand(1);
40+
const MCOperand &Op3 = MI->getOperand(2);
41+
const MCOperand &Op4 = MI->getOperand(3);
42+
43+
if (Op1.isReg() && Op3.isReg() && Op1.getReg() == Op3.getReg() &&
44+
Op2.isImm() && Op4.isImm() && Op2.getImm() == Op4.getImm())
45+
return true;
46+
// TODO: Is it possible to check if two MCExpr are equal?
47+
return false;
48+
}
49+
3050
void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
3151
StringRef Annot, const MCSubtargetInfo &STI) {
52+
// Print add x,x -> rla x (only mm case here, rr is handled by tablegen)
53+
// TODO: Is it possible to resolve this by tablegen as well?
54+
if (isRLAmInstruction(MI)) {
55+
switch (MI->getOpcode()) {
56+
case MSP430::ADD8mm: O << "\trla.b\t"; break;
57+
case MSP430::ADD16mm: O << "\trla\t"; break;
58+
case MSP430::ADDC8mm: O << "\trlc.b\t"; break;
59+
case MSP430::ADDC16mm: O << "\trlc\t"; break;
60+
default:
61+
llvm_unreachable("Unexpected instruction");
62+
}
63+
printSrcMemOperand(MI, 0, O);
64+
printAnnotation(O, Annot);
65+
return;
66+
}
67+
3268
if (!printAliasInstr(MI, O))
3369
printInstruction(MI, O);
70+
3471
printAnnotation(O, Annot);
3572
}
3673

src/llvm/lib/Target/MSP430/MSP430InstrInfo.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,16 +586,16 @@ def INV16r : InstAlias<"inv\t$dst", (XOR16rc GR16:$dst, -1)>;
586586
def INV8m : InstAlias<"inv.b\t$dst", (XOR8mc memdst:$dst, -1)>;
587587
def INV16m : InstAlias<"inv\t$dst", (XOR16mc memdst:$dst, -1)>;
588588

589-
// printAliasInstr() doesn't check $dst operands are actually equal
589+
// printAliasInstr() doesn't check non-register operands are actually equal
590590
// for RLA and RLC aliases below, so disable printing aliases.
591591

592-
def RLA8r : InstAlias<"rla.b\t$dst", (ADD8rr GR8:$dst, GR8:$dst), 0>;
593-
def RLA16r : InstAlias<"rla\t$dst", (ADD16rr GR16:$dst, GR16:$dst), 0>;
592+
def RLA8r : InstAlias<"rla.b\t$dst", (ADD8rr GR8:$dst, GR8:$dst), 1>;
593+
def RLA16r : InstAlias<"rla\t$dst", (ADD16rr GR16:$dst, GR16:$dst), 1>;
594594
def RLA8m : InstAlias<"rla.b\t$dst", (ADD8mm memdst:$dst, memdst:$dst), 0>;
595595
def RLA16m : InstAlias<"rla\t$dst", (ADD16mm memdst:$dst, memdst:$dst), 0>;
596596

597-
def RLC8r : InstAlias<"rlc.b\t$dst", (ADDC8rr GR8:$dst, GR8:$dst), 0>;
598-
def RLC16r : InstAlias<"rlc\t$dst", (ADDC16rr GR16:$dst, GR16:$dst), 0>;
597+
def RLC8r : InstAlias<"rlc.b\t$dst", (ADDC8rr GR8:$dst, GR8:$dst), 1>;
598+
def RLC16r : InstAlias<"rlc\t$dst", (ADDC16rr GR16:$dst, GR16:$dst), 1>;
599599
def RLC8m : InstAlias<"rlc.b\t$dst", (ADDC8mm memdst:$dst, memdst:$dst), 0>;
600600
def RLC16m : InstAlias<"rlc\t$dst", (ADDC16mm memdst:$dst, memdst:$dst), 0>;
601601

src/llvm/test/CodeGen/MSP430/jumptable.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ entry:
1515
%i.addr = alloca i16, align 2
1616
store i16 %i, i16* %i.addr, align 2
1717
%0 = load i16, i16* %i.addr, align 2
18-
; CHECK: add r12, r12
18+
; CHECK: rla r12
1919
; CHECK-NEXT: br .LJTI0_0(r12)
2020
switch i16 %0, label %sw.default [
2121
i16 0, label %sw.bb

src/llvm/test/CodeGen/MSP430/shifts.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ entry:
2222
define zeroext i8 @shl8(i8 zeroext %a, i8 zeroext %cnt) nounwind readnone {
2323
entry:
2424
; CHECK: shl8
25-
; CHECK: add.b
25+
; CHECK: rla.b
2626
%shl = shl i8 %a, %cnt
2727
ret i8 %shl
2828
}
@@ -47,7 +47,7 @@ entry:
4747
define zeroext i16 @shl16(i16 zeroext %a, i16 zeroext %cnt) nounwind readnone {
4848
entry:
4949
; CHECK-LABEL: shl16:
50-
; CHECK: add
50+
; CHECK: rla
5151
%shl = shl i16 %a, %cnt
5252
ret i16 %shl
5353
}

src/llvm/test/MC/MSP430/opcode.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
;; Emulated logical instructions
126126
inv r7 ; CHECK-INST: inv r7
127127
; CHECK: encoding: [0x37,0xe3]
128-
rla r7 ; CHECK-INST: add r7, r7
128+
rla r7 ; CHECK-INST: rla r7
129129
; CHECK: encoding: [0x07,0x57]
130-
rlc r7 ; CHECK-INST: addc r7, r7
130+
rlc r7 ; CHECK-INST: rlc r7
131131
; CHECK: encoding: [0x07,0x67]
132132

133133
;; Emulated program flow control instructions

0 commit comments

Comments
 (0)