Skip to content

Commit

Permalink
[InstCombine] Remove unreachable blocks before DCE
Browse files Browse the repository at this point in the history
Dropping unreachable code may reduce use counts on other instructions,
so it's better to do this earlier rather than later.

NFC-ish, may only impact worklist order.
  • Loading branch information
nikic committed Mar 28, 2020
1 parent 97cc127 commit 2215dcf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Expand Up @@ -3685,6 +3685,18 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
Worklist.push_back(SuccBB);
} while (!Worklist.empty());

// Remove instructions inside unreachable blocks. This prevents the
// instcombine code from having to deal with some bad special cases, and
// reduces use counts of instructions.
for (BasicBlock &BB : F) {
if (Visited.count(&BB))
continue;

unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB);
MadeIRChange |= NumDeadInstInBB > 0;
NumDeadInst += NumDeadInstInBB;
}

// Once we've found all of the instructions to add to instcombine's worklist,
// add them in reverse order. This way instcombine will visit from the top
// of the function down. This jives well with the way that it adds all uses
Expand All @@ -3706,18 +3718,6 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
ICWorklist.push(Inst);
}

// Do a quick scan over the function. If we find any blocks that are
// unreachable, remove any instructions inside of them. This prevents
// the instcombine code from having to deal with some bad special cases.
for (BasicBlock &BB : F) {
if (Visited.count(&BB))
continue;

unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB);
MadeIRChange |= NumDeadInstInBB > 0;
NumDeadInst += NumDeadInstInBB;
}

return MadeIRChange;
}

Expand Down

0 comments on commit 2215dcf

Please sign in to comment.