1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
; RUN: opt %s -simplifycfg -S | FileCheck %s
declare i32 @f(i32)
define i32 @basic(i32 %x) {
; CHECK-LABEL: @basic
; CHECK: x.off = add i32 %x, -5
; CHECK: %switch = icmp ult i32 %x.off, 3
; CHECK: br i1 %switch, label %a, label %default
entry:
switch i32 %x, label %default [
i32 5, label %a
i32 6, label %a
i32 7, label %a
]
default:
%0 = call i32 @f(i32 0)
ret i32 %0
a:
%1 = call i32 @f(i32 1)
ret i32 %1
}
define i32 @unreachable(i32 %x) {
; CHECK-LABEL: @unreachable
; CHECK: x.off = add i32 %x, -5
; CHECK: %switch = icmp ult i32 %x.off, 3
; CHECK: br i1 %switch, label %a, label %b
entry:
switch i32 %x, label %unreachable [
i32 5, label %a
i32 6, label %a
i32 7, label %a
i32 10, label %b
i32 20, label %b
i32 30, label %b
i32 40, label %b
]
unreachable:
unreachable
a:
%0 = call i32 @f(i32 0)
ret i32 %0
b:
%1 = call i32 @f(i32 1)
ret i32 %1
}
define i32 @unreachable2(i32 %x) {
; CHECK-LABEL: @unreachable2
; CHECK: x.off = add i32 %x, -5
; CHECK: %switch = icmp ult i32 %x.off, 3
; CHECK: br i1 %switch, label %a, label %b
entry:
; Note: folding the most popular case destination into the default
; would prevent switch-to-icmp here.
switch i32 %x, label %unreachable [
i32 5, label %a
i32 6, label %a
i32 7, label %a
i32 10, label %b
i32 20, label %b
]
unreachable:
unreachable
a:
%0 = call i32 @f(i32 0)
ret i32 %0
b:
%1 = call i32 @f(i32 1)
ret i32 %1
}
|