From: Nick Lewycky Date: Fri, 1 Sep 2006 03:26:35 +0000 (+0000) Subject: Don't confuse canonicalize and lookup. Fixes predsimplify.reg4.ll. Also X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7218c288223c9d1d8eb4d8c1c2c0e9d212cd3e46;p=oota-llvm.git 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 --- diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index 7f998dac3ff..ba28040ed1a 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -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; - - // Is one side a number? - ConstantInt *CI = dyn_cast(KP.lookup(I->V1)); - if (!CI) CI = dyn_cast(KP.lookup(I->V2)); - - if (CI) { - unsigned i = SI->findCaseValue(CI); - if (i != 0) { - SI->getSuccessor(i)->removePredecessor(SI->getParent()); - SI->removeCase(i); - modified = true; - ++NumSwitchCases; - } + 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(KP.canonicalize(I->V1)); + if (!CI) CI = dyn_cast(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; } } }