parent
ba8735d25a
commit
930aa9d3d2
|
@ -10981,22 +10981,24 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the PHI node operands to match the pred iterator order. This will
|
// If there are multiple PHIs, sort their operands so that they all list
|
||||||
// help identical PHIs be eliminated by other passes. Other passes shouldn't
|
// the blocks in the same order. This will help identical PHIs be eliminated
|
||||||
// depend on this for correctness however.
|
// by other passes. Other passes shouldn't depend on this for correctness
|
||||||
unsigned i = 0;
|
// however.
|
||||||
for (pred_iterator PI = pred_begin(PN.getParent()),
|
PHINode *FirstPN = cast<PHINode>(PN.getParent()->begin());
|
||||||
PE = pred_end(PN.getParent()); PI != PE; ++PI, ++i)
|
if (&PN != FirstPN)
|
||||||
if (PN.getIncomingBlock(i) != *PI) {
|
for (unsigned i = 0, e = FirstPN->getNumIncomingValues(); i != e; ++i) {
|
||||||
unsigned j = PN.getBasicBlockIndex(*PI);
|
|
||||||
Value *VA = PN.getIncomingValue(i);
|
|
||||||
BasicBlock *BBA = PN.getIncomingBlock(i);
|
BasicBlock *BBA = PN.getIncomingBlock(i);
|
||||||
Value *VB = PN.getIncomingValue(j);
|
BasicBlock *BBB = FirstPN->getIncomingBlock(i);
|
||||||
BasicBlock *BBB = PN.getIncomingBlock(j);
|
if (BBA != BBB) {
|
||||||
PN.setIncomingBlock(i, BBB);
|
Value *VA = PN.getIncomingValue(i);
|
||||||
PN.setIncomingValue(i, VB);
|
unsigned j = PN.getBasicBlockIndex(BBB);
|
||||||
PN.setIncomingBlock(j, BBA);
|
Value *VB = PN.getIncomingValue(j);
|
||||||
PN.setIncomingValue(j, VA);
|
PN.setIncomingBlock(i, BBB);
|
||||||
|
PN.setIncomingValue(i, VB);
|
||||||
|
PN.setIncomingBlock(j, BBA);
|
||||||
|
PN.setIncomingValue(j, VA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue