diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2006-09-01 03:26:35 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2006-09-01 03:26:35 +0000 |
commit | f6f529d0082b0e4c71bcf2a891b52af8e5b8f2ea (patch) | |
tree | 6806cbb81ee30b5d570a56b440a6e6ef9b3b34a9 /llvm/lib | |
parent | 31305c45da2d65c1673cf7782a13b71eabaf0727 (diff) | |
download | bcm5719-llvm-f6f529d0082b0e4c71bcf2a891b52af8e5b8f2ea.tar.gz bcm5719-llvm-f6f529d0082b0e4c71bcf2a891b52af8e5b8f2ea.zip |
Don't confuse canonicalize and lookup. Fixes predsimplify.reg4.ll. Also
corrects missing optimization opportunity removing cases from a switch.
llvm-svn: 30009
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp b/llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp index 7f998dac3ff..ba28040ed1a 100644 --- a/llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/llvm/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<ConstantInt>(KP.lookup(I->V1)); - if (!CI) CI = dyn_cast<ConstantInt>(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<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; } } } |