diff options
| author | Toma Tabacu <toma.tabacu@imgtec.com> | 2015-05-01 10:26:47 +0000 |
|---|---|---|
| committer | Toma Tabacu <toma.tabacu@imgtec.com> | 2015-05-01 10:26:47 +0000 |
| commit | a2861db834d909fc4ab3b5e5385ae24024520a97 (patch) | |
| tree | 5071e204de225fa629490762421970a3b3998d68 /llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | |
| parent | b3e428e5870e9ed1c667b28c6cbceb8f0fa5d1bd (diff) | |
| download | bcm5719-llvm-a2861db834d909fc4ab3b5e5385ae24024520a97.tar.gz bcm5719-llvm-a2861db834d909fc4ab3b5e5385ae24024520a97.zip | |
[mips] [IAS] Slightly improve shift instruction generation in expandLoadImm.
Summary:
Generate one DSLL32 of 0 instead of two consecutive DSLL of 16.
In order to do this I had to change createLShiftOri's template argument from a bool to an unsigned.
This also gave me the opportunity to rewrite the mips64-expansions.s test, as it was testing the same cases multiple times and skipping over other cases.
It was also somewhat unreadable, as the CHECK lines were grouped in a huge block of text at the beginning of the file.
Reviewers: dsanders
Reviewed By: dsanders
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D8974
llvm-svn: 236311
Diffstat (limited to 'llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp')
| -rw-r--r-- | llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 9eaed5622f7..ed6e8ebe048 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -1632,15 +1632,23 @@ bool MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc, } namespace { -template <bool PerformShift> +template <unsigned ShiftAmount> void createLShiftOri(MCOperand Operand, unsigned RegNo, SMLoc IDLoc, - SmallVectorImpl<MCInst> &Instructions) { + SmallVectorImpl<MCInst> &Instructions) { MCInst tmpInst; - if (PerformShift) { + if (ShiftAmount >= 32) { + tmpInst.setOpcode(Mips::DSLL32); + tmpInst.addOperand(MCOperand::CreateReg(RegNo)); + tmpInst.addOperand(MCOperand::CreateReg(RegNo)); + tmpInst.addOperand(MCOperand::CreateImm(ShiftAmount - 32)); + tmpInst.setLoc(IDLoc); + Instructions.push_back(tmpInst); + tmpInst.clear(); + } else if (ShiftAmount > 0) { tmpInst.setOpcode(Mips::DSLL); tmpInst.addOperand(MCOperand::CreateReg(RegNo)); tmpInst.addOperand(MCOperand::CreateReg(RegNo)); - tmpInst.addOperand(MCOperand::CreateImm(16)); + tmpInst.addOperand(MCOperand::CreateImm(ShiftAmount)); tmpInst.setLoc(IDLoc); Instructions.push_back(tmpInst); tmpInst.clear(); @@ -1657,11 +1665,11 @@ void createLShiftOri(MCOperand Operand, unsigned RegNo, SMLoc IDLoc, Instructions.push_back(tmpInst); } -template <bool PerformShift> +template <unsigned ShiftAmount> void createLShiftOri(int64_t Value, unsigned RegNo, SMLoc IDLoc, - SmallVectorImpl<MCInst> &Instructions) { - createLShiftOri<PerformShift>(MCOperand::CreateImm(Value), RegNo, IDLoc, - Instructions); + SmallVectorImpl<MCInst> &Instructions) { + createLShiftOri<ShiftAmount>(MCOperand::CreateImm(Value), RegNo, IDLoc, + Instructions); } } @@ -1747,7 +1755,7 @@ bool MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc, tmpInst.addOperand(MCOperand::CreateReg(Reg)); tmpInst.addOperand(MCOperand::CreateImm(Bits31To16)); Instructions.push_back(tmpInst); - createLShiftOri<false>(Bits15To0, Reg, IDLoc, Instructions); + createLShiftOri<0>(Bits15To0, Reg, IDLoc, Instructions); } else if ((ImmValue & (0xffffLL << 48)) == 0) { if (!isGP64bit()) { Error(IDLoc, "instruction requires a 64-bit architecture"); @@ -1775,8 +1783,8 @@ bool MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc, tmpInst.addOperand(MCOperand::CreateReg(Reg)); tmpInst.addOperand(MCOperand::CreateImm(Bits47To32)); Instructions.push_back(tmpInst); - createLShiftOri<false>(Bits31To16, Reg, IDLoc, Instructions); - createLShiftOri<true>(Bits15To0, Reg, IDLoc, Instructions); + createLShiftOri<0>(Bits31To16, Reg, IDLoc, Instructions); + createLShiftOri<16>(Bits15To0, Reg, IDLoc, Instructions); } else { if (!isGP64bit()) { Error(IDLoc, "instruction requires a 64-bit architecture"); @@ -1806,9 +1814,16 @@ bool MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc, tmpInst.addOperand(MCOperand::CreateReg(Reg)); tmpInst.addOperand(MCOperand::CreateImm(Bits63To48)); Instructions.push_back(tmpInst); - createLShiftOri<false>(Bits47To32, Reg, IDLoc, Instructions); - createLShiftOri<true>(Bits31To16, Reg, IDLoc, Instructions); - createLShiftOri<true>(Bits15To0, Reg, IDLoc, Instructions); + createLShiftOri<0>(Bits47To32, Reg, IDLoc, Instructions); + + // When Bits31To16 is 0, do a left shift of 32 bits instead of doing + // two left shifts of 16 bits. + if (Bits31To16 == 0) { + createLShiftOri<32>(Bits15To0, Reg, IDLoc, Instructions); + } else { + createLShiftOri<16>(Bits31To16, Reg, IDLoc, Instructions); + createLShiftOri<16>(Bits15To0, Reg, IDLoc, Instructions); + } } return false; } @@ -1947,11 +1962,11 @@ MipsAsmParser::expandLoadAddressSym(MCInst &Inst, SMLoc IDLoc, tmpInst.addOperand(MCOperand::CreateExpr(HighestExpr)); Instructions.push_back(tmpInst); - createLShiftOri<false>(MCOperand::CreateExpr(HigherExpr), RegNo, SMLoc(), - Instructions); - createLShiftOri<true>(MCOperand::CreateExpr(HiExpr), RegNo, SMLoc(), + createLShiftOri<0>(MCOperand::CreateExpr(HigherExpr), RegNo, SMLoc(), + Instructions); + createLShiftOri<16>(MCOperand::CreateExpr(HiExpr), RegNo, SMLoc(), Instructions); - createLShiftOri<true>(MCOperand::CreateExpr(LoExpr), RegNo, SMLoc(), + createLShiftOri<16>(MCOperand::CreateExpr(LoExpr), RegNo, SMLoc(), Instructions); } else { // Otherwise, expand to: @@ -1962,8 +1977,8 @@ MipsAsmParser::expandLoadAddressSym(MCInst &Inst, SMLoc IDLoc, tmpInst.addOperand(MCOperand::CreateExpr(HiExpr)); Instructions.push_back(tmpInst); - createLShiftOri<false>(MCOperand::CreateExpr(LoExpr), RegNo, SMLoc(), - Instructions); + createLShiftOri<0>(MCOperand::CreateExpr(LoExpr), RegNo, SMLoc(), + Instructions); } } |

