[llvm] r222961 - Switch lowering: Fix broken 'Figure out which block is next' code
Hans Wennborg
hans at hanshq.net
Sat Nov 29 13:17:06 PST 2014
Author: hans
Date: Sat Nov 29 15:17:05 2014
New Revision: 222961
URL: http://llvm.org/viewvc/llvm-project?rev=222961&view=rev
Log:
Switch lowering: Fix broken 'Figure out which block is next' code
This doesn't seem to have worked in a long time, but other optimizations
would clean it up.
Added:
llvm/trunk/test/CodeGen/X86/switch-default-only.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/trunk/test/DebugInfo/unconditional-branch.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=222961&r1=222960&r2=222961&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Sat Nov 29 15:17:05 2014
@@ -2694,6 +2694,9 @@ void SelectionDAGBuilder::visitSwitch(co
// Figure out which block is immediately after the current one.
MachineBasicBlock *NextBlock = nullptr;
+ if (SwitchMBB + 1 != FuncInfo.MF->end())
+ NextBlock = SwitchMBB + 1;
+
MachineBasicBlock *Default = FuncInfo.MBBMap[SI.getDefaultDest()];
// If there is only the default destination, branch to it if it is not the
Added: llvm/trunk/test/CodeGen/X86/switch-default-only.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/switch-default-only.ll?rev=222961&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/switch-default-only.ll (added)
+++ llvm/trunk/test/CodeGen/X86/switch-default-only.ll Sat Nov 29 15:17:05 2014
@@ -0,0 +1,14 @@
+; RUN: llc -O0 -fast-isel=false -march=x86 < %s | FileCheck %s
+
+; No need for branching when the default and only destination follows
+; immediately after the switch.
+; CHECK-LABEL: no_branch:
+; CHECK-NOT: jmp
+; CHECK: ret
+
+define void @no_branch(i32 %x) {
+entry:
+ switch i32 %x, label %exit [ ]
+exit:
+ ret void
+}
Modified: llvm/trunk/test/DebugInfo/unconditional-branch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/unconditional-branch.ll?rev=222961&r1=222960&r2=222961&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/unconditional-branch.ll (original)
+++ llvm/trunk/test/DebugInfo/unconditional-branch.ll Sat Nov 29 15:17:05 2014
@@ -27,11 +27,12 @@ entry:
switch i32 %0, label %sw.default [
], !dbg !14
+sw.epilog: ; preds = %sw.default
+ ret void, !dbg !17
+
sw.default: ; preds = %entry
br label %sw.epilog, !dbg !15
-sw.epilog: ; preds = %sw.default
- ret void, !dbg !17
}
; Function Attrs: nounwind readnone
More information about the llvm-commits
mailing list