1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @test_switch_with_shl_mask(i32 %a) {
5 ; CHECK-LABEL: define i1 @test_switch_with_shl_mask(
6 ; CHECK-SAME: i32 [[A:%.*]]) {
8 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[A]] to i8
9 ; CHECK-NEXT: switch i8 [[TRUNC]], label [[SW_DEFAULT:%.*]] [
10 ; CHECK-NEXT: i8 0, label [[SW_BB:%.*]]
11 ; CHECK-NEXT: i8 1, label [[SW_BB]]
12 ; CHECK-NEXT: i8 -128, label [[SW_BB]]
15 ; CHECK-NEXT: ret i1 true
17 ; CHECK-NEXT: ret i1 false
21 switch i32 %b, label %sw.default [
23 i32 16777216, label %sw.bb
24 i32 2147483648, label %sw.bb
33 define i1 @test_switch_with_shl_nuw_multiuse(i32 %a) {
34 ; CHECK-LABEL: define i1 @test_switch_with_shl_nuw_multiuse(
35 ; CHECK-SAME: i32 [[A:%.*]]) {
37 ; CHECK-NEXT: [[B:%.*]] = shl nuw i32 [[A]], 24
38 ; CHECK-NEXT: call void @use(i32 [[B]])
39 ; CHECK-NEXT: switch i32 [[A]], label [[SW_DEFAULT:%.*]] [
40 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
41 ; CHECK-NEXT: i32 1, label [[SW_BB]]
42 ; CHECK-NEXT: i32 128, label [[SW_BB]]
45 ; CHECK-NEXT: ret i1 true
47 ; CHECK-NEXT: ret i1 false
50 %b = shl nuw i32 %a, 24
51 call void @use(i32 %b)
52 switch i32 %b, label %sw.default [
54 i32 16777216, label %sw.bb
55 i32 2147483648, label %sw.bb
64 define i1 @test_switch_with_shl_nsw_multiuse(i32 %a) {
65 ; CHECK-LABEL: define i1 @test_switch_with_shl_nsw_multiuse(
66 ; CHECK-SAME: i32 [[A:%.*]]) {
68 ; CHECK-NEXT: [[B:%.*]] = shl nsw i32 [[A]], 24
69 ; CHECK-NEXT: call void @use(i32 [[B]])
70 ; CHECK-NEXT: switch i32 [[A]], label [[SW_DEFAULT:%.*]] [
71 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
72 ; CHECK-NEXT: i32 1, label [[SW_BB]]
73 ; CHECK-NEXT: i32 -128, label [[SW_BB]]
76 ; CHECK-NEXT: ret i1 true
78 ; CHECK-NEXT: ret i1 false
81 %b = shl nsw i32 %a, 24
82 call void @use(i32 %b)
83 switch i32 %b, label %sw.default [
85 i32 16777216, label %sw.bb
86 i32 2147483648, label %sw.bb
97 define i1 @test_switch_with_shl_mask_multiuse(i32 %a) {
98 ; CHECK-LABEL: define i1 @test_switch_with_shl_mask_multiuse(
99 ; CHECK-SAME: i32 [[A:%.*]]) {
101 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[A]], 24
102 ; CHECK-NEXT: call void @use(i32 [[B]])
103 ; CHECK-NEXT: switch i32 [[B]], label [[SW_DEFAULT:%.*]] [
104 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
105 ; CHECK-NEXT: i32 16777216, label [[SW_BB]]
106 ; CHECK-NEXT: i32 -2147483648, label [[SW_BB]]
109 ; CHECK-NEXT: ret i1 true
111 ; CHECK-NEXT: ret i1 false
115 call void @use(i32 %b)
116 switch i32 %b, label %sw.default [
118 i32 16777216, label %sw.bb
119 i32 2147483648, label %sw.bb
128 define i1 @test_switch_with_shl_mask_unknown_shamt(i32 %a, i32 %shamt) {
129 ; CHECK-LABEL: define i1 @test_switch_with_shl_mask_unknown_shamt(
130 ; CHECK-SAME: i32 [[A:%.*]], i32 [[SHAMT:%.*]]) {
132 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[A]], [[SHAMT]]
133 ; CHECK-NEXT: switch i32 [[B]], label [[SW_DEFAULT:%.*]] [
134 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
135 ; CHECK-NEXT: i32 16777216, label [[SW_BB]]
136 ; CHECK-NEXT: i32 -2147483648, label [[SW_BB]]
139 ; CHECK-NEXT: ret i1 true
141 ; CHECK-NEXT: ret i1 false
144 %b = shl i32 %a, %shamt
145 switch i32 %b, label %sw.default [
147 i32 16777216, label %sw.bb
148 i32 2147483648, label %sw.bb
157 define i1 @test_switch_with_shl_mask_poison(i32 %a) {
158 ; CHECK-LABEL: define i1 @test_switch_with_shl_mask_poison(
159 ; CHECK-SAME: i32 [[A:%.*]]) {
161 ; CHECK-NEXT: switch i32 poison, label [[SW_DEFAULT:%.*]] [
162 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
163 ; CHECK-NEXT: i32 16777216, label [[SW_BB]]
164 ; CHECK-NEXT: i32 -2147483648, label [[SW_BB]]
167 ; CHECK-NEXT: ret i1 true
169 ; CHECK-NEXT: ret i1 false
173 switch i32 %b, label %sw.default [
175 i32 16777216, label %sw.bb
176 i32 2147483648, label %sw.bb
185 declare void @use(i32)