1 ; RUN: opt %s -passes=lowerswitch -S | FileCheck %s
3 define void @foo(i32 %x, ptr %p) {
4 ; Cases 2 and 4 are removed and become the new default case.
5 ; It is now enough to use two icmps to lower the switch.
8 ; CHECK: icmp slt i32 %x, 5
9 ; CHECK: icmp eq i32 %x, 1
13 switch i32 %x, label %default [
34 define void @unreachable_gap(i64 %x, ptr %p) {
35 ; Cases 6 and INT64_MAX become the new default, but we still exploit the fact
36 ; that 3-4 is unreachable, so four icmps is enough.
38 ; CHECK-LABEL: @unreachable_gap
39 ; CHECK: icmp slt i64 %x, 2
40 ; CHECK: icmp slt i64 %x, 5
41 ; CHECK: icmp eq i64 %x, 5
42 ; CHECK: icmp slt i64 %x, 1
46 switch i64 %x, label %default [
47 i64 -9223372036854775808, label %bb0
52 i64 9223372036854775807, label %bb4
77 define void @nocases(i32 %x, ptr %p) {
78 ; Don't fall over when there are no cases.
80 ; CHECK-LABEL: @nocases
82 ; CHECK-NEXT: br label %default
85 switch i32 %x, label %default [
91 define void @nocasesleft(i32 %x, ptr %p) {
92 ; Cases 2 and 4 are removed and we are left with no cases.
94 ; CHECK-LABEL: @nocasesleft
96 ; CHECK-NEXT: br label %popular
99 switch i32 %x, label %default [
100 i32 2, label %popular
101 i32 4, label %popular