diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 59d96bee1c9..accfbee9dfb 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -582,6 +582,10 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI, } if (SwitchInst *SI = dyn_cast(&TI)) { + if (TI.getNumSuccessors() < 2) { + Succs[0] = true; + return; + } LatticeVal SCValue = getValueState(SI->getCondition()); ConstantInt *CI = SCValue.getConstantInt(); @@ -642,6 +646,9 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) { return true; if (SwitchInst *SI = dyn_cast(TI)) { + if (SI->getNumSuccessors() < 2) + return true; + LatticeVal SCValue = getValueState(SI->getCondition()); ConstantInt *CI = SCValue.getConstantInt(); diff --git a/test/Transforms/SCCP/switch.ll b/test/Transforms/SCCP/switch.ll new file mode 100644 index 00000000000..9f934237e61 --- /dev/null +++ b/test/Transforms/SCCP/switch.ll @@ -0,0 +1,13 @@ +; RUN: opt -S -sccp < %s | FileCheck %s + +; Make sure we always consider the default edge executable for a switch +; with no cases. +declare void @foo() +define void @test1() { +; CHECK: define void @test1 +; CHECK: call void @foo() + switch i32 undef, label %d [] +d: + call void @foo() + ret void +}