mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-20 11:29:24 +00:00
Don't confuse canonicalize and lookup. Fixes predsimplify.reg4.ll. Also
corrects missing optimization opportunity removing cases from a switch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30009 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dfcfacb0cb
commit
7218c28822
@ -576,30 +576,29 @@ void PredicateSimplifier::visit(BranchInst *BI,
|
||||
void PredicateSimplifier::visit(SwitchInst *SI,
|
||||
DominatorTree::Node *DTNode, PropertySet KP) {
|
||||
Value *Condition = SI->getCondition();
|
||||
DEBUG(assert(Condition == KP.canonicalize(Condition) &&
|
||||
"Instruction wasn't already canonicalized?"));
|
||||
|
||||
// If there's an NEProperty covering this SwitchInst, we may be able to
|
||||
// eliminate one of the cases.
|
||||
if (Value *C = KP.lookup(Condition)) {
|
||||
Condition = C;
|
||||
for (PropertySet::ConstPropertyIterator I = KP.Properties.begin(),
|
||||
E = KP.Properties.end(); I != E; ++I) {
|
||||
if (I->Opcode != PropertySet::NE) continue;
|
||||
Value *V1 = KP.lookup(I->V1),
|
||||
*V2 = KP.lookup(I->V2);
|
||||
if (V1 != C && V2 != C) continue;
|
||||
for (PropertySet::ConstPropertyIterator I = KP.Properties.begin(),
|
||||
E = KP.Properties.end(); I != E; ++I) {
|
||||
if (I->Opcode != PropertySet::NE) continue;
|
||||
Value *V1 = KP.canonicalize(I->V1),
|
||||
*V2 = KP.canonicalize(I->V2);
|
||||
if (V1 != Condition && V2 != Condition) continue;
|
||||
|
||||
// Is one side a number?
|
||||
ConstantInt *CI = dyn_cast<ConstantInt>(KP.lookup(I->V1));
|
||||
if (!CI) CI = dyn_cast<ConstantInt>(KP.lookup(I->V2));
|
||||
// Is one side a number?
|
||||
ConstantInt *CI = dyn_cast<ConstantInt>(KP.canonicalize(I->V1));
|
||||
if (!CI) CI = dyn_cast<ConstantInt>(KP.canonicalize(I->V2));
|
||||
|
||||
if (CI) {
|
||||
unsigned i = SI->findCaseValue(CI);
|
||||
if (i != 0) {
|
||||
SI->getSuccessor(i)->removePredecessor(SI->getParent());
|
||||
SI->removeCase(i);
|
||||
modified = true;
|
||||
++NumSwitchCases;
|
||||
}
|
||||
if (CI) {
|
||||
unsigned i = SI->findCaseValue(CI);
|
||||
if (i != 0) {
|
||||
SI->getSuccessor(i)->removePredecessor(SI->getParent());
|
||||
SI->removeCase(i);
|
||||
modified = true;
|
||||
++NumSwitchCases;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user