mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
Also optimize large switch statements.
The isValueEqualityComparison() guard at the top of SimplifySwitch() only applies to some of the possible transformations. The newer transformations work just fine on large switches, and the check on predecessor count is nonsensical. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166710 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -3583,32 +3583,30 @@ static bool SwitchToLookupTable(SwitchInst *SI,
|
||||
}
|
||||
|
||||
bool SimplifyCFGOpt::SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) {
|
||||
// If this switch is too complex to want to look at, ignore it.
|
||||
if (!isValueEqualityComparison(SI))
|
||||
return false;
|
||||
|
||||
BasicBlock *BB = SI->getParent();
|
||||
|
||||
// If we only have one predecessor, and if it is a branch on this value,
|
||||
// see if that predecessor totally determines the outcome of this switch.
|
||||
if (BasicBlock *OnlyPred = BB->getSinglePredecessor())
|
||||
if (SimplifyEqualityComparisonWithOnlyPredecessor(SI, OnlyPred, Builder))
|
||||
return SimplifyCFG(BB) | true;
|
||||
if (isValueEqualityComparison(SI)) {
|
||||
// If we only have one predecessor, and if it is a branch on this value,
|
||||
// see if that predecessor totally determines the outcome of this switch.
|
||||
if (BasicBlock *OnlyPred = BB->getSinglePredecessor())
|
||||
if (SimplifyEqualityComparisonWithOnlyPredecessor(SI, OnlyPred, Builder))
|
||||
return SimplifyCFG(BB) | true;
|
||||
|
||||
Value *Cond = SI->getCondition();
|
||||
if (SelectInst *Select = dyn_cast<SelectInst>(Cond))
|
||||
if (SimplifySwitchOnSelect(SI, Select))
|
||||
return SimplifyCFG(BB) | true;
|
||||
Value *Cond = SI->getCondition();
|
||||
if (SelectInst *Select = dyn_cast<SelectInst>(Cond))
|
||||
if (SimplifySwitchOnSelect(SI, Select))
|
||||
return SimplifyCFG(BB) | true;
|
||||
|
||||
// If the block only contains the switch, see if we can fold the block
|
||||
// away into any preds.
|
||||
BasicBlock::iterator BBI = BB->begin();
|
||||
// Ignore dbg intrinsics.
|
||||
while (isa<DbgInfoIntrinsic>(BBI))
|
||||
++BBI;
|
||||
if (SI == &*BBI)
|
||||
if (FoldValueComparisonIntoPredecessors(SI, Builder))
|
||||
return SimplifyCFG(BB) | true;
|
||||
// If the block only contains the switch, see if we can fold the block
|
||||
// away into any preds.
|
||||
BasicBlock::iterator BBI = BB->begin();
|
||||
// Ignore dbg intrinsics.
|
||||
while (isa<DbgInfoIntrinsic>(BBI))
|
||||
++BBI;
|
||||
if (SI == &*BBI)
|
||||
if (FoldValueComparisonIntoPredecessors(SI, Builder))
|
||||
return SimplifyCFG(BB) | true;
|
||||
}
|
||||
|
||||
// Try to transform the switch into an icmp and a branch.
|
||||
if (TurnSwitchRangeIntoICmp(SI, Builder))
|
||||
|
Reference in New Issue
Block a user