PR1255(case ranges) related changes in Local Transformations.
authorStepan Dyatkovskiy <stpworld@narod.ru>
Wed, 23 May 2012 08:18:26 +0000 (08:18 +0000)
committerStepan Dyatkovskiy <stpworld@narod.ru>
Wed, 23 May 2012 08:18:26 +0000 (08:18 +0000)
llvm-svn: 157315

llvm/lib/Transforms/Utils/Local.cpp

index 4e1a00f..179f29c 100644 (file)
@@ -169,16 +169,20 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions) {
       // Otherwise, we can fold this switch into a conditional branch
       // instruction if it has only one non-default destination.
       SwitchInst::CaseIt FirstCase = SI->case_begin();
-      Value *Cond = Builder.CreateICmpEQ(SI->getCondition(),
-          FirstCase.getCaseValue(), "cond");
-
-      // Insert the new branch.
-      Builder.CreateCondBr(Cond, FirstCase.getCaseSuccessor(),
-                           SI->getDefaultDest());
-
-      // Delete the old switch.
-      SI->eraseFromParent();
-      return true;
+      ConstantRangesSet CRS = FirstCase.getCaseValueEx();
+      if (CRS.getNumItems() == 1 && CRS.isSingleNumber(0)) {
+        Value *Cond = Builder.CreateICmpEQ(SI->getCondition(),
+            CRS.getItem(0).Low, "cond");
+
+        // Insert the new branch.
+        Builder.CreateCondBr(Cond, FirstCase.getCaseSuccessor(),
+                             SI->getDefaultDest());
+
+        // Delete the old switch.
+        SI->eraseFromParent();
+        return true;
+        
+      }
     }
     return false;
   }