Don't confuse canonicalize and lookup. Fixes predsimplify.reg4.ll. Also
authorNick Lewycky <nicholas@mxc.ca>
Fri, 1 Sep 2006 03:26:35 +0000 (03:26 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 1 Sep 2006 03:26:35 +0000 (03:26 +0000)
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

lib/Transforms/Scalar/PredicateSimplifier.cpp

index 7f998dac3ff5b10dd84208637cd18e6c85c1f62d..ba28040ed1a4ccd7744aa31d154835df87b61511 100644 (file)
@@ -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;
       }
     }
   }