1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 define i32 @cttz_abs(i32 %x) {
5 ; CHECK-LABEL: @cttz_abs(
6 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true), !range !0
7 ; CHECK-NEXT: ret i32 [[R]]
9 %c = icmp slt i32 %x, 0
11 %d = select i1 %c, i32 %s, i32 %x
12 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
16 define <2 x i64> @cttz_abs_vec(<2 x i64> %x) {
17 ; CHECK-LABEL: @cttz_abs_vec(
18 ; CHECK-NEXT: [[R:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[X:%.*]], i1 false)
19 ; CHECK-NEXT: ret <2 x i64> [[R]]
21 %c = icmp slt <2 x i64> %x, zeroinitializer
22 %s = sub <2 x i64> zeroinitializer, %x
23 %d = select <2 x i1> %c, <2 x i64> %s, <2 x i64> %x
24 %r = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %d)
28 define i32 @cttz_abs2(i32 %x) {
29 ; CHECK-LABEL: @cttz_abs2(
30 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], 0
31 ; CHECK-NEXT: call void @use_cond(i1 [[C]])
32 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true), !range !0
33 ; CHECK-NEXT: ret i32 [[R]]
35 %c = icmp sgt i32 %x, 0
36 call void @use_cond(i1 %c)
38 %d = select i1 %c, i32 %x, i32 %s
39 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
43 define i32 @cttz_abs3(i32 %x) {
44 ; CHECK-LABEL: @cttz_abs3(
45 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], -1
46 ; CHECK-NEXT: call void @use_cond(i1 [[C]])
47 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true), !range !0
48 ; CHECK-NEXT: ret i32 [[R]]
50 %c = icmp sgt i32 %x, -1
51 call void @use_cond(i1 %c)
53 %d = select i1 %c, i32 %x, i32 %s
54 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
58 define i32 @cttz_abs4(i32 %x) {
59 ; CHECK-LABEL: @cttz_abs4(
60 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true), !range !0
61 ; CHECK-NEXT: ret i32 [[R]]
63 %c = icmp slt i32 %x, 1
65 %d = select i1 %c, i32 %s, i32 %x
66 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
70 define i32 @cttz_nabs(i32 %x) {
71 ; CHECK-LABEL: @cttz_nabs(
72 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range !0
73 ; CHECK-NEXT: ret i32 [[R]]
75 %c = icmp slt i32 %x, 0
77 %d = select i1 %c, i32 %x, i32 %s
78 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 false)
82 define <2 x i64> @cttz_nabs_vec(<2 x i64> %x) {
83 ; CHECK-LABEL: @cttz_nabs_vec(
84 ; CHECK-NEXT: [[R:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[X:%.*]], i1 false)
85 ; CHECK-NEXT: ret <2 x i64> [[R]]
87 %c = icmp slt <2 x i64> %x, zeroinitializer
88 %s = sub <2 x i64> zeroinitializer, %x
89 %d = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %s
90 %r = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %d)
94 define i64 @cttz_abs_64(i64 %x) {
95 ; CHECK-LABEL: @cttz_abs_64(
96 ; CHECK-NEXT: [[R:%.*]] = call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 false), !range !1
97 ; CHECK-NEXT: ret i64 [[R]]
99 %c = icmp slt i64 %x, 0
101 %d = select i1 %c, i64 %s, i64 %x
102 %r = tail call i64 @llvm.cttz.i64(i64 %d)
106 define i32 @cttz_abs_multiuse(i32 %x) {
107 ; CHECK-LABEL: @cttz_abs_multiuse(
108 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 0
109 ; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X]]
110 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[S]], i32 [[X]]
111 ; CHECK-NEXT: call void @use_abs(i32 [[D]])
112 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true), !range !0
113 ; CHECK-NEXT: ret i32 [[R]]
115 %c = icmp slt i32 %x, 1
117 %d = select i1 %c, i32 %s, i32 %x
118 call void @use_abs(i32 %d)
119 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
123 define i32 @cttz_nabs_multiuse(i32 %x) {
124 ; CHECK-LABEL: @cttz_nabs_multiuse(
125 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 0
126 ; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X]]
127 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[S]]
128 ; CHECK-NEXT: call void @use_abs(i32 [[D]])
129 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true), !range !0
130 ; CHECK-NEXT: ret i32 [[R]]
132 %c = icmp slt i32 %x, 1
134 %d = select i1 %c, i32 %x, i32 %s
135 call void @use_abs(i32 %d)
136 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
142 define i32 @no_cttz_abs(i32 %x) {
143 ; CHECK-LABEL: @no_cttz_abs(
144 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 2
145 ; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X]]
146 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[S]], i32 [[X]]
147 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[D]], i1 true), !range !0
148 ; CHECK-NEXT: ret i32 [[R]]
150 %c = icmp slt i32 %x, 2
152 %d = select i1 %c, i32 %s, i32 %x
153 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
157 define i32 @no_cttz_abs2(i32 %x) {
158 ; CHECK-LABEL: @no_cttz_abs2(
159 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 0
160 ; CHECK-NEXT: [[S:%.*]] = sub i32 1, [[X]]
161 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[S]], i32 [[X]]
162 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[D]], i1 true), !range !0
163 ; CHECK-NEXT: ret i32 [[R]]
165 %c = icmp slt i32 %x, 0
167 %d = select i1 %c, i32 %s, i32 %x
168 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
172 define i32 @no_cttz_abs3(i32 %x) {
173 ; CHECK-LABEL: @no_cttz_abs3(
174 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], -2
175 ; CHECK-NEXT: call void @use_cond(i1 [[C]])
176 ; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X]]
177 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[S]]
178 ; CHECK-NEXT: [[R:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[D]], i1 true), !range !0
179 ; CHECK-NEXT: ret i32 [[R]]
181 %c = icmp sgt i32 %x, -2
182 call void @use_cond(i1 %c)
184 %d = select i1 %c, i32 %x, i32 %s
185 %r = tail call i32 @llvm.cttz.i32(i32 %d, i1 true)
189 define <2 x i64> @no_cttz_abs_vec(<2 x i64> %x) {
190 ; CHECK-LABEL: @no_cttz_abs_vec(
191 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i64> [[X:%.*]], <i64 2, i64 1>
192 ; CHECK-NEXT: [[S:%.*]] = sub <2 x i64> <i64 1, i64 0>, [[X]]
193 ; CHECK-NEXT: [[D:%.*]] = select <2 x i1> [[C]], <2 x i64> [[S]], <2 x i64> [[X]]
194 ; CHECK-NEXT: [[R:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[D]], i1 false)
195 ; CHECK-NEXT: ret <2 x i64> [[R]]
197 %c = icmp slt <2 x i64> %x, <i64 2, i64 1>
198 %s = sub <2 x i64> <i64 1, i64 0>, %x
199 %d = select <2 x i1> %c, <2 x i64> %s, <2 x i64> %x
200 %r = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %d)
204 define <2 x i64> @no_cttz_nabs_vec(<2 x i64> %x) {
205 ; CHECK-LABEL: @no_cttz_nabs_vec(
206 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i64> [[X:%.*]], <i64 2, i64 1>
207 ; CHECK-NEXT: [[S:%.*]] = sub <2 x i64> <i64 1, i64 0>, [[X]]
208 ; CHECK-NEXT: [[D:%.*]] = select <2 x i1> [[C]], <2 x i64> [[X]], <2 x i64> [[S]]
209 ; CHECK-NEXT: [[R:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[D]], i1 false)
210 ; CHECK-NEXT: ret <2 x i64> [[R]]
212 %c = icmp slt <2 x i64> %x, <i64 2, i64 1>
213 %s = sub <2 x i64> <i64 1, i64 0>, %x
214 %d = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %s
215 %r = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %d)
220 declare void @use_cond(i1)
221 declare void @use_abs(i32)
222 declare i32 @llvm.cttz.i32(i32, i1)
223 declare i64 @llvm.cttz.i64(i64)
224 declare <2 x i64> @llvm.cttz.v2i64(<2 x i64>)