[Hexagon] Handle ENDLOOP0 in InsertBranch and RemoveBranch

llvm-svn: 232643
This commit is contained in:
Krzysztof Parzyszek 2015-03-18 15:56:43 +00:00
parent 7d4dc00131
commit 7c0a6d7439
2 changed files with 30 additions and 20 deletions

View File

@ -157,15 +157,19 @@ HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
}
BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
} else {
BuildMI(&MBB, DL,
get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
// If Cond[0] is a basic block, insert ENDLOOP0.
if (Cond[0].isMBB())
BuildMI(&MBB, DL, get(Hexagon::ENDLOOP0)).addMBB(Cond[0].getMBB());
else
BuildMI(&MBB, DL,
get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
}
return 1;
}
// We don't handle ENDLOOP0 with a conditional branch in AnalyzeBranch.
BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
return 2;
}
@ -314,30 +318,35 @@ bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
int BOpc = Hexagon::J2_jump;
int BccOpc = Hexagon::J2_jumpt;
int BccOpcNot = Hexagon::J2_jumpf;
MachineBasicBlock::iterator I = MBB.end();
if (I == MBB.begin()) return 0;
--I;
if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
I->getOpcode() != BccOpcNot)
return 0;
// Remove the branch.
I->eraseFromParent();
unsigned Opc1 = I->getOpcode();
switch (Opc1) {
case Hexagon::J2_jump:
case Hexagon::J2_jumpt:
case Hexagon::J2_jumpf:
case Hexagon::ENDLOOP0:
I->eraseFromParent();
break;
default:
return 0;
}
I = MBB.end();
if (I == MBB.begin()) return 1;
--I;
if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
return 1;
// Remove the branch.
I->eraseFromParent();
return 2;
unsigned Opc2 = I->getOpcode();
switch (Opc2) {
case Hexagon::J2_jumpt:
case Hexagon::J2_jumpf:
case Hexagon::ENDLOOP0:
I->eraseFromParent();
return 2;
default:
return 1;
}
}

View File

@ -1,4 +1,5 @@
; RUN: llc -march=hexagon -mcpu=hexagonv4 < %s | FileCheck %s
; RUN: llc -march=hexagon -mcpu=hexagonv4 -no-phi-elim-live-out-early-exit \
; RUN: < %s | FileCheck %s
; Check that we remove the compare and induction variable instructions
; after generating hardware loops.
; Bug 6685.