1 ; RUN: opt %s -S -simplifycfg | FileCheck %s
4 define void @test(i1 %a) {
6 ; CHECK: br i1 [[IGNORE:%.*]], label %true, label %false
7 switch i1 %a, label %default [i1 1, label %true
20 define void @test2(i2 %a) {
22 switch i2 %a, label %default [i2 0, label %case0
39 ; CHECK-LABEL: default1:
40 ; CHECK-NEXT: unreachable
45 ; This one is a negative test - we know the value of the default,
47 define void @test3(i2 %a) {
49 switch i2 %a, label %default [i2 0, label %case0
63 ; CHECK-LABEL: default:
64 ; CHECK-NEXT: call void @foo
69 ; Negative test - check for possible overflow when computing
70 ; number of possible cases.
71 define void @test4(i128 %a) {
73 switch i128 %a, label %default [i128 0, label %case0
83 ; CHECK-LABEL: default:
84 ; CHECK-NEXT: call void @foo
89 ; All but one bit known zero
90 define void @test5(i8 %a) {
92 ; CHECK: br i1 [[IGNORE:%.*]], label %true, label %false
93 %cmp = icmp ult i8 %a, 2
94 call void @llvm.assume(i1 %cmp)
95 switch i8 %a, label %default [i8 1, label %true
101 call void @foo(i32 3)
104 call void @foo(i32 2)
108 ;; All but one bit known one
109 define void @test6(i8 %a) {
110 ; CHECK-LABEL: @test6
111 ; CHECK: @llvm.assume
112 ; CHECK: br i1 [[IGNORE:%.*]], label %true, label %false
113 %and = and i8 %a, 254
114 %cmp = icmp eq i8 %and, 254
115 call void @llvm.assume(i1 %cmp)
116 switch i8 %a, label %default [i8 255, label %true
117 i8 254, label %false]
119 call void @foo(i32 1)
122 call void @foo(i32 3)
125 call void @foo(i32 2)
129 ; Check that we can eliminate both dead cases and dead defaults
130 ; within a single run of simplify-cfg
131 define void @test7(i8 %a) {
132 ; CHECK-LABEL: @test7
133 ; CHECK: @llvm.assume
134 ; CHECK: br i1 [[IGNORE:%.*]], label %true, label %false
135 %and = and i8 %a, 254
136 %cmp = icmp eq i8 %and, 254
137 call void @llvm.assume(i1 %cmp)
138 switch i8 %a, label %default [i8 255, label %true
140 i8 0, label %also_dead]
142 call void @foo(i32 1)
145 call void @foo(i32 3)
148 call void @foo(i32 5)
151 call void @foo(i32 2)
155 ;; All but one bit known undef
156 ;; Note: This is currently testing an optimization which doesn't trigger. The
157 ;; case this is protecting against is that a bit could be assumed both zero
158 ;; *or* one given we know it's undef. ValueTracking doesn't do this today,
159 ;; but it doesn't hurt to confirm.
160 define void @test8(i8 %a) {
161 ; CHECK-LABEL: @test8(
163 %and = and i8 %a, 254
164 %cmp = icmp eq i8 %and, undef
165 call void @llvm.assume(i1 %cmp)
166 switch i8 %a, label %default [i8 255, label %true
167 i8 254, label %false]
169 call void @foo(i32 1)
172 call void @foo(i32 3)
175 call void @foo(i32 2)
179 declare void @llvm.assume(i1)