1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
6 declare i32 @llvm.ctlz.i32(i32, i1)
7 declare <3 x i17> @llvm.ctlz.v3i17(<3 x i17>, i1)
9 declare i32 @llvm.cttz.i32(i32, i1)
10 declare <3 x i5> @llvm.cttz.v3i5(<3 x i5>, i1)
12 declare i32 @llvm.ctpop.i32(i32)
13 declare <3 x i7> @llvm.ctpop.v3i7(<3 x i7>)
15 define i32 @ctlz_sel_const_true_false(i1 %b) {
16 ; CHECK-LABEL: @ctlz_sel_const_true_false(
17 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i32 29, i32 0
18 ; CHECK-NEXT: ret i32 [[C]]
20 %s = select i1 %b, i32 5, i32 -7
21 %c = call i32 @llvm.ctlz.i32(i32 %s, i1 true)
25 define i32 @ctlz_sel_const_true(i1 %b, i32 %x) {
26 ; CHECK-LABEL: @ctlz_sel_const_true(
27 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 false), !range [[RNG0:![0-9]+]]
28 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i32 29, i32 [[TMP1]]
29 ; CHECK-NEXT: ret i32 [[C]]
31 %s = select i1 %b, i32 5, i32 %x
32 %c = call i32 @llvm.ctlz.i32(i32 %s, i1 false)
36 define <3 x i17> @ctlz_sel_const_false(<3 x i1> %b, <3 x i17> %x) {
37 ; CHECK-LABEL: @ctlz_sel_const_false(
38 ; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i17> @llvm.ctlz.v3i17(<3 x i17> [[X:%.*]], i1 true)
39 ; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i17> [[TMP1]], <3 x i17> <i17 14, i17 0, i17 undef>
40 ; CHECK-NEXT: ret <3 x i17> [[C]]
42 %s = select <3 x i1> %b, <3 x i17> %x, <3 x i17> <i17 7, i17 -1, i17 0>
43 %c = call <3 x i17> @llvm.ctlz.v3i17(<3 x i17> %s, i1 true)
47 define i32 @ctlz_sel_const_true_false_extra_use(i1 %b) {
48 ; CHECK-LABEL: @ctlz_sel_const_true_false_extra_use(
49 ; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 -1, i32 7
50 ; CHECK-NEXT: call void @use(i32 [[S]])
51 ; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctlz.i32(i32 [[S]], i1 true), !range [[RNG1:![0-9]+]]
52 ; CHECK-NEXT: ret i32 [[C]]
54 %s = select i1 %b, i32 -1, i32 7
55 call void @use(i32 %s)
56 %c = call i32 @llvm.ctlz.i32(i32 %s, i1 false)
60 define i32 @cttz_sel_const_true_false(i1 %b) {
61 ; CHECK-LABEL: @cttz_sel_const_true_false(
62 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i32 2, i32 0
63 ; CHECK-NEXT: ret i32 [[C]]
65 %s = select i1 %b, i32 4, i32 -7
66 %c = call i32 @llvm.cttz.i32(i32 %s, i1 false)
70 define i32 @cttz_sel_const_true(i1 %b, i32 %x) {
71 ; CHECK-LABEL: @cttz_sel_const_true(
72 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true), !range [[RNG0]]
73 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i32 0, i32 [[TMP1]]
74 ; CHECK-NEXT: ret i32 [[C]]
76 %s = select i1 %b, i32 5, i32 %x
77 %c = call i32 @llvm.cttz.i32(i32 %s, i1 true)
81 define <3 x i5> @cttz_sel_const_false(<3 x i1> %b, <3 x i5> %x) {
82 ; CHECK-LABEL: @cttz_sel_const_false(
83 ; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i5> @llvm.cttz.v3i5(<3 x i5> [[X:%.*]], i1 false)
84 ; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i5> [[TMP1]], <3 x i5> <i5 0, i5 0, i5 5>
85 ; CHECK-NEXT: ret <3 x i5> [[C]]
87 %s = select <3 x i1> %b, <3 x i5> %x, <3 x i5> <i5 7, i5 -1, i5 0>
88 %c = call <3 x i5> @llvm.cttz.v3i5(<3 x i5> %s, i1 false)
92 define i32 @cttz_sel_const_true_false_extra_use(i1 %b) {
93 ; CHECK-LABEL: @cttz_sel_const_true_false_extra_use(
94 ; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 5, i32 -8
95 ; CHECK-NEXT: call void @use(i32 [[S]])
96 ; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.cttz.i32(i32 [[S]], i1 true), !range [[RNG0]]
97 ; CHECK-NEXT: ret i32 [[C]]
99 %s = select i1 %b, i32 5, i32 -8
100 call void @use(i32 %s)
101 %c = call i32 @llvm.cttz.i32(i32 %s, i1 true)
105 define i32 @ctpop_sel_const_true_false(i1 %b) {
106 ; CHECK-LABEL: @ctpop_sel_const_true_false(
107 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i32 2, i32 30
108 ; CHECK-NEXT: ret i32 [[C]]
110 %s = select i1 %b, i32 5, i32 -7
111 %c = call i32 @llvm.ctpop.i32(i32 %s)
115 define i32 @ctpop_sel_const_true(i1 %b, i32 %x) {
116 ; CHECK-LABEL: @ctpop_sel_const_true(
117 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range [[RNG0]]
118 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i32 2, i32 [[TMP1]]
119 ; CHECK-NEXT: ret i32 [[C]]
121 %s = select i1 %b, i32 5, i32 %x
122 %c = call i32 @llvm.ctpop.i32(i32 %s)
126 define <3 x i7> @ctpop_sel_const_false(<3 x i1> %b, <3 x i7> %x) {
127 ; CHECK-LABEL: @ctpop_sel_const_false(
128 ; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i7> @llvm.ctpop.v3i7(<3 x i7> [[X:%.*]])
129 ; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i7> [[TMP1]], <3 x i7> <i7 3, i7 7, i7 0>
130 ; CHECK-NEXT: ret <3 x i7> [[C]]
132 %s = select <3 x i1> %b, <3 x i7> %x, <3 x i7> <i7 7, i7 -1, i7 0>
133 %c = call <3 x i7> @llvm.ctpop.v3i7(<3 x i7> %s)
137 define i32 @ctpop_sel_const_true_false_extra_use(i1 %b) {
138 ; CHECK-LABEL: @ctpop_sel_const_true_false_extra_use(
139 ; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 5, i32 7
140 ; CHECK-NEXT: call void @use(i32 [[S]])
141 ; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctpop.i32(i32 [[S]]), !range [[RNG2:![0-9]+]]
142 ; CHECK-NEXT: ret i32 [[C]]
144 %s = select i1 %b, i32 5, i32 7
145 call void @use(i32 %s)
146 %c = call i32 @llvm.ctpop.i32(i32 %s)