diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index e037108c2b44..5e9bc0da871b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -9237,7 +9237,8 @@ void SelectionDAGBuilder::visitSwitch(const SwitchInst &SI) { WorkList.pop_back(); unsigned NumClusters = W.LastCluster - W.FirstCluster + 1; - if (NumClusters > 3 && TM.getOptLevel() != CodeGenOpt::None) { + if (NumClusters > 3 && TM.getOptLevel() != CodeGenOpt::None && + !DefaultMBB->getParent()->getFunction()->optForMinSize()) { // For optimized builds, lower large range as a balanced binary tree. splitWorkItem(WorkList, W, SI.getCondition(), SwitchMBB); continue; diff --git a/llvm/test/CodeGen/ARM/switch-minsize.ll b/llvm/test/CodeGen/ARM/switch-minsize.ll new file mode 100644 index 000000000000..92af6b35c3c5 --- /dev/null +++ b/llvm/test/CodeGen/ARM/switch-minsize.ll @@ -0,0 +1,34 @@ +; RUN: llc < %s | FileCheck %s + +target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32" +target triple = "thumbv7-apple-ios8.0.0" + +; CHECK: beq +; CHECK: beq +; CHECK: beq +; CHECK: cbnz +declare void @g(i32) +define void @f(i32 %val) optsize minsize { + switch i32 %val, label %def [ + i32 0, label %one + i32 9, label %two + i32 994, label %three + i32 1154, label %four + ] + +one: + call void @g(i32 1) + ret void +two: + call void @g(i32 001) + ret void +three: + call void @g(i32 78) + ret void +four: + call void @g(i32 87) + ret void +def: + call void @g(i32 11) + ret void +}