Skip to content

Commit 03f9c01

Browse files
committedJul 14, 2015
[mips] Fix li/la differences between IAS and GAS.
Summary: - Signed 16-bit should have priority over unsigned. - For la, unsigned 16-bit must use ori+addu rather than directly use ori. - Correct tests on 32-bit immediates with 64-bit predicates by sign-extending the immediate beforehand. For example, isInt<16>(0xffff8000) should be true and use addiu. Also split li/la testing into separate files due to their size. Reviewers: vkalintiris Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10967 llvm-svn: 242139
1 parent ea40cee commit 03f9c01

File tree

9 files changed

+464
-168
lines changed

9 files changed

+464
-168
lines changed
 

‎llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

+83-82
Original file line numberDiff line numberDiff line change
@@ -1727,37 +1727,59 @@ bool MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
17271727
}
17281728

17291729
namespace {
1730+
void emitRX(unsigned Opcode, unsigned DstReg, MCOperand Imm, SMLoc IDLoc,
1731+
SmallVectorImpl<MCInst> &Instructions) {
1732+
MCInst tmpInst;
1733+
tmpInst.setOpcode(Opcode);
1734+
tmpInst.addOperand(MCOperand::createReg(DstReg));
1735+
tmpInst.addOperand(Imm);
1736+
tmpInst.setLoc(IDLoc);
1737+
Instructions.push_back(tmpInst);
1738+
}
1739+
1740+
void emitRI(unsigned Opcode, unsigned DstReg, int16_t Imm, SMLoc IDLoc,
1741+
SmallVectorImpl<MCInst> &Instructions) {
1742+
emitRX(Opcode, DstReg, MCOperand::createImm(Imm), IDLoc, Instructions);
1743+
}
1744+
1745+
1746+
void emitRRX(unsigned Opcode, unsigned DstReg, unsigned SrcReg, MCOperand Imm,
1747+
SMLoc IDLoc, SmallVectorImpl<MCInst> &Instructions) {
1748+
MCInst tmpInst;
1749+
tmpInst.setOpcode(Opcode);
1750+
tmpInst.addOperand(MCOperand::createReg(DstReg));
1751+
tmpInst.addOperand(MCOperand::createReg(SrcReg));
1752+
tmpInst.addOperand(Imm);
1753+
tmpInst.setLoc(IDLoc);
1754+
Instructions.push_back(tmpInst);
1755+
}
1756+
1757+
void emitRRR(unsigned Opcode, unsigned DstReg, unsigned SrcReg,
1758+
unsigned SrcReg2, SMLoc IDLoc,
1759+
SmallVectorImpl<MCInst> &Instructions) {
1760+
emitRRX(Opcode, DstReg, SrcReg, MCOperand::createReg(SrcReg2), IDLoc,
1761+
Instructions);
1762+
}
1763+
1764+
void emitRRI(unsigned Opcode, unsigned DstReg, unsigned SrcReg, int16_t Imm,
1765+
SMLoc IDLoc, SmallVectorImpl<MCInst> &Instructions) {
1766+
emitRRX(Opcode, DstReg, SrcReg, MCOperand::createImm(Imm), IDLoc,
1767+
Instructions);
1768+
}
1769+
17301770
template <unsigned ShiftAmount>
17311771
void createLShiftOri(MCOperand Operand, unsigned RegNo, SMLoc IDLoc,
17321772
SmallVectorImpl<MCInst> &Instructions) {
1733-
MCInst tmpInst;
1734-
if (ShiftAmount >= 32) {
1735-
tmpInst.setOpcode(Mips::DSLL32);
1736-
tmpInst.addOperand(MCOperand::createReg(RegNo));
1737-
tmpInst.addOperand(MCOperand::createReg(RegNo));
1738-
tmpInst.addOperand(MCOperand::createImm(ShiftAmount - 32));
1739-
tmpInst.setLoc(IDLoc);
1740-
Instructions.push_back(tmpInst);
1741-
tmpInst.clear();
1742-
} else if (ShiftAmount > 0) {
1743-
tmpInst.setOpcode(Mips::DSLL);
1744-
tmpInst.addOperand(MCOperand::createReg(RegNo));
1745-
tmpInst.addOperand(MCOperand::createReg(RegNo));
1746-
tmpInst.addOperand(MCOperand::createImm(ShiftAmount));
1747-
tmpInst.setLoc(IDLoc);
1748-
Instructions.push_back(tmpInst);
1749-
tmpInst.clear();
1750-
}
1773+
if (ShiftAmount >= 32)
1774+
emitRRI(Mips::DSLL32, RegNo, RegNo, ShiftAmount - 32, IDLoc, Instructions);
1775+
else if (ShiftAmount > 0)
1776+
emitRRI(Mips::DSLL, RegNo, RegNo, ShiftAmount, IDLoc, Instructions);
1777+
17511778
// There's no need for an ORi if the immediate is 0.
17521779
if (Operand.isImm() && Operand.getImm() == 0)
17531780
return;
17541781

1755-
tmpInst.setOpcode(Mips::ORi);
1756-
tmpInst.addOperand(MCOperand::createReg(RegNo));
1757-
tmpInst.addOperand(MCOperand::createReg(RegNo));
1758-
tmpInst.addOperand(Operand);
1759-
tmpInst.setLoc(IDLoc);
1760-
Instructions.push_back(tmpInst);
1782+
emitRRX(Mips::ORi, RegNo, RegNo, Operand, IDLoc, Instructions);
17611783
}
17621784

17631785
template <unsigned ShiftAmount>
@@ -1818,12 +1840,22 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
18181840
return true;
18191841
}
18201842

1843+
if (Is32BitImm) {
1844+
if (isInt<32>(ImmValue) || isUInt<32>(ImmValue)) {
1845+
// Sign extend up to 64-bit so that the predicates match the hardware
1846+
// behaviour. In particular, isInt<16>(0xffff8000) and similar should be
1847+
// true.
1848+
ImmValue = SignExtend64<32>(ImmValue);
1849+
} else {
1850+
Error(IDLoc, "instruction requires a 32-bit immediate");
1851+
return true;
1852+
}
1853+
}
1854+
18211855
bool UseSrcReg = false;
18221856
if (SrcReg != Mips::NoRegister)
18231857
UseSrcReg = true;
18241858

1825-
MCInst tmpInst;
1826-
18271859
unsigned TmpReg = DstReg;
18281860
if (UseSrcReg && (DstReg == SrcReg)) {
18291861
// At this point we need AT to perform the expansions and we exit if it is
@@ -1834,29 +1866,26 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
18341866
TmpReg = ATReg;
18351867
}
18361868

1837-
tmpInst.setLoc(IDLoc);
18381869
// FIXME: gas has a special case for values that are 000...1111, which
18391870
// becomes a li -1 and then a dsrl
1840-
if (0 <= ImmValue && ImmValue <= 65535) {
1841-
// For unsigned and positive signed 16-bit values (0 <= j <= 65535):
1842-
// li d,j => ori d,$zero,j
1843-
if (!UseSrcReg)
1844-
SrcReg = isGP64bit() ? Mips::ZERO_64 : Mips::ZERO;
1845-
tmpInst.setOpcode(Mips::ORi);
1846-
tmpInst.addOperand(MCOperand::createReg(DstReg));
1847-
tmpInst.addOperand(MCOperand::createReg(SrcReg));
1848-
tmpInst.addOperand(MCOperand::createImm(ImmValue));
1849-
Instructions.push_back(tmpInst);
1850-
} else if (ImmValue < 0 && ImmValue >= -32768) {
1851-
// For negative signed 16-bit values (-32768 <= j < 0):
1871+
if (isInt<16>(ImmValue)) {
18521872
// li d,j => addiu d,$zero,j
18531873
if (!UseSrcReg)
18541874
SrcReg = Mips::ZERO;
1855-
tmpInst.setOpcode(Mips::ADDiu);
1856-
tmpInst.addOperand(MCOperand::createReg(DstReg));
1857-
tmpInst.addOperand(MCOperand::createReg(SrcReg));
1858-
tmpInst.addOperand(MCOperand::createImm(ImmValue));
1859-
Instructions.push_back(tmpInst);
1875+
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, Instructions);
1876+
} else if (isUInt<16>(ImmValue)) {
1877+
// li d,j => ori d,$zero,j
1878+
unsigned TmpReg = DstReg;
1879+
if (SrcReg == DstReg) {
1880+
unsigned ATReg = getATReg(IDLoc);
1881+
if (!ATReg)
1882+
return true;
1883+
TmpReg = ATReg;
1884+
}
1885+
1886+
emitRRI(Mips::ORi, TmpReg, Mips::ZERO, ImmValue, IDLoc, Instructions);
1887+
if (UseSrcReg)
1888+
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, Instructions);
18601889
} else if (isInt<32>(ImmValue) || isUInt<32>(ImmValue)) {
18611890
warnIfNoMacro(IDLoc);
18621891

@@ -1869,30 +1898,16 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
18691898
if (!Is32BitImm && !isInt<32>(ImmValue)) {
18701899
// For DLI, expand to an ORi instead of a LUi to avoid sign-extending the
18711900
// upper 32 bits.
1872-
tmpInst.setOpcode(Mips::ORi);
1873-
tmpInst.addOperand(MCOperand::createReg(TmpReg));
1874-
tmpInst.addOperand(MCOperand::createReg(Mips::ZERO));
1875-
tmpInst.addOperand(MCOperand::createImm(Bits31To16));
1876-
tmpInst.setLoc(IDLoc);
1877-
Instructions.push_back(tmpInst);
1878-
// Move the value to the upper 16 bits by doing a 16-bit left shift.
1879-
createLShiftOri<16>(0, TmpReg, IDLoc, Instructions);
1880-
} else {
1881-
tmpInst.setOpcode(Mips::LUi);
1882-
tmpInst.addOperand(MCOperand::createReg(TmpReg));
1883-
tmpInst.addOperand(MCOperand::createImm(Bits31To16));
1884-
Instructions.push_back(tmpInst);
1885-
}
1901+
emitRRI(Mips::ORi, TmpReg, Mips::ZERO, Bits31To16, IDLoc, Instructions);
1902+
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, Instructions);
1903+
} else
1904+
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, Instructions);
18861905
createLShiftOri<0>(Bits15To0, TmpReg, IDLoc, Instructions);
18871906

18881907
if (UseSrcReg)
18891908
createAddu(DstReg, TmpReg, SrcReg, !Is32BitImm, Instructions);
18901909

18911910
} else if ((ImmValue & (0xffffLL << 48)) == 0) {
1892-
if (Is32BitImm) {
1893-
Error(IDLoc, "instruction requires a 32-bit immediate");
1894-
return true;
1895-
}
18961911
warnIfNoMacro(IDLoc);
18971912

18981913
// <------- lo32 ------>
@@ -1912,21 +1927,14 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
19121927
uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
19131928
uint16_t Bits15To0 = ImmValue & 0xffff;
19141929

1915-
tmpInst.setOpcode(Mips::LUi);
1916-
tmpInst.addOperand(MCOperand::createReg(TmpReg));
1917-
tmpInst.addOperand(MCOperand::createImm(Bits47To32));
1918-
Instructions.push_back(tmpInst);
1930+
emitRI(Mips::LUi, TmpReg, Bits47To32, IDLoc, Instructions);
19191931
createLShiftOri<0>(Bits31To16, TmpReg, IDLoc, Instructions);
19201932
createLShiftOri<16>(Bits15To0, TmpReg, IDLoc, Instructions);
19211933

19221934
if (UseSrcReg)
19231935
createAddu(DstReg, TmpReg, SrcReg, !Is32BitImm, Instructions);
19241936

19251937
} else {
1926-
if (Is32BitImm) {
1927-
Error(IDLoc, "instruction requires a 32-bit immediate");
1928-
return true;
1929-
}
19301938
warnIfNoMacro(IDLoc);
19311939

19321940
// <------- hi32 ------> <------- lo32 ------>
@@ -1948,10 +1956,7 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
19481956
uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
19491957
uint16_t Bits15To0 = ImmValue & 0xffff;
19501958

1951-
tmpInst.setOpcode(Mips::LUi);
1952-
tmpInst.addOperand(MCOperand::createReg(TmpReg));
1953-
tmpInst.addOperand(MCOperand::createImm(Bits63To48));
1954-
Instructions.push_back(tmpInst);
1959+
emitRI(Mips::LUi, TmpReg, Bits63To48, IDLoc, Instructions);
19551960
createLShiftOri<0>(Bits47To32, TmpReg, IDLoc, Instructions);
19561961

19571962
// When Bits31To16 is 0, do a left shift of 32 bits instead of doing
@@ -2096,8 +2101,8 @@ bool MipsAsmParser::loadAndAddSymbolAddress(
20962101
tmpInst.addOperand(MCOperand::createExpr(HiExpr));
20972102
Instructions.push_back(tmpInst);
20982103

2099-
createLShiftOri<0>(MCOperand::createExpr(LoExpr), TmpReg, SMLoc(),
2100-
Instructions);
2104+
emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr), SMLoc(),
2105+
Instructions);
21012106
}
21022107

21032108
if (UseSrcReg)
@@ -2708,12 +2713,8 @@ void MipsAsmParser::createNop(bool hasShortDelaySlot, SMLoc IDLoc,
27082713
void MipsAsmParser::createAddu(unsigned DstReg, unsigned SrcReg,
27092714
unsigned TrgReg, bool Is64Bit,
27102715
SmallVectorImpl<MCInst> &Instructions) {
2711-
MCInst AdduInst;
2712-
AdduInst.setOpcode(Is64Bit ? Mips::DADDu : Mips::ADDu);
2713-
AdduInst.addOperand(MCOperand::createReg(DstReg));
2714-
AdduInst.addOperand(MCOperand::createReg(SrcReg));
2715-
AdduInst.addOperand(MCOperand::createReg(TrgReg));
2716-
Instructions.push_back(AdduInst);
2716+
emitRRR(Is64Bit ? Mips::DADDu : Mips::ADDu, DstReg, SrcReg, TrgReg, SMLoc(),
2717+
Instructions);
27172718
}
27182719

27192720
unsigned MipsAsmParser::checkTargetMatchPredicate(MCInst &Inst) {

‎llvm/test/MC/Mips/macro-la-bad.s

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# RUN: not llvm-mc %s -arch=mips -mcpu=mips32r2 2>%t1
2+
# RUN: FileCheck %s < %t1 --check-prefix=32-BIT
3+
# RUN: not llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n32 2>&1 | \
4+
# RUN: FileCheck %s --check-prefix=64-BIT --check-prefix=N32-ONLY
5+
# RUN: not llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 2>&1 | \
6+
# RUN: FileCheck %s --check-prefix=64-BIT --check-prefix=N64-ONLY
7+
8+
.text
9+
la $5, 0x100000000
10+
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 32-bit immediate
11+
# 64-BIT: :[[@LINE-2]]:3: error: instruction requires a 32-bit immediate
12+
la $5, 0x100000000($6)
13+
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 32-bit immediate
14+
# 64-BIT: :[[@LINE-2]]:3: error: instruction requires a 32-bit immediate
15+
la $5, symbol
16+
# N64-ONLY: :[[@LINE-1]]:3: warning: instruction loads the 32-bit address of a 64-bit symbol
17+
# N32-ONLY-NOT: :[[@LINE-2]]:3: warning: instruction loads the 32-bit address of a 64-bit symbol

‎llvm/test/MC/Mips/macro-la.s

+263
Large diffs are not rendered by default.

‎llvm/test/MC/Mips/macro-li-bad.s

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: not llvm-mc %s -arch=mips -mcpu=mips32r2 2>%t1
2+
# RUN: FileCheck %s < %t1 --check-prefix=32-BIT
3+
# RUN: not llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n32 2>&1 | \
4+
# RUN: FileCheck %s --check-prefix=64-BIT
5+
# RUN: not llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 2>&1 | \
6+
# RUN: FileCheck %s --check-prefix=64-BIT
7+
8+
.text
9+
li $5, 0x100000000
10+
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 32-bit immediate
11+
# 64-BIT: :[[@LINE-2]]:3: error: instruction requires a 32-bit immediate

‎llvm/test/MC/Mips/macro-li.s

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r2 | \
2+
# RUN: FileCheck %s
3+
# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r6 | \
4+
# RUN: FileCheck %s
5+
# RUN: llvm-mc %s -triple=mips64-unknown-linux -show-encoding -mcpu=mips64r2 | \
6+
# RUN: FileCheck %s
7+
# RUN: llvm-mc %s -triple=mips64-unknown-linux -show-encoding -mcpu=mips64r6 | \
8+
# RUN: FileCheck %s
9+
10+
li $5, 0x00000001 # CHECK: addiu $5, $zero, 1 # encoding: [0x24,0x05,0x00,0x01]
11+
li $5, 0x00000002 # CHECK: addiu $5, $zero, 2 # encoding: [0x24,0x05,0x00,0x02]
12+
li $5, 0x00004000 # CHECK: addiu $5, $zero, 16384 # encoding: [0x24,0x05,0x40,0x00]
13+
li $5, 0x00008000 # CHECK: ori $5, $zero, 32768 # encoding: [0x34,0x05,0x80,0x00]
14+
li $5, 0xffffffff # CHECK: addiu $5, $zero, -1 # encoding: [0x24,0x05,0xff,0xff]
15+
li $5, 0xfffffffe # CHECK: addiu $5, $zero, -2 # encoding: [0x24,0x05,0xff,0xfe]
16+
li $5, 0xffffc000 # CHECK: addiu $5, $zero, -16384 # encoding: [0x24,0x05,0xc0,0x00]
17+
li $5, 0xffff8000 # CHECK: addiu $5, $zero, -32768 # encoding: [0x24,0x05,0x80,0x00]
18+
19+
li $5, 0x00010000 # CHECK: lui $5, 1 # encoding: [0x3c,0x05,0x00,0x01]
20+
li $5, 0x00020000 # CHECK: lui $5, 2 # encoding: [0x3c,0x05,0x00,0x02]
21+
li $5, 0x40000000 # CHECK: lui $5, 16384 # encoding: [0x3c,0x05,0x40,0x00]
22+
li $5, 0x80000000 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
23+
li $5, 0xffff0000 # CHECK: lui $5, 65535 # encoding: [0x3c,0x05,0xff,0xff]
24+
li $5, 0xfffe0000 # CHECK: lui $5, 65534 # encoding: [0x3c,0x05,0xff,0xfe]
25+
li $5, 0xc0000000 # CHECK: lui $5, 49152 # encoding: [0x3c,0x05,0xc0,0x00]
26+
li $5, 0x80000000 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
27+
28+
li $5, 0x00010001 # CHECK: lui $5, 1 # encoding: [0x3c,0x05,0x00,0x01]
29+
# CHECK: ori $5, $5, 1 # encoding: [0x34,0xa5,0x00,0x01]
30+
li $5, 0x00020001 # CHECK: lui $5, 2 # encoding: [0x3c,0x05,0x00,0x02]
31+
# CHECK: ori $5, $5, 1 # encoding: [0x34,0xa5,0x00,0x01]
32+
li $5, 0x40000001 # CHECK: lui $5, 16384 # encoding: [0x3c,0x05,0x40,0x00]
33+
# CHECK: ori $5, $5, 1 # encoding: [0x34,0xa5,0x00,0x01]
34+
li $5, 0x80000001 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
35+
# CHECK: ori $5, $5, 1 # encoding: [0x34,0xa5,0x00,0x01]
36+
li $5, 0x00010002 # CHECK: lui $5, 1 # encoding: [0x3c,0x05,0x00,0x01]
37+
# CHECK: ori $5, $5, 2 # encoding: [0x34,0xa5,0x00,0x02]
38+
li $5, 0x00020002 # CHECK: lui $5, 2 # encoding: [0x3c,0x05,0x00,0x02]
39+
# CHECK: ori $5, $5, 2 # encoding: [0x34,0xa5,0x00,0x02]
40+
li $5, 0x40000002 # CHECK: lui $5, 16384 # encoding: [0x3c,0x05,0x40,0x00]
41+
# CHECK: ori $5, $5, 2 # encoding: [0x34,0xa5,0x00,0x02]
42+
li $5, 0x80000002 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
43+
# CHECK: ori $5, $5, 2 # encoding: [0x34,0xa5,0x00,0x02]
44+
li $5, 0x00014000 # CHECK: lui $5, 1 # encoding: [0x3c,0x05,0x00,0x01]
45+
# CHECK: ori $5, $5, 16384 # encoding: [0x34,0xa5,0x40,0x00]
46+
li $5, 0x00024000 # CHECK: lui $5, 2 # encoding: [0x3c,0x05,0x00,0x02]
47+
# CHECK: ori $5, $5, 16384 # encoding: [0x34,0xa5,0x40,0x00]
48+
li $5, 0x40004000 # CHECK: lui $5, 16384 # encoding: [0x3c,0x05,0x40,0x00]
49+
# CHECK: ori $5, $5, 16384 # encoding: [0x34,0xa5,0x40,0x00]
50+
li $5, 0x80004000 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
51+
# CHECK: ori $5, $5, 16384 # encoding: [0x34,0xa5,0x40,0x00]
52+
li $5, 0x00018000 # CHECK: lui $5, 1 # encoding: [0x3c,0x05,0x00,0x01]
53+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]
54+
li $5, 0x00028000 # CHECK: lui $5, 2 # encoding: [0x3c,0x05,0x00,0x02]
55+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]
56+
li $5, 0x40008000 # CHECK: lui $5, 16384 # encoding: [0x3c,0x05,0x40,0x00]
57+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]
58+
li $5, 0x80008000 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
59+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]
60+
li $5, 0xffff4000 # CHECK: lui $5, 65535 # encoding: [0x3c,0x05,0xff,0xff]
61+
# CHECK: ori $5, $5, 16384 # encoding: [0x34,0xa5,0x40,0x00]
62+
li $5, 0xfffe8000 # CHECK: lui $5, 65534 # encoding: [0x3c,0x05,0xff,0xfe]
63+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]
64+
li $5, 0xc0008000 # CHECK: lui $5, 49152 # encoding: [0x3c,0x05,0xc0,0x00]
65+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]
66+
li $5, 0x80008000 # CHECK: lui $5, 32768 # encoding: [0x3c,0x05,0x80,0x00]
67+
# CHECK: ori $5, $5, 32768 # encoding: [0x34,0xa5,0x80,0x00]

‎llvm/test/MC/Mips/micromips-expansions.s

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#------------------------------------------------------------------------------
66
# Load immediate instructions
77
#------------------------------------------------------------------------------
8-
# CHECK: ori $5, $zero, 123 # encoding: [0xa0,0x50,0x7b,0x00]
8+
# CHECK: addiu $5, $zero, 123 # encoding: [0xa0,0x30,0x7b,0x00]
99
# CHECK: addiu $6, $zero, -2345 # encoding: [0xc0,0x30,0xd7,0xf6]
1010
# CHECK: lui $7, 1 # encoding: [0xa7,0x41,0x01,0x00]
1111
# CHECK: ori $7, $7, 2 # encoding: [0xe7,0x50,0x02,0x00]
12-
# CHECK: ori $4, $zero, 20 # encoding: [0x80,0x50,0x14,0x00]
12+
# CHECK: addiu $4, $zero, 20 # encoding: [0x80,0x30,0x14,0x00]
1313
# CHECK: lui $7, 1 # encoding: [0xa7,0x41,0x01,0x00]
1414
# CHECK: ori $7, $7, 2 # encoding: [0xe7,0x50,0x02,0x00]
15-
# CHECK: ori $4, $5, 20 # encoding: [0x85,0x50,0x14,0x00]
15+
# CHECK: addiu $4, $5, 20 # encoding: [0x85,0x30,0x14,0x00]
1616
# CHECK: lui $7, 1 # encoding: [0xa7,0x41,0x01,0x00]
1717
# CHECK: ori $7, $7, 2 # encoding: [0xe7,0x50,0x02,0x00]
1818
# CHECK: addu $7, $7, $8 # encoding: [0x07,0x01,0x50,0x39]

‎llvm/test/MC/Mips/mips-expansions-bad.s

-12
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
# RUN: FileCheck %s --check-prefix=64-BIT --check-prefix=N64-ONLY
77

88
.text
9-
li $5, 0x100000000
10-
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 32-bit immediate
11-
# 64-BIT: :[[@LINE-2]]:3: error: instruction requires a 32-bit immediate
12-
la $5, 0x100000000
13-
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 32-bit immediate
14-
# 64-BIT: :[[@LINE-2]]:3: error: instruction requires a 32-bit immediate
15-
la $5, 0x100000000($6)
16-
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 32-bit immediate
17-
# 64-BIT: :[[@LINE-2]]:3: error: instruction requires a 32-bit immediate
18-
la $5, symbol
19-
# N64-ONLY: :[[@LINE-1]]:3: warning: instruction loads the 32-bit address of a 64-bit symbol
20-
# N32-ONLY-NOT: :[[@LINE-2]]:3: warning: instruction loads the 32-bit address of a 64-bit symbol
219
dli $5, 1
2210
# 32-BIT: :[[@LINE-1]]:3: error: instruction requires a 64-bit architecture
2311
bne $2, 0x100010001, 1332

‎llvm/test/MC/Mips/mips-expansions.s

+19-70
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,13 @@
55

66
# Check that the IAS expands macro instructions in the same way as GAS.
77

8-
# Load immediate, done by MipsAsmParser::expandLoadImm():
9-
li $5, 123
10-
# CHECK-LE: ori $5, $zero, 123 # encoding: [0x7b,0x00,0x05,0x34]
11-
li $6, -2345
12-
# CHECK-LE: addiu $6, $zero, -2345 # encoding: [0xd7,0xf6,0x06,0x24]
13-
li $7, 65538
14-
# CHECK-LE: lui $7, 1 # encoding: [0x01,0x00,0x07,0x3c]
15-
# CHECK-LE: ori $7, $7, 2 # encoding: [0x02,0x00,0xe7,0x34]
16-
li $8, ~7
17-
# CHECK-LE: addiu $8, $zero, -8 # encoding: [0xf8,0xff,0x08,0x24]
18-
li $9, 0x10000
19-
# CHECK-LE: lui $9, 1 # encoding: [0x01,0x00,0x09,0x3c]
20-
# CHECK-LE-NOT: ori $9, $9, 0 # encoding: [0x00,0x00,0x29,0x35]
21-
li $10, ~(0x101010)
22-
# CHECK-LE: lui $10, 65519 # encoding: [0xef,0xff,0x0a,0x3c]
23-
# CHECK-LE: ori $10, $10, 61423 # encoding: [0xef,0xef,0x4a,0x35]
24-
258
# Load address, done by MipsAsmParser::expandLoadAddressReg()
269
# and MipsAsmParser::expandLoadAddressImm():
27-
la $4, 20
28-
# CHECK-LE: ori $4, $zero, 20 # encoding: [0x14,0x00,0x04,0x34]
29-
la $7, 65538
30-
# CHECK-LE: lui $7, 1 # encoding: [0x01,0x00,0x07,0x3c]
31-
# CHECK-LE: ori $7, $7, 2 # encoding: [0x02,0x00,0xe7,0x34]
32-
la $4, 20($5)
33-
# CHECK-LE: ori $4, $5, 20 # encoding: [0x14,0x00,0xa4,0x34]
34-
la $7, 65538($8)
35-
# CHECK-LE: lui $7, 1 # encoding: [0x01,0x00,0x07,0x3c]
36-
# CHECK-LE: ori $7, $7, 2 # encoding: [0x02,0x00,0xe7,0x34]
37-
# CHECK-LE: addu $7, $7, $8 # encoding: [0x21,0x38,0xe8,0x00]
3810
la $8, 1f
3911
# CHECK-LE: lui $8, %hi($tmp0) # encoding: [A,A,0x08,0x3c]
4012
# CHECK-LE: # fixup A - offset: 0, value: ($tmp0)@ABS_HI, kind: fixup_Mips_HI16
41-
# CHECK-LE: ori $8, $8, %lo($tmp0) # encoding: [A,A,0x08,0x35]
13+
# CHECK-LE: addiu $8, $8, %lo($tmp0) # encoding: [A,A,0x08,0x25]
4214
# CHECK-LE: # fixup A - offset: 0, value: ($tmp0)@ABS_LO, kind: fixup_Mips_LO16
43-
la $8, symbol
44-
# CHECK-LE: lui $8, %hi(symbol) # encoding: [A,A,0x08,0x3c]
45-
# CHECK-LE: # fixup A - offset: 0, value: symbol@ABS_HI, kind: fixup_Mips_HI16
46-
# CHECK-LE: ori $8, $8, %lo(symbol) # encoding: [A,A,0x08,0x35]
47-
# CHECK-LE: # fixup A - offset: 0, value: symbol@ABS_LO, kind: fixup_Mips_LO16
48-
la $8, symbol($9)
49-
# CHECK-LE: lui $8, %hi(symbol) # encoding: [A,A,0x08,0x3c]
50-
# CHECK-LE: # fixup A - offset: 0, value: symbol@ABS_HI, kind: fixup_Mips_HI16
51-
# CHECK-LE: ori $8, $8, %lo(symbol) # encoding: [A,A,0x08,0x35]
52-
# CHECK-LE: # fixup A - offset: 0, value: symbol@ABS_LO, kind: fixup_Mips_LO16
53-
# CHECK-LE: addu $8, $8, $9 # encoding: [0x21,0x40,0x09,0x01]
54-
la $8, symbol($8)
55-
# CHECK-LE: lui $1, %hi(symbol) # encoding: [A,A,0x01,0x3c]
56-
# CHECK-LE: # fixup A - offset: 0, value: symbol@ABS_HI, kind: fixup_Mips_HI16
57-
# CHECK-LE: ori $1, $1, %lo(symbol) # encoding: [A,A,0x21,0x34]
58-
# CHECK-LE: # fixup A - offset: 0, value: symbol@ABS_LO, kind: fixup_Mips_LO16
59-
# CHECK-LE: addu $8, $1, $8 # encoding: [0x21,0x40,0x28,0x00]
60-
la $8, 20($8)
61-
# CHECK-LE: ori $8, $8, 20 # encoding: [0x14,0x00,0x08,0x35]
62-
la $8, 65538($8)
63-
# CHECK-LE: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c]
64-
# CHECK-LE: ori $1, $1, 2 # encoding: [0x02,0x00,0x21,0x34]
65-
# CHECK-LE: addu $8, $1, $8 # encoding: [0x21,0x40,0x28,0x00]
6615

6716
# LW/SW and LDC1/SDC1 of symbol address, done by MipsAsmParser::expandMemInst():
6817
.set noat
@@ -126,7 +75,7 @@
12675
# CHECK-LE: nop # encoding: [0x00,0x00,0x00,0x00]
12776

12877
bne $2, 123, 1332
129-
# CHECK-LE: ori $1, $zero, 123 # encoding: [0x7b,0x00,0x01,0x34]
78+
# CHECK-LE: addiu $1, $zero, 123 # encoding: [0x7b,0x00,0x01,0x24]
13079
# CHECK-LE: bne $2, $1, 1332 # encoding: [0x4d,0x01,0x41,0x14]
13180
# CHECK-LE: nop # encoding: [0x00,0x00,0x00,0x00]
13281

@@ -157,7 +106,7 @@
157106
# CHECK-LE: nop # encoding: [0x00,0x00,0x00,0x00]
158107

159108
beq $2, 123, 1332
160-
# CHECK-LE: ori $1, $zero, 123 # encoding: [0x7b,0x00,0x01,0x34]
109+
# CHECK-LE: addiu $1, $zero, 123 # encoding: [0x7b,0x00,0x01,0x24]
161110
# CHECK-LE: beq $2, $1, 1332 # encoding: [0x4d,0x01,0x41,0x10]
162111
# CHECK-LE: nop # encoding: [0x00,0x00,0x00,0x00]
163112

@@ -266,16 +215,16 @@
266215
# CHECK-LE: or $8, $8, $1 # encoding: [0x25,0x40,0x01,0x01]
267216

268217
ulhu $8, 32767
269-
# CHECK-BE: ori $1, $zero, 32767 # encoding: [0x34,0x01,0x7f,0xff]
270-
# CHECK-BE: lbu $8, 0($1) # encoding: [0x90,0x28,0x00,0x00]
271-
# CHECK-BE: lbu $1, 1($1) # encoding: [0x90,0x21,0x00,0x01]
272-
# CHECK-BE: sll $8, $8, 8 # encoding: [0x00,0x08,0x42,0x00]
273-
# CHECK-BE: or $8, $8, $1 # encoding: [0x01,0x01,0x40,0x25]
274-
# CHECK-LE: ori $1, $zero, 32767 # encoding: [0xff,0x7f,0x01,0x34]
275-
# CHECK-LE: lbu $8, 1($1) # encoding: [0x01,0x00,0x28,0x90]
276-
# CHECK-LE: lbu $1, 0($1) # encoding: [0x00,0x00,0x21,0x90]
277-
# CHECK-LE: sll $8, $8, 8 # encoding: [0x00,0x42,0x08,0x00]
278-
# CHECK-LE: or $8, $8, $1 # encoding: [0x25,0x40,0x01,0x01]
218+
# CHECK-BE: addiu $1, $zero, 32767 # encoding: [0x24,0x01,0x7f,0xff]
219+
# CHECK-BE: lbu $8, 0($1) # encoding: [0x90,0x28,0x00,0x00]
220+
# CHECK-BE: lbu $1, 1($1) # encoding: [0x90,0x21,0x00,0x01]
221+
# CHECK-BE: sll $8, $8, 8 # encoding: [0x00,0x08,0x42,0x00]
222+
# CHECK-BE: or $8, $8, $1 # encoding: [0x01,0x01,0x40,0x25]
223+
# CHECK-LE: addiu $1, $zero, 32767 # encoding: [0xff,0x7f,0x01,0x24]
224+
# CHECK-LE: lbu $8, 1($1) # encoding: [0x01,0x00,0x28,0x90]
225+
# CHECK-LE: lbu $1, 0($1) # encoding: [0x00,0x00,0x21,0x90]
226+
# CHECK-LE: sll $8, $8, 8 # encoding: [0x00,0x42,0x08,0x00]
227+
# CHECK-LE: or $8, $8, $1 # encoding: [0x25,0x40,0x01,0x01]
279228

280229
# Test ULHU with immediate offset and a source register operand.
281230
ulhu $8, 0($9)
@@ -369,13 +318,13 @@
369318
# CHECK-LE: or $8, $8, $1 # encoding: [0x25,0x40,0x01,0x01]
370319

371320
ulhu $8, 32767($9)
372-
# CHECK-BE: ori $1, $zero, 32767 # encoding: [0x34,0x01,0x7f,0xff]
321+
# CHECK-BE: addiu $1, $zero, 32767 # encoding: [0x24,0x01,0x7f,0xff]
373322
# CHECK-BE: addu $1, $1, $9 # encoding: [0x00,0x29,0x08,0x21]
374323
# CHECK-BE: lbu $8, 0($1) # encoding: [0x90,0x28,0x00,0x00]
375324
# CHECK-BE: lbu $1, 1($1) # encoding: [0x90,0x21,0x00,0x01]
376325
# CHECK-BE: sll $8, $8, 8 # encoding: [0x00,0x08,0x42,0x00]
377326
# CHECK-BE: or $8, $8, $1 # encoding: [0x01,0x01,0x40,0x25]
378-
# CHECK-LE: ori $1, $zero, 32767 # encoding: [0xff,0x7f,0x01,0x34]
327+
# CHECK-LE: addiu $1, $zero, 32767 # encoding: [0xff,0x7f,0x01,0x24]
379328
# CHECK-LE: addu $1, $1, $9 # encoding: [0x21,0x08,0x29,0x00]
380329
# CHECK-LE: lbu $8, 1($1) # encoding: [0x01,0x00,0x28,0x90]
381330
# CHECK-LE: lbu $1, 0($1) # encoding: [0x00,0x00,0x21,0x90]
@@ -438,10 +387,10 @@
438387
# CHECK-LE: lwr $8, 0($1) # encoding: [0x00,0x00,0x28,0x98]
439388

440389
ulw $8, 32765
441-
# CHECK-BE: ori $1, $zero, 32765 # encoding: [0x34,0x01,0x7f,0xfd]
390+
# CHECK-BE: addiu $1, $zero, 32765 # encoding: [0x24,0x01,0x7f,0xfd]
442391
# CHECK-BE: lwl $8, 0($1) # encoding: [0x88,0x28,0x00,0x00]
443392
# CHECK-BE: lwr $8, 3($1) # encoding: [0x98,0x28,0x00,0x03]
444-
# CHECK-LE: ori $1, $zero, 32765 # encoding: [0xfd,0x7f,0x01,0x34]
393+
# CHECK-LE: addiu $1, $zero, 32765 # encoding: [0xfd,0x7f,0x01,0x24]
445394
# CHECK-LE: lwl $8, 3($1) # encoding: [0x03,0x00,0x28,0x88]
446395
# CHECK-LE: lwr $8, 0($1) # encoding: [0x00,0x00,0x28,0x98]
447396

@@ -509,11 +458,11 @@
509458
# CHECK-LE: lwr $8, 0($1) # encoding: [0x00,0x00,0x28,0x98]
510459

511460
ulw $8, 32765($9)
512-
# CHECK-BE: ori $1, $zero, 32765 # encoding: [0x34,0x01,0x7f,0xfd]
461+
# CHECK-BE: addiu $1, $zero, 32765 # encoding: [0x24,0x01,0x7f,0xfd]
513462
# CHECK-BE: addu $1, $1, $9 # encoding: [0x00,0x29,0x08,0x21]
514463
# CHECK-BE: lwl $8, 0($1) # encoding: [0x88,0x28,0x00,0x00]
515464
# CHECK-BE: lwr $8, 3($1) # encoding: [0x98,0x28,0x00,0x03]
516-
# CHECK-LE: ori $1, $zero, 32765 # encoding: [0xfd,0x7f,0x01,0x34]
465+
# CHECK-LE: addiu $1, $zero, 32765 # encoding: [0xfd,0x7f,0x01,0x24]
517466
# CHECK-LE: addu $1, $1, $9 # encoding: [0x21,0x08,0x29,0x00]
518467
# CHECK-LE: lwl $8, 3($1) # encoding: [0x03,0x00,0x28,0x88]
519468
# CHECK-LE: lwr $8, 0($1) # encoding: [0x00,0x00,0x28,0x98]

‎llvm/test/MC/Mips/mips64-expansions.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Immediate is <= 32 bits.
66
dli $5, 123
7-
# CHECK: ori $5, $zero, 123 # encoding: [0x7b,0x00,0x05,0x34]
7+
# CHECK: addiu $5, $zero, 123 # encoding: [0x7b,0x00,0x05,0x24]
88

99
dli $6, -2345
1010
# CHECK: addiu $6, $zero, -2345 # encoding: [0xd7,0xf6,0x06,0x24]

0 commit comments

Comments
 (0)
Please sign in to comment.