diff options
author | Stepan Dyatkovskiy <stpworld@narod.ru> | 2012-05-23 08:18:26 +0000 |
---|---|---|
committer | Stepan Dyatkovskiy <stpworld@narod.ru> | 2012-05-23 08:18:26 +0000 |
commit | 7a50155227e84d94ae233407050a7f85e7f53199 (patch) | |
tree | 74cfd2196d44095ad2ab5481fdd91167e230ed38 | |
parent | 4a17675888cd61de28571bade60255fd01bdb757 (diff) | |
download | bcm5719-llvm-7a50155227e84d94ae233407050a7f85e7f53199.tar.gz bcm5719-llvm-7a50155227e84d94ae233407050a7f85e7f53199.zip |
PR1255(case ranges) related changes in Local Transformations.
llvm-svn: 157315
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 4e1a00fa2d3..179f29cdafa 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -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; } |