mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
Sort the incoming values in PHI nodes to match the predecessor order.
This helps expose duplicate PHIs, which will make it easier for them to be eliminated. llvm-svn: 85623
This commit is contained in:
parent
ad6c6a3d33
commit
82139ffc65
@ -10980,6 +10980,25 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the PHI node operands to match the pred iterator order. This will
|
||||
// help identical PHIs be eliminated by other passes. Other passes shouldn't
|
||||
// depend on this for correctness however.
|
||||
unsigned i = 0;
|
||||
for (pred_iterator PI = pred_begin(PN.getParent()),
|
||||
PE = pred_end(PN.getParent()); PI != PE; ++PI, ++i)
|
||||
if (PN.getIncomingBlock(i) != *PI) {
|
||||
unsigned j = PN.getBasicBlockIndex(*PI);
|
||||
Value *VA = PN.getIncomingValue(i);
|
||||
BasicBlock *BBA = PN.getIncomingBlock(i);
|
||||
Value *VB = PN.getIncomingValue(j);
|
||||
BasicBlock *BBB = PN.getIncomingBlock(j);
|
||||
PN.setIncomingBlock(i, BBB);
|
||||
PN.setIncomingValue(i, VB);
|
||||
PN.setIncomingBlock(j, BBA);
|
||||
PN.setIncomingValue(j, VA);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user