mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196845 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user