Skip to content

Commit 5419bc8

Browse files
committed
fixed opcode + 1 problem with InstrMapping
1 parent abb742a commit 5419bc8

File tree

2 files changed

+64
-25
lines changed

2 files changed

+64
-25
lines changed

llvm/lib/Target/PowerPC/PPC.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,18 @@ def getAltVSXFMAOpcode : InstrMapping {
534534
let ValueCols = [["1"]];
535535
}
536536

537+
def get64BitInstrFromSignedExt32BitInstr : InstrMapping {
538+
let FilterClass = "SExt32To64";
539+
// Instructions with the same opcode.
540+
let RowFields = ["Inst"];
541+
// Instructions with the same Interpretation64Bit value form a column.
542+
let ColFields = ["Interpretation64Bit"];
543+
// The key column are not the Interpretation64Bit-form instructions.
544+
let KeyCol = ["0"];
545+
// Value columns are the Interpretation64Bit-form instructions.
546+
let ValueCols = [["1"]];
547+
}
548+
537549
//===----------------------------------------------------------------------===//
538550
// Register File Description
539551
//===----------------------------------------------------------------------===//

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5245,11 +5245,24 @@ void PPCInstrInfo::replaceInstrAfterElimExt32To64(const Register &Reg,
52455245

52465246
unsigned Opcode = MI->getOpcode();
52475247
bool IsReplaceInstr = false;
5248+
int NewOpcode = -1;
5249+
5250+
auto SetNewOpcode = [&](int NewOpc) {
5251+
if (!IsReplaceInstr) {
5252+
NewOpcode = NewOpc;
5253+
IsReplaceInstr = true;
5254+
}
5255+
};
5256+
52485257
switch (Opcode) {
52495258
case PPC::OR:
5259+
SetNewOpcode(PPC::OR8);
5260+
[[fallthrough]];
5261+
case PPC::ISEL:
5262+
SetNewOpcode(PPC::ISEL8);
5263+
[[fallthrough]];
52505264
case PPC::OR8:
52515265
case PPC::PHI:
5252-
case PPC::ISEL:
52535266
if (BinOpDepth < MAX_BINOP_DEPTH) {
52545267
unsigned OperandEnd = 3, OperandStride = 1;
52555268
if (Opcode == PPC::PHI) {
@@ -5263,9 +5276,7 @@ void PPCInstrInfo::replaceInstrAfterElimExt32To64(const Register &Reg,
52635276
replaceInstrAfterElimExt32To64(SrcReg, MRI, BinOpDepth + 1, LV);
52645277
}
52655278

5266-
if (Opcode == PPC::OR || Opcode == PPC::ISEL)
5267-
IsReplaceInstr = true;
5268-
else
5279+
if (!IsReplaceInstr)
52695280
return;
52705281
}
52715282
break;
@@ -5287,37 +5298,60 @@ void PPCInstrInfo::replaceInstrAfterElimExt32To64(const Register &Reg,
52875298
}
52885299
return;
52895300
case PPC::ORI:
5301+
SetNewOpcode(PPC::ORI8);
5302+
[[fallthrough]];
52905303
case PPC::XORI:
5291-
case PPC::ORI8:
5292-
case PPC::XORI8:
5304+
SetNewOpcode(PPC::XORI8);
5305+
[[fallthrough]];
52935306
case PPC::ORIS:
5307+
SetNewOpcode(PPC::ORIS8);
5308+
[[fallthrough]];
52945309
case PPC::XORIS:
5310+
SetNewOpcode(PPC::XORIS8);
5311+
[[fallthrough]];
5312+
case PPC::ORI8:
5313+
case PPC::XORI8:
52955314
case PPC::ORIS8:
52965315
case PPC::XORIS8: {
52975316
Register SrcReg = MI->getOperand(1).getReg();
52985317
replaceInstrAfterElimExt32To64(SrcReg, MRI, BinOpDepth, LV);
52995318

5300-
if (Opcode == PPC::ORI || Opcode == PPC::XORI || Opcode == PPC::ORIS ||
5301-
Opcode == PPC::ORIS || Opcode == PPC::XORIS)
5302-
IsReplaceInstr = true;
5303-
else
5319+
if (!IsReplaceInstr)
53045320
return;
53055321
break;
53065322
}
53075323
case PPC::AND:
5324+
SetNewOpcode(PPC::AND8);
5325+
[[fallthrough]];
53085326
case PPC::AND8: {
53095327
if (BinOpDepth < MAX_BINOP_DEPTH) {
53105328
Register SrcReg1 = MI->getOperand(1).getReg();
53115329
replaceInstrAfterElimExt32To64(SrcReg1, MRI, BinOpDepth, LV);
53125330
Register SrcReg2 = MI->getOperand(2).getReg();
53135331
replaceInstrAfterElimExt32To64(SrcReg2, MRI, BinOpDepth, LV);
5314-
if (Opcode == PPC::AND)
5315-
IsReplaceInstr = true;
5316-
else
5332+
if (!IsReplaceInstr)
53175333
return;
53185334
}
53195335
break;
53205336
}
5337+
case PPC::RLWINM:
5338+
SetNewOpcode(PPC::RLWINM8);
5339+
break;
5340+
case PPC::RLWINM_rec:
5341+
SetNewOpcode(PPC::RLWINM8_rec);
5342+
break;
5343+
case PPC::RLWNM:
5344+
SetNewOpcode(PPC ::RLWNM8);
5345+
break;
5346+
case PPC::RLWNM_rec:
5347+
SetNewOpcode(PPC::RLWNM8_rec);
5348+
break;
5349+
case PPC::ANDC_rec:
5350+
SetNewOpcode(PPC::ANDC8_rec);
5351+
break;
5352+
case PPC::ANDIS_rec:
5353+
SetNewOpcode(PPC::ANDIS8_rec);
5354+
break;
53215355
default:
53225356
break;
53235357
}
@@ -5332,18 +5366,11 @@ void PPCInstrInfo::replaceInstrAfterElimExt32To64(const Register &Reg,
53325366
assert(RC != &PPC::G8RCRegClass && RC != &PPC::G8RC_and_G8RC_NOX0RegClass &&
53335367
"Must be 32-bit Register!");
53345368

5335-
// Fix Me: Most of the pseudo-opcode of 64-bit instruction are equal to
5336-
// the pseudo-opcode of the 32-bit version of the same instruction plus
5337-
// one. However, there are some exceptions: PPC::ANDC_rec,
5338-
// PPC::ANDI_rec, PPC::ANDIS_rec.
5339-
unsigned NewOpcode = Opcode + 1;
5340-
5341-
if (Opcode == PPC::ANDC_rec)
5342-
NewOpcode = PPC::ANDC8_rec;
5343-
if (Opcode == PPC::ANDI_rec)
5344-
NewOpcode = PPC::ANDI8_rec;
5345-
if (Opcode == PPC::ANDIS_rec)
5346-
NewOpcode = PPC::ANDIS8_rec;
5369+
if (!IsReplaceInstr)
5370+
NewOpcode = PPC::get64BitInstrFromSignedExt32BitInstr(Opcode);
5371+
5372+
assert(NewOpcode != -1 &&
5373+
"Must have a 64-bit opcode to map the 32-bit opcode!");
53475374

53485375
const TargetRegisterInfo *TRI = MRI->getTargetRegisterInfo();
53495376
const MCInstrDesc &MCID = TII->get(NewOpcode);

0 commit comments

Comments
 (0)