Change ld/st multiples to explicitly model the writeback to base register. This fixes most of the -ldstopti-before-sched2 regressions.

llvm-svn: 83191
This commit is contained in:
Evan Cheng 2009-10-01 01:33:39 +00:00
parent 34986f12e6
commit 3bbc6c3ae6
6 changed files with 55 additions and 40 deletions

View File

@ -627,13 +627,11 @@ let isReturn = 1, isTerminator = 1, isBarrier = 1 in
} }
// FIXME: remove when we have a way to marking a MI with these properties. // FIXME: remove when we have a way to marking a MI with these properties.
// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
// operand list.
// FIXME: Should pc be an implicit operand like PICADD, etc? // FIXME: Should pc be an implicit operand like PICADD, etc?
let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in
def LDM_RET : AXI4ld<(outs), def LDM_RET : AXI4ld<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
LdStMulFrm, IIC_Br, "ldm${p}${addr:submode} $addr, $dst1", LdStMulFrm, IIC_Br, "ldm${p}${addr:submode} $addr, $wb",
[]>; []>;
// On non-Darwin platforms R9 is callee-saved. // On non-Darwin platforms R9 is callee-saved.
@ -900,17 +898,16 @@ def STRB_POST: AI2stbpo<(outs GPR:$base_wb),
// Load / store multiple Instructions. // Load / store multiple Instructions.
// //
// FIXME: $dst1 should be a def.
let mayLoad = 1 in let mayLoad = 1 in
def LDM : AXI4ld<(outs), def LDM : AXI4ld<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
LdStMulFrm, IIC_iLoadm, "ldm${p}${addr:submode} $addr, $dst1", LdStMulFrm, IIC_iLoadm, "ldm${p}${addr:submode} $addr, $wb",
[]>; []>;
let mayStore = 1 in let mayStore = 1 in
def STM : AXI4st<(outs), def STM : AXI4st<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
LdStMulFrm, IIC_iStorem, "stm${p}${addr:submode} $addr, $src1", LdStMulFrm, IIC_iStorem, "stm${p}${addr:submode} $addr, $wb",
[]>; []>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -182,8 +182,8 @@ let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
// FIXME: remove when we have a way to marking a MI with these properties. // FIXME: remove when we have a way to marking a MI with these properties.
let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in
def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$dst1, variable_ops), IIC_Br, def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
"pop${p} $dst1", []>; "pop${p} $wb", []>;
let isCall = 1, let isCall = 1,
Defs = [R0, R1, R2, R3, R12, LR, Defs = [R0, R1, R2, R3, R12, LR,
@ -350,23 +350,23 @@ def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
// These requires base address to be written back or one of the loaded regs. // These requires base address to be written back or one of the loaded regs.
let mayLoad = 1 in let mayLoad = 1 in
def tLDM : T1I<(outs), def tLDM : T1I<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
IIC_iLoadm, IIC_iLoadm,
"ldm${addr:submode}${p} $addr, $dst1", []>; "ldm${addr:submode}${p} $addr, $wb", []>;
let mayStore = 1 in let mayStore = 1 in
def tSTM : T1I<(outs), def tSTM : T1I<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
IIC_iStorem, IIC_iStorem,
"stm${addr:submode}${p} $addr, $src1", []>; "stm${addr:submode}${p} $addr, $wb", []>;
let mayLoad = 1, Uses = [SP], Defs = [SP] in let mayLoad = 1, Uses = [SP], Defs = [SP] in
def tPOP : T1I<(outs), (ins pred:$p, reglist:$dst1, variable_ops), IIC_Br, def tPOP : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
"pop${p} $dst1", []>; "pop${p} $wb", []>;
let mayStore = 1, Uses = [SP], Defs = [SP] in let mayStore = 1, Uses = [SP], Defs = [SP] in
def tPUSH : T1I<(outs), (ins pred:$p, reglist:$src1, variable_ops), IIC_Br, def tPUSH : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
"push${p} $src1", []>; "push${p} $wb", []>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Arithmetic Instructions. // Arithmetic Instructions.

View File

@ -633,13 +633,13 @@ def t2STRB_POST : T2Iidxldst<(outs GPR:$base_wb),
let mayLoad = 1 in let mayLoad = 1 in
def t2LDM : T2XI<(outs), def t2LDM : T2XI<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
IIC_iLoadm, "ldm${addr:submode}${p}${addr:wide} $addr, $dst1", []>; IIC_iLoadm, "ldm${addr:submode}${p}${addr:wide} $addr, $wb", []>;
let mayStore = 1 in let mayStore = 1 in
def t2STM : T2XI<(outs), def t2STM : T2XI<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
IIC_iStorem, "stm${addr:submode}${p}${addr:wide} $addr, $src1", []>; IIC_iStorem, "stm${addr:submode}${p}${addr:wide} $addr, $wb", []>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Move Instructions. // Move Instructions.
@ -1074,8 +1074,8 @@ let Defs =
// FIXME: Should pc be an implicit operand like PICADD, etc? // FIXME: Should pc be an implicit operand like PICADD, etc?
let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in
def t2LDM_RET : T2XI<(outs), def t2LDM_RET : T2XI<(outs),
(ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops), (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
IIC_Br, "ldm${addr:submode}${p}${addr:wide} $addr, $dst1", IIC_Br, "ldm${addr:submode}${p}${addr:wide} $addr, $wb",
[]>; []>;
let isBranch = 1, isTerminator = 1, isBarrier = 1 in { let isBranch = 1, isTerminator = 1, isBarrier = 1 in {

View File

@ -57,32 +57,32 @@ def FSTS : ASI5<0b1101, 0b00, (outs), (ins SPR:$src, addrmode5:$addr),
// //
let mayLoad = 1 in { let mayLoad = 1 in {
def FLDMD : AXDI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$dst1, def FLDMD : AXDI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$wb,
variable_ops), IIC_fpLoadm, variable_ops), IIC_fpLoadm,
"fldm${addr:submode}d${p} ${addr:base}, $dst1", "fldm${addr:submode}d${p} ${addr:base}, $wb",
[]> { []> {
let Inst{20} = 1; let Inst{20} = 1;
} }
def FLDMS : AXSI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$dst1, def FLDMS : AXSI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$wb,
variable_ops), IIC_fpLoadm, variable_ops), IIC_fpLoadm,
"fldm${addr:submode}s${p} ${addr:base}, $dst1", "fldm${addr:submode}s${p} ${addr:base}, $wb",
[]> { []> {
let Inst{20} = 1; let Inst{20} = 1;
} }
} }
let mayStore = 1 in { let mayStore = 1 in {
def FSTMD : AXDI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$src1, def FSTMD : AXDI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$wb,
variable_ops), IIC_fpStorem, variable_ops), IIC_fpStorem,
"fstm${addr:submode}d${p} ${addr:base}, $src1", "fstm${addr:submode}d${p} ${addr:base}, $wb",
[]> { []> {
let Inst{20} = 0; let Inst{20} = 0;
} }
def FSTMS : AXSI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$src1, def FSTMS : AXSI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$wb,
variable_ops), IIC_fpStorem, variable_ops), IIC_fpStorem,
"fstm${addr:submode}s${p} ${addr:base}, $src1", "fstm${addr:submode}s${p} ${addr:base}, $wb",
[]> { []> {
let Inst{20} = 0; let Inst{20} = 0;
} }
@ -233,8 +233,8 @@ def FMSR : AVConv4I<0b11100000, 0b1010, (outs SPR:$dst), (ins GPR:$src),
[(set SPR:$dst, (bitconvert GPR:$src))]>; [(set SPR:$dst, (bitconvert GPR:$src))]>;
def FMRRD : AVConv3I<0b11000101, 0b1011, def FMRRD : AVConv3I<0b11000101, 0b1011,
(outs GPR:$dst1, GPR:$dst2), (ins DPR:$src), (outs GPR:$wb, GPR:$dst2), (ins DPR:$src),
IIC_VMOVDI, "fmrrd", " $dst1, $dst2, $src", IIC_VMOVDI, "fmrrd", " $wb, $dst2, $src",
[/* FIXME: Can't write pattern for multiple result instr*/]>; [/* FIXME: Can't write pattern for multiple result instr*/]>;
// FMDHR: GPR -> SPR // FMDHR: GPR -> SPR

View File

@ -241,6 +241,7 @@ ARMLoadStoreOpt::MergeOps(MachineBasicBlock &MBB,
.addReg(Base, getKillRegState(BaseKill)) .addReg(Base, getKillRegState(BaseKill))
.addImm(ARM_AM::getAM5Opc(Mode, false, isDPR ? NumRegs<<1 : NumRegs)) .addImm(ARM_AM::getAM5Opc(Mode, false, isDPR ? NumRegs<<1 : NumRegs))
.addImm(Pred).addReg(PredReg); .addImm(Pred).addReg(PredReg);
MIB.addReg(0); // Add optional writeback (0 for now).
for (unsigned i = 0; i != NumRegs; ++i) for (unsigned i = 0; i != NumRegs; ++i)
MIB = MIB.addReg(Regs[i].first, getDefRegState(isDef) MIB = MIB.addReg(Regs[i].first, getDefRegState(isDef)
| getKillRegState(Regs[i].second)); | getKillRegState(Regs[i].second));
@ -383,7 +384,7 @@ static inline unsigned getLSMultipleTransferSize(MachineInstr *MI) {
case ARM::STM: case ARM::STM:
case ARM::t2LDM: case ARM::t2LDM:
case ARM::t2STM: case ARM::t2STM:
return (MI->getNumOperands() - 4) * 4; return (MI->getNumOperands() - 5) * 4;
case ARM::FLDMS: case ARM::FLDMS:
case ARM::FSTMS: case ARM::FSTMS:
case ARM::FLDMD: case ARM::FLDMD:
@ -434,11 +435,15 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSMultiple(MachineBasicBlock &MBB,
if (Mode == ARM_AM::ia && if (Mode == ARM_AM::ia &&
isMatchingDecrement(PrevMBBI, Base, Bytes, 0, Pred, PredReg)) { isMatchingDecrement(PrevMBBI, Base, Bytes, 0, Pred, PredReg)) {
MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(ARM_AM::db, true)); MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(ARM_AM::db, true));
MI->getOperand(4).setReg(Base);
MI->getOperand(4).setIsDef();
MBB.erase(PrevMBBI); MBB.erase(PrevMBBI);
return true; return true;
} else if (Mode == ARM_AM::ib && } else if (Mode == ARM_AM::ib &&
isMatchingDecrement(PrevMBBI, Base, Bytes, 0, Pred, PredReg)) { isMatchingDecrement(PrevMBBI, Base, Bytes, 0, Pred, PredReg)) {
MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(ARM_AM::da, true)); MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(ARM_AM::da, true));
MI->getOperand(4).setReg(Base); // WB to base
MI->getOperand(4).setIsDef();
MBB.erase(PrevMBBI); MBB.erase(PrevMBBI);
return true; return true;
} }
@ -449,6 +454,8 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSMultiple(MachineBasicBlock &MBB,
if ((Mode == ARM_AM::ia || Mode == ARM_AM::ib) && if ((Mode == ARM_AM::ia || Mode == ARM_AM::ib) &&
isMatchingIncrement(NextMBBI, Base, Bytes, 0, Pred, PredReg)) { isMatchingIncrement(NextMBBI, Base, Bytes, 0, Pred, PredReg)) {
MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(Mode, true)); MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(Mode, true));
MI->getOperand(4).setReg(Base); // WB to base
MI->getOperand(4).setIsDef();
if (NextMBBI == I) { if (NextMBBI == I) {
Advance = true; Advance = true;
++I; ++I;
@ -458,6 +465,8 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSMultiple(MachineBasicBlock &MBB,
} else if ((Mode == ARM_AM::da || Mode == ARM_AM::db) && } else if ((Mode == ARM_AM::da || Mode == ARM_AM::db) &&
isMatchingDecrement(NextMBBI, Base, Bytes, 0, Pred, PredReg)) { isMatchingDecrement(NextMBBI, Base, Bytes, 0, Pred, PredReg)) {
MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(Mode, true)); MI->getOperand(1).setImm(ARM_AM::getAM4ModeImm(Mode, true));
MI->getOperand(4).setReg(Base); // WB to base
MI->getOperand(4).setIsDef();
if (NextMBBI == I) { if (NextMBBI == I) {
Advance = true; Advance = true;
++I; ++I;
@ -478,6 +487,8 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSMultiple(MachineBasicBlock &MBB,
if (Mode == ARM_AM::ia && if (Mode == ARM_AM::ia &&
isMatchingDecrement(PrevMBBI, Base, Bytes, 0, Pred, PredReg)) { isMatchingDecrement(PrevMBBI, Base, Bytes, 0, Pred, PredReg)) {
MI->getOperand(1).setImm(ARM_AM::getAM5Opc(ARM_AM::db, true, Offset)); MI->getOperand(1).setImm(ARM_AM::getAM5Opc(ARM_AM::db, true, Offset));
MI->getOperand(4).setReg(Base); // WB to base
MI->getOperand(4).setIsDef();
MBB.erase(PrevMBBI); MBB.erase(PrevMBBI);
return true; return true;
} }
@ -488,6 +499,8 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSMultiple(MachineBasicBlock &MBB,
if (Mode == ARM_AM::ia && if (Mode == ARM_AM::ia &&
isMatchingIncrement(NextMBBI, Base, Bytes, 0, Pred, PredReg)) { isMatchingIncrement(NextMBBI, Base, Bytes, 0, Pred, PredReg)) {
MI->getOperand(1).setImm(ARM_AM::getAM5Opc(ARM_AM::ia, true, Offset)); MI->getOperand(1).setImm(ARM_AM::getAM5Opc(ARM_AM::ia, true, Offset));
MI->getOperand(4).setReg(Base); // WB to base
MI->getOperand(4).setIsDef();
if (NextMBBI == I) { if (NextMBBI == I) {
Advance = true; Advance = true;
++I; ++I;
@ -630,6 +643,7 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLoadStore(MachineBasicBlock &MBB,
BuildMI(MBB, MBBI, dl, TII->get(NewOpc)) BuildMI(MBB, MBBI, dl, TII->get(NewOpc))
.addReg(Base, getKillRegState(BaseKill)) .addReg(Base, getKillRegState(BaseKill))
.addImm(Offset).addImm(Pred).addReg(PredReg) .addImm(Offset).addImm(Pred).addReg(PredReg)
.addReg(Base, getDefRegState(true)) // WB base register
.addReg(MI->getOperand(0).getReg(), RegState::Define); .addReg(MI->getOperand(0).getReg(), RegState::Define);
else if (isAM2) else if (isAM2)
// LDR_PRE, LDR_POST, // LDR_PRE, LDR_POST,
@ -647,6 +661,7 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLoadStore(MachineBasicBlock &MBB,
// FSTMS, FSTMD // FSTMS, FSTMD
BuildMI(MBB, MBBI, dl, TII->get(NewOpc)).addReg(Base).addImm(Offset) BuildMI(MBB, MBBI, dl, TII->get(NewOpc)).addReg(Base).addImm(Offset)
.addImm(Pred).addReg(PredReg) .addImm(Pred).addReg(PredReg)
.addReg(Base, getDefRegState(true)) // WB base register
.addReg(MO.getReg(), getKillRegState(MO.isKill())); .addReg(MO.getReg(), getKillRegState(MO.isKill()));
else if (isAM2) else if (isAM2)
// STR_PRE, STR_POST // STR_PRE, STR_POST
@ -811,6 +826,7 @@ bool ARMLoadStoreOpt::FixInvalidRegPairOp(MachineBasicBlock &MBB,
.addReg(BaseReg, getKillRegState(BaseKill)) .addReg(BaseReg, getKillRegState(BaseKill))
.addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)) .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))
.addImm(Pred).addReg(PredReg) .addImm(Pred).addReg(PredReg)
.addReg(0)
.addReg(EvenReg, getDefRegState(isLd) | getDeadRegState(EvenDeadKill)) .addReg(EvenReg, getDefRegState(isLd) | getDeadRegState(EvenDeadKill))
.addReg(OddReg, getDefRegState(isLd) | getDeadRegState(OddDeadKill)); .addReg(OddReg, getDefRegState(isLd) | getDeadRegState(OddDeadKill));
++NumLDRD2LDM; ++NumLDRD2LDM;
@ -819,6 +835,7 @@ bool ARMLoadStoreOpt::FixInvalidRegPairOp(MachineBasicBlock &MBB,
.addReg(BaseReg, getKillRegState(BaseKill)) .addReg(BaseReg, getKillRegState(BaseKill))
.addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)) .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))
.addImm(Pred).addReg(PredReg) .addImm(Pred).addReg(PredReg)
.addReg(0)
.addReg(EvenReg, .addReg(EvenReg,
getKillRegState(EvenDeadKill) | getUndefRegState(EvenUndef)) getKillRegState(EvenDeadKill) | getUndefRegState(EvenUndef))
.addReg(OddReg, .addReg(OddReg,

View File

@ -838,10 +838,11 @@ void ARMAsmPrinter::printPCLabel(const MachineInstr *MI, int OpNum) {
void ARMAsmPrinter::printRegisterList(const MachineInstr *MI, int OpNum) { void ARMAsmPrinter::printRegisterList(const MachineInstr *MI, int OpNum) {
O << "{"; O << "{";
for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) { // Always skip the first operand, it's the optional (and implicit writeback).
for (unsigned i = OpNum+1, e = MI->getNumOperands(); i != e; ++i) {
if (MI->getOperand(i).isImplicit()) if (MI->getOperand(i).isImplicit())
continue; continue;
if ((int)i != OpNum) O << ", "; if ((int)i != OpNum+1) O << ", ";
printOperand(MI, i); printOperand(MI, i);
} }
O << "}"; O << "}";