1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4 declare i32 @llvm.ctlz.i32(i32, i1)
5 declare i32 @llvm.cttz.i32(i32, i1)
6 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32>, i1)
7 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32>, i1)
9 define i32 @lshr_ctlz_true(i32) {
10 ; CHECK-LABEL: define i32 @lshr_ctlz_true(
11 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
12 ; CHECK-NEXT: [[CTLZ:%.*]] = add i32 [[TMP0]], 9
13 ; CHECK-NEXT: ret i32 [[CTLZ]]
15 %lshr = lshr i32 8387584, %0
16 %ctlz = call i32 @llvm.ctlz.i32(i32 %lshr, i1 true)
20 define i32 @shl_nuw_ctlz_true(i32) {
21 ; CHECK-LABEL: define i32 @shl_nuw_ctlz_true(
22 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
23 ; CHECK-NEXT: [[CTLZ:%.*]] = sub i32 9, [[TMP0]]
24 ; CHECK-NEXT: ret i32 [[CTLZ]]
26 %shl = shl nuw i32 8387584, %0
27 %ctlz = call i32 @llvm.ctlz.i32(i32 %shl, i1 true)
31 define i32 @shl_nuw_nsw_ctlz_true(i32) {
32 ; CHECK-LABEL: define i32 @shl_nuw_nsw_ctlz_true(
33 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
34 ; CHECK-NEXT: [[CTLZ:%.*]] = sub i32 9, [[TMP0]]
35 ; CHECK-NEXT: ret i32 [[CTLZ]]
37 %shl = shl nuw nsw i32 8387584, %0
38 %ctlz = call i32 @llvm.ctlz.i32(i32 %shl, i1 true)
42 define i32 @lshr_exact_cttz_true(i32) {
43 ; CHECK-LABEL: define i32 @lshr_exact_cttz_true(
44 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
45 ; CHECK-NEXT: [[CTTZ:%.*]] = sub i32 10, [[TMP0]]
46 ; CHECK-NEXT: ret i32 [[CTTZ]]
48 %lshr = lshr exact i32 8387584, %0
49 %cttz = call i32 @llvm.cttz.i32(i32 %lshr, i1 true)
53 define i32 @shl_cttz_true(i32) {
54 ; CHECK-LABEL: define i32 @shl_cttz_true(
55 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
56 ; CHECK-NEXT: [[CTTZ:%.*]] = add i32 [[TMP0]], 10
57 ; CHECK-NEXT: ret i32 [[CTTZ]]
59 %shl = shl i32 8387584, %0
60 %cttz = call i32 @llvm.cttz.i32(i32 %shl, i1 true)
64 define <2 x i32> @vec2_lshr_ctlz_true(<2 x i32>) {
65 ; CHECK-LABEL: define <2 x i32> @vec2_lshr_ctlz_true(
66 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
67 ; CHECK-NEXT: [[CTLZ:%.*]] = add <2 x i32> [[TMP0]], <i32 9, i32 9>
68 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
70 %div = lshr <2 x i32> <i32 8387584, i32 4276440>, %0
71 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %div, i1 true)
75 define <2 x i32> @vec2_shl_nuw_ctlz_true(<2 x i32>) {
76 ; CHECK-LABEL: define <2 x i32> @vec2_shl_nuw_ctlz_true(
77 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
78 ; CHECK-NEXT: [[CTLZ:%.*]] = sub <2 x i32> <i32 9, i32 9>, [[TMP0]]
79 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
81 %shl = shl nuw <2 x i32> <i32 8387584, i32 4276440>, %0
82 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %shl, i1 true)
86 define <2 x i32> @vec2_shl_nuw_nsw_ctlz_true(<2 x i32>) {
87 ; CHECK-LABEL: define <2 x i32> @vec2_shl_nuw_nsw_ctlz_true(
88 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
89 ; CHECK-NEXT: [[CTLZ:%.*]] = sub <2 x i32> <i32 9, i32 9>, [[TMP0]]
90 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
92 %shl = shl nuw nsw <2 x i32> <i32 8387584, i32 4276440>, %0
93 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %shl, i1 true)
97 define <2 x i32> @vec2_lshr_exact_cttz_true(<2 x i32>) {
98 ; CHECK-LABEL: define <2 x i32> @vec2_lshr_exact_cttz_true(
99 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
100 ; CHECK-NEXT: [[CTTZ:%.*]] = sub <2 x i32> <i32 10, i32 3>, [[TMP0]]
101 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
103 %lshr = lshr exact <2 x i32> <i32 8387584, i32 4276440>, %0
104 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %lshr, i1 true)
108 define <2 x i32> @vec2_shl_cttz_true(<2 x i32>) {
109 ; CHECK-LABEL: define <2 x i32> @vec2_shl_cttz_true(
110 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
111 ; CHECK-NEXT: [[CTTZ:%.*]] = add <2 x i32> [[TMP0]], <i32 10, i32 3>
112 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
114 %shl = shl <2 x i32> <i32 8387584, i32 4276440>, %0
115 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %shl, i1 true)
121 define <2 x i32> @vec2_shl_nsw_ctlz_true_neg(<2 x i32>) {
122 ; CHECK-LABEL: define <2 x i32> @vec2_shl_nsw_ctlz_true_neg(
123 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
124 ; CHECK-NEXT: [[SHL:%.*]] = shl nsw <2 x i32> <i32 8387584, i32 4276440>, [[TMP0]]
125 ; CHECK-NEXT: [[CTLZ:%.*]] = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[SHL]], i1 true), !range [[RNG0:![0-9]+]]
126 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
128 %shl = shl nsw <2 x i32> <i32 8387584, i32 4276440>, %0
129 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %shl, i1 true)
133 define <2 x i32> @vec2_lshr_ctlz_false_neg(<2 x i32>) {
134 ; CHECK-LABEL: define <2 x i32> @vec2_lshr_ctlz_false_neg(
135 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
136 ; CHECK-NEXT: [[DIV:%.*]] = lshr <2 x i32> <i32 8387584, i32 4276440>, [[TMP0]]
137 ; CHECK-NEXT: [[CTLZ:%.*]] = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[DIV]], i1 false), !range [[RNG1:![0-9]+]]
138 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
140 %div = lshr <2 x i32> <i32 8387584, i32 4276440>, %0
141 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %div, i1 false)
145 define <2 x i32> @vec2_shl_ctlz_false_neg(<2 x i32>) {
146 ; CHECK-LABEL: define <2 x i32> @vec2_shl_ctlz_false_neg(
147 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
148 ; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 8387584, i32 4276440>, [[TMP0]]
149 ; CHECK-NEXT: [[CTLZ:%.*]] = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> [[SHL]], i1 false), !range [[RNG2:![0-9]+]]
150 ; CHECK-NEXT: ret <2 x i32> [[CTLZ]]
152 %shl = shl <2 x i32> <i32 8387584, i32 4276440>, %0
153 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %shl, i1 false)
157 define <2 x i32> @vec2_lshr_cttz_false_neg(<2 x i32>) {
158 ; CHECK-LABEL: define <2 x i32> @vec2_lshr_cttz_false_neg(
159 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
160 ; CHECK-NEXT: [[LSHR:%.*]] = lshr <2 x i32> <i32 8387584, i32 4276440>, [[TMP0]]
161 ; CHECK-NEXT: [[CTTZ:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[LSHR]], i1 false), !range [[RNG2]]
162 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
164 %lshr = lshr <2 x i32> <i32 8387584, i32 4276440>, %0
165 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %lshr, i1 false)
169 define <2 x i32> @vec2_shl_cttz_false_neg(<2 x i32>) {
170 ; CHECK-LABEL: define <2 x i32> @vec2_shl_cttz_false_neg(
171 ; CHECK-SAME: <2 x i32> [[TMP0:%.*]]) {
172 ; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 8387584, i32 4276440>, [[TMP0]]
173 ; CHECK-NEXT: [[CTTZ:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[SHL]], i1 false), !range [[RNG3:![0-9]+]]
174 ; CHECK-NEXT: ret <2 x i32> [[CTTZ]]
176 %shl = shl <2 x i32> <i32 8387584, i32 4276440>, %0
177 %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %shl, i1 false)
181 define i32 @lshr_ctlz_faslse_neg(i32) {
182 ; CHECK-LABEL: define i32 @lshr_ctlz_faslse_neg(
183 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
184 ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 8387584, [[TMP0]]
185 ; CHECK-NEXT: [[CTLZ:%.*]] = call i32 @llvm.ctlz.i32(i32 [[LSHR]], i1 false), !range [[RNG1]]
186 ; CHECK-NEXT: ret i32 [[CTLZ]]
188 %lshr = lshr i32 8387584, %0
189 %ctlz = call i32 @llvm.ctlz.i32(i32 %lshr, i1 false)
193 define i32 @shl_ctlz_false_neg(i32) {
194 ; CHECK-LABEL: define i32 @shl_ctlz_false_neg(
195 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
196 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 8387584, [[TMP0]]
197 ; CHECK-NEXT: [[CTLZ:%.*]] = call i32 @llvm.ctlz.i32(i32 [[SHL]], i1 false), !range [[RNG2]]
198 ; CHECK-NEXT: ret i32 [[CTLZ]]
200 %shl = shl i32 8387584, %0
201 %ctlz = call i32 @llvm.ctlz.i32(i32 %shl, i1 false)
205 define i32 @lshr_cttz_false_neg(i32) {
206 ; CHECK-LABEL: define i32 @lshr_cttz_false_neg(
207 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
208 ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 8387584, [[TMP0]]
209 ; CHECK-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[LSHR]], i1 false), !range [[RNG2]]
210 ; CHECK-NEXT: ret i32 [[CTTZ]]
212 %lshr = lshr i32 8387584, %0
213 %cttz = call i32 @llvm.cttz.i32(i32 %lshr, i1 false)
217 define i32 @shl_cttz_false_neg(i32) {
218 ; CHECK-LABEL: define i32 @shl_cttz_false_neg(
219 ; CHECK-SAME: i32 [[TMP0:%.*]]) {
220 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 8387584, [[TMP0]]
221 ; CHECK-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[SHL]], i1 false), !range [[RNG4:![0-9]+]]
222 ; CHECK-NEXT: ret i32 [[CTTZ]]
224 %shl = shl i32 8387584, %0
225 %cttz = call i32 @llvm.cttz.i32(i32 %shl, i1 false)
229 ; CHECK: [[RNG0]] = !{i32 1, i32 33}
230 ; CHECK: [[RNG1]] = !{i32 9, i32 33}
231 ; CHECK: [[RNG2]] = !{i32 0, i32 33}
232 ; CHECK: [[RNG3]] = !{i32 3, i32 33}
233 ; CHECK: [[RNG4]] = !{i32 10, i32 33}