diff options
author | Justin Bogner <mail@justinbogner.com> | 2013-12-10 00:13:41 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2013-12-10 00:13:41 +0000 |
commit | a41a7b3ee5783977459747f794249fc3387841ef (patch) | |
tree | 8a500e173a96cf2d0a632419fd35fffbd46018a2 /llvm/lib/Transforms/Utils | |
parent | 4287a49913b4e965702abe886fc497d34ff6fd53 (diff) | |
download | bcm5719-llvm-a41a7b3ee5783977459747f794249fc3387841ef.tar.gz bcm5719-llvm-a41a7b3ee5783977459747f794249fc3387841ef.zip |
Transforms: Don't create bad branch weights when folding a switch
This avoids creating branch weight metadata of length one when we fold
cases into the default of a switch instruction, which was triggering
an assert.
llvm-svn: 196845
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 2768041fb2b..8a15c7c9a1b 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -127,8 +127,10 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions, // dest. If so, eliminate it as an explicit compare. if (i.getCaseSuccessor() == DefaultDest) { MDNode* MD = SI->getMetadata(LLVMContext::MD_prof); - // MD should have 2 + NumCases operands. - if (MD && MD->getNumOperands() == 2 + SI->getNumCases()) { + unsigned NCases = SI->getNumCases(); + // Fold the case metadata into the default if there will be any branches + // left, unless the metadata doesn't match the switch. + if (NCases > 1 && MD && MD->getNumOperands() == 2 + NCases) { // Collect branch weights into a vector. SmallVector<uint32_t, 8> Weights; for (unsigned MD_i = 1, MD_e = MD->getNumOperands(); MD_i < MD_e; |