diff options
author | Chris Lattner <sabre@nondot.org> | 2011-04-17 00:54:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-04-17 00:54:30 +0000 |
commit | b11f9198111796ada02b57f62cdea92134fde9f7 (patch) | |
tree | ef962f36d01588087abb2b0701ce24cc18d1c62b /lib/CodeGen/CGStmt.cpp | |
parent | a5e5e0f41e1dcee4603244ccea3d3956c55c23ac (diff) |
implement rdar://9289524 - case followed immediately by break results in empty IR block,
a -O0 code quality issue.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129652 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGStmt.cpp')
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 7a1ce19b07..b8b2cd9f3e 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -867,11 +867,25 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) { } void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) { + // Handle case ranges. if (S.getRHS()) { EmitCaseStmtRange(S); return; } + // If the body of the case is just a 'break', try to not emit an empty block. + if (isa<BreakStmt>(S.getSubStmt())) { + JumpDest Block = BreakContinueStack.back().BreakBlock; + + // Only do this optimization if there are no cleanups that need emitting. + if (isObviouslyBranchWithoutCleanups(Block)) { + llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext()); + SwitchInsn->addCase(llvm::ConstantInt::get(getLLVMContext(), CaseVal), + Block.getBlock()); + return; + } + } + EmitBlock(createBasicBlock("sw.bb")); llvm::BasicBlock *CaseDest = Builder.GetInsertBlock(); llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext()); |