forked from OSchip/llvm-project
Fix some subtle bugs: bug during succeessor copying; incorrectly updating states of ifcvted blocks.
llvm-svn: 37429
This commit is contained in:
parent
6357bf20fa
commit
17aad8164e
|
@ -153,7 +153,9 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
||||||
default: assert(false && "Unexpected!");
|
default: assert(false && "Unexpected!");
|
||||||
break;
|
break;
|
||||||
case ICReAnalyze:
|
case ICReAnalyze:
|
||||||
// One or more of 'childrean' have been modified, abort!
|
// One or more of 'children' have been modified, abort!
|
||||||
|
case ICDead:
|
||||||
|
// Block has been already been if-converted, abort!
|
||||||
break;
|
break;
|
||||||
case ICSimple:
|
case ICSimple:
|
||||||
case ICSimpleFalse:
|
case ICSimpleFalse:
|
||||||
|
@ -219,9 +221,10 @@ bool IfConverter::ReverseBranchCondition(BBInfo &BBI) {
|
||||||
void IfConverter::StructuralAnalysis(MachineBasicBlock *BB) {
|
void IfConverter::StructuralAnalysis(MachineBasicBlock *BB) {
|
||||||
BBInfo &BBI = BBAnalysis[BB->getNumber()];
|
BBInfo &BBI = BBAnalysis[BB->getNumber()];
|
||||||
|
|
||||||
if (BBI.Kind == ICReAnalyze)
|
if (BBI.Kind == ICReAnalyze) {
|
||||||
BBI.BrCond.clear();
|
BBI.BrCond.clear();
|
||||||
else {
|
BBI.TrueBB = BBI.FalseBB = NULL;
|
||||||
|
} else {
|
||||||
if (BBI.Kind != ICNotAnalyzed)
|
if (BBI.Kind != ICNotAnalyzed)
|
||||||
return; // Already analyzed.
|
return; // Already analyzed.
|
||||||
BBI.BB = BB;
|
BBI.BB = BB;
|
||||||
|
@ -504,10 +507,7 @@ bool IfConverter::IfConvertSimple(BBInfo &BBI) {
|
||||||
std::copy(Cond.begin(), Cond.end(), std::back_inserter(BBI.Predicate));
|
std::copy(Cond.begin(), Cond.end(), std::back_inserter(BBI.Predicate));
|
||||||
|
|
||||||
// Update block info. BB can be iteratively if-converted.
|
// Update block info. BB can be iteratively if-converted.
|
||||||
BBI.Kind = ICNotAnalyzed;
|
BBI.Kind = ICReAnalyze;
|
||||||
BBI.TrueBB = BBI.FalseBB = NULL;
|
|
||||||
BBI.BrCond.clear();
|
|
||||||
TII->AnalyzeBranch(*BBI.BB, BBI.TrueBB, BBI.FalseBB, BBI.BrCond);
|
|
||||||
ReTryPreds(BBI.BB);
|
ReTryPreds(BBI.BB);
|
||||||
CvtBBI->Kind = ICDead;
|
CvtBBI->Kind = ICDead;
|
||||||
|
|
||||||
|
@ -537,9 +537,11 @@ bool IfConverter::IfConvertTriangle(BBInfo &BBI) {
|
||||||
// Join the 'true' and 'false' blocks if the 'false' block has no other
|
// Join the 'true' and 'false' blocks if the 'false' block has no other
|
||||||
// predecessors. Otherwise, add a unconditional branch from 'true' to 'false'.
|
// predecessors. Otherwise, add a unconditional branch from 'true' to 'false'.
|
||||||
BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
|
BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
|
||||||
if (FalseBBI.BB->pred_size() == 2)
|
bool FalseBBDead = false;
|
||||||
|
if (FalseBBI.BB->pred_size() == 2) {
|
||||||
MergeBlocks(TrueBBI, FalseBBI);
|
MergeBlocks(TrueBBI, FalseBBI);
|
||||||
else if (!isNextBlock(TrueBBI.BB, FalseBBI.BB))
|
FalseBBDead = true;
|
||||||
|
} else if (!isNextBlock(TrueBBI.BB, FalseBBI.BB))
|
||||||
InsertUncondBranch(TrueBBI.BB, FalseBBI.BB, TII);
|
InsertUncondBranch(TrueBBI.BB, FalseBBI.BB, TII);
|
||||||
|
|
||||||
// Now merge the entry of the triangle with the true block.
|
// Now merge the entry of the triangle with the true block.
|
||||||
|
@ -549,12 +551,11 @@ bool IfConverter::IfConvertTriangle(BBInfo &BBI) {
|
||||||
std::back_inserter(BBI.Predicate));
|
std::back_inserter(BBI.Predicate));
|
||||||
|
|
||||||
// Update block info. BB can be iteratively if-converted.
|
// Update block info. BB can be iteratively if-converted.
|
||||||
BBI.Kind = ICNotClassfied;
|
BBI.Kind = ICReAnalyze;
|
||||||
BBI.TrueBB = BBI.FalseBB = NULL;
|
|
||||||
BBI.BrCond.clear();
|
|
||||||
TII->AnalyzeBranch(*BBI.BB, BBI.TrueBB, BBI.FalseBB, BBI.BrCond);
|
|
||||||
ReTryPreds(BBI.BB);
|
ReTryPreds(BBI.BB);
|
||||||
TrueBBI.Kind = ICDead;
|
TrueBBI.Kind = ICDead;
|
||||||
|
if (FalseBBDead)
|
||||||
|
FalseBBI.Kind = ICDead;
|
||||||
|
|
||||||
// FIXME: Must maintain LiveIns.
|
// FIXME: Must maintain LiveIns.
|
||||||
return true;
|
return true;
|
||||||
|
@ -683,10 +684,7 @@ bool IfConverter::IfConvertDiamond(BBInfo &BBI) {
|
||||||
|
|
||||||
// Update block info. BB may be iteratively if-converted.
|
// Update block info. BB may be iteratively if-converted.
|
||||||
if (OkToIfcvt) {
|
if (OkToIfcvt) {
|
||||||
BBI.Kind = ICNotClassfied;
|
BBI.Kind = ICReAnalyze;
|
||||||
BBI.TrueBB = BBI.FalseBB = NULL;
|
|
||||||
BBI.BrCond.clear();
|
|
||||||
TII->AnalyzeBranch(*BBI.BB, BBI.TrueBB, BBI.FalseBB, BBI.BrCond);
|
|
||||||
ReTryPreds(BBI.BB);
|
ReTryPreds(BBI.BB);
|
||||||
}
|
}
|
||||||
TrueBBI.Kind = ICDead;
|
TrueBBI.Kind = ICDead;
|
||||||
|
@ -734,9 +732,10 @@ static void TransferPreds(MachineBasicBlock *ToBB, MachineBasicBlock *FromBB) {
|
||||||
static void TransferSuccs(MachineBasicBlock *ToBB, MachineBasicBlock *FromBB) {
|
static void TransferSuccs(MachineBasicBlock *ToBB, MachineBasicBlock *FromBB) {
|
||||||
for (MachineBasicBlock::succ_iterator I = FromBB->succ_begin(),
|
for (MachineBasicBlock::succ_iterator I = FromBB->succ_begin(),
|
||||||
E = FromBB->succ_end(); I != E; ++I) {
|
E = FromBB->succ_end(); I != E; ++I) {
|
||||||
FromBB->removeSuccessor(*I);
|
MachineBasicBlock *Succ = *I;
|
||||||
if (!ToBB->isSuccessor(*I))
|
FromBB->removeSuccessor(Succ);
|
||||||
ToBB->addSuccessor(*I);
|
if (!ToBB->isSuccessor(Succ))
|
||||||
|
ToBB->addSuccessor(Succ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue