Skip to content

Commit f0cdc75

Browse files
committed
address comment
1 parent 34b52bb commit f0cdc75

File tree

1 file changed

+40
-42
lines changed

1 file changed

+40
-42
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5256,45 +5256,44 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
52565256
return;
52575257

52585258
unsigned Opcode = MI->getOpcode();
5259-
bool IsNonSignedExtInstrNeedPromoted = false;
5259+
bool HasNonSignedExtInstrPromoted = false;
52605260
int NewOpcode = -1;
52615261

5262-
#define MapOpCode(A) \
5263-
case A: \
5264-
NewOpcode = A##8; \
5265-
IsNonSignedExtInstrNeedPromoted = true; \
5266-
break
5267-
5268-
switch (Opcode) {
5269-
MapOpCode(PPC::OR);
5270-
MapOpCode(PPC::ISEL);
5271-
MapOpCode(PPC::ORI);
5272-
MapOpCode(PPC::XORI);
5273-
MapOpCode(PPC::ORIS);
5274-
MapOpCode(PPC::XORIS);
5275-
MapOpCode(PPC::AND);
5262+
std::unordered_map<unsigned, unsigned> OpcodeMap = {
5263+
{PPC::OR, PPC::OR8}, {PPC::ISEL, PPC::ISEL8},
5264+
{PPC::ORI, PPC::ORI8}, {PPC::XORI, PPC::XORI8},
5265+
{PPC::ORIS, PPC::ORIS8}, {PPC::XORIS, PPC::XORIS8},
5266+
{PPC::AND, PPC::AND8}};
5267+
5268+
// Check if the Opcode is in the map.
5269+
auto It = OpcodeMap.find(Opcode);
5270+
if (It != OpcodeMap.end()) {
5271+
// Set the new opcode to the mapped 64-bit version.
5272+
NewOpcode = It->second;
5273+
HasNonSignedExtInstrPromoted = true;
52765274
}
5277-
#undef MapOpCode
52785275

52795276
switch (Opcode) {
52805277
case PPC::OR:
52815278
case PPC::ISEL:
52825279
case PPC::OR8:
5283-
case PPC::PHI:
5284-
if (BinOpDepth < MAX_BINOP_DEPTH) {
5285-
unsigned OperandEnd = 3, OperandStride = 1;
5286-
if (Opcode == PPC::PHI) {
5287-
OperandEnd = MI->getNumOperands();
5288-
OperandStride = 2;
5289-
}
5280+
case PPC::PHI: {
5281+
if (BinOpDepth >= MAX_BINOP_DEPTH)
5282+
break;
5283+
unsigned OperandEnd = 3, OperandStride = 1;
5284+
if (Opcode == PPC::PHI) {
5285+
OperandEnd = MI->getNumOperands();
5286+
OperandStride = 2;
5287+
}
52905288

5291-
for (unsigned I = 1; I < OperandEnd; I += OperandStride) {
5292-
assert(MI->getOperand(I).isReg() && "Operand must be register");
5293-
Register SrcReg = MI->getOperand(I).getReg();
5294-
promoteInstr32To64ForElimEXTSW(SrcReg, MRI, BinOpDepth + 1, LV);
5295-
}
5289+
for (unsigned I = 1; I < OperandEnd; I += OperandStride) {
5290+
assert(MI->getOperand(I).isReg() && "Operand must be register");
5291+
promoteInstr32To64ForElimEXTSW(MI->getOperand(I).getReg(), MRI,
5292+
BinOpDepth + 1, LV);
52965293
}
5294+
52975295
break;
5296+
}
52985297
case PPC::COPY: {
52995298
// Refers to the logic of the `case PPC::COPY` statement in the function
53005299
// PPCInstrInfo::isSignOrZeroExtended().
@@ -5326,26 +5325,25 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
53265325
case PPC::ORI8:
53275326
case PPC::XORI8:
53285327
case PPC::ORIS8:
5329-
case PPC::XORIS8: {
5330-
Register SrcReg = MI->getOperand(1).getReg();
5331-
promoteInstr32To64ForElimEXTSW(SrcReg, MRI, BinOpDepth, LV);
5328+
case PPC::XORIS8:
5329+
promoteInstr32To64ForElimEXTSW(MI->getOperand(1).getReg(), MRI, BinOpDepth,
5330+
LV);
53325331
break;
5333-
}
53345332
case PPC::AND:
5335-
case PPC::AND8: {
5336-
if (BinOpDepth < MAX_BINOP_DEPTH) {
5337-
Register SrcReg1 = MI->getOperand(1).getReg();
5338-
promoteInstr32To64ForElimEXTSW(SrcReg1, MRI, BinOpDepth + 1, LV);
5339-
Register SrcReg2 = MI->getOperand(2).getReg();
5340-
promoteInstr32To64ForElimEXTSW(SrcReg2, MRI, BinOpDepth + 1, LV);
5341-
}
5333+
case PPC::AND8:
5334+
if (BinOpDepth >= MAX_BINOP_DEPTH)
5335+
break;
5336+
5337+
promoteInstr32To64ForElimEXTSW(MI->getOperand(1).getReg(), MRI,
5338+
BinOpDepth + 1, LV);
5339+
promoteInstr32To64ForElimEXTSW(MI->getOperand(2).getReg(), MRI,
5340+
BinOpDepth + 1, LV);
53425341
break;
53435342
}
5344-
}
53455343

53465344
const PPCInstrInfo *TII =
53475345
MI->getMF()->getSubtarget<PPCSubtarget>().getInstrInfo();
5348-
if (!TII->isSExt32To64(Opcode) && !IsNonSignedExtInstrNeedPromoted)
5346+
if (!TII->isSExt32To64(Opcode) && !HasNonSignedExtInstrPromoted)
53495347
return;
53505348

53515349
const TargetRegisterClass *RC = MRI->getRegClass(Reg);
@@ -5356,7 +5354,7 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
53565354
// The TableGen function `get64BitInstrFromSignedExt32BitInstr` is used to
53575355
// map the 32-bit instruction with the `SExt32To64` flag to the 64-bit
53585356
// instruction with the same opcode.
5359-
if (!IsNonSignedExtInstrNeedPromoted)
5357+
if (!HasNonSignedExtInstrPromoted)
53605358
NewOpcode = PPC::get64BitInstrFromSignedExt32BitInstr(Opcode);
53615359

53625360
assert(NewOpcode != -1 &&

0 commit comments

Comments
 (0)