1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -instcombine | FileCheck %s
4 declare i32 @llvm.cttz.i32(i32, i1)
5 declare <2 x i64> @llvm.cttz.v2i64(<2 x i64>, i1)
8 define i32 @cttz_zext_zero_undef(i16 %x) {
9 ; CHECK-LABEL: @cttz_zext_zero_undef(
10 ; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.cttz.i16(i16 [[X:%.*]], i1 true), !range [[RNG0:![0-9]+]]
11 ; CHECK-NEXT: [[TMP2:%.*]] = zext i16 [[TMP1]] to i32
12 ; CHECK-NEXT: ret i32 [[TMP2]]
14 %z = zext i16 %x to i32
15 %tz = call i32 @llvm.cttz.i32(i32 %z, i1 true)
19 define i32 @cttz_zext_zero_def(i16 %x) {
20 ; CHECK-LABEL: @cttz_zext_zero_def(
21 ; CHECK-NEXT: [[Z:%.*]] = zext i16 [[X:%.*]] to i32
22 ; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[Z]], i1 false), !range [[RNG1:![0-9]+]]
23 ; CHECK-NEXT: ret i32 [[TZ]]
25 %z = zext i16 %x to i32
26 %tz = call i32 @llvm.cttz.i32(i32 %z, i1 false)
30 define i32 @cttz_zext_zero_undef_extra_use(i16 %x) {
31 ; CHECK-LABEL: @cttz_zext_zero_undef_extra_use(
32 ; CHECK-NEXT: [[Z:%.*]] = zext i16 [[X:%.*]] to i32
33 ; CHECK-NEXT: call void @use(i32 [[Z]])
34 ; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[Z]], i1 true), !range [[RNG1]]
35 ; CHECK-NEXT: ret i32 [[TZ]]
37 %z = zext i16 %x to i32
38 call void @use(i32 %z)
39 %tz = call i32 @llvm.cttz.i32(i32 %z, i1 true)
43 define <2 x i64> @cttz_zext_zero_undef_vec(<2 x i32> %x) {
44 ; CHECK-LABEL: @cttz_zext_zero_undef_vec(
45 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[X:%.*]], i1 true)
46 ; CHECK-NEXT: [[TMP2:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
47 ; CHECK-NEXT: ret <2 x i64> [[TMP2]]
49 %z = zext <2 x i32> %x to <2 x i64>
50 %tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %z, i1 true)
54 define <2 x i64> @cttz_zext_zero_def_vec(<2 x i32> %x) {
55 ; CHECK-LABEL: @cttz_zext_zero_def_vec(
56 ; CHECK-NEXT: [[Z:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
57 ; CHECK-NEXT: [[TZ:%.*]] = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[Z]], i1 false)
58 ; CHECK-NEXT: ret <2 x i64> [[TZ]]
60 %z = zext <2 x i32> %x to <2 x i64>
61 %tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %z, i1 false)
65 define i32 @cttz_sext_zero_undef(i16 %x) {
66 ; CHECK-LABEL: @cttz_sext_zero_undef(
67 ; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.cttz.i16(i16 [[X:%.*]], i1 true), !range [[RNG0]]
68 ; CHECK-NEXT: [[TMP2:%.*]] = zext i16 [[TMP1]] to i32
69 ; CHECK-NEXT: ret i32 [[TMP2]]
71 %s = sext i16 %x to i32
72 %tz = call i32 @llvm.cttz.i32(i32 %s, i1 true)
76 define i32 @cttz_sext_zero_def(i16 %x) {
77 ; CHECK-LABEL: @cttz_sext_zero_def(
78 ; CHECK-NEXT: [[TMP1:%.*]] = zext i16 [[X:%.*]] to i32
79 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP1]], i1 false), !range [[RNG1]]
80 ; CHECK-NEXT: ret i32 [[TMP2]]
82 %s = sext i16 %x to i32
83 %tz = call i32 @llvm.cttz.i32(i32 %s, i1 false)
87 define i32 @cttz_sext_zero_undef_extra_use(i16 %x) {
88 ; CHECK-LABEL: @cttz_sext_zero_undef_extra_use(
89 ; CHECK-NEXT: [[S:%.*]] = sext i16 [[X:%.*]] to i32
90 ; CHECK-NEXT: call void @use(i32 [[S]])
91 ; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[S]], i1 true), !range [[RNG1]]
92 ; CHECK-NEXT: ret i32 [[TZ]]
94 %s = sext i16 %x to i32
95 call void @use(i32 %s)
96 %tz = call i32 @llvm.cttz.i32(i32 %s, i1 true)
100 define <2 x i64> @cttz_sext_zero_undef_vec(<2 x i32> %x) {
101 ; CHECK-LABEL: @cttz_sext_zero_undef_vec(
102 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[X:%.*]], i1 true)
103 ; CHECK-NEXT: [[TMP2:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
104 ; CHECK-NEXT: ret <2 x i64> [[TMP2]]
106 %s = sext <2 x i32> %x to <2 x i64>
107 %tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %s, i1 true)
111 define <2 x i64> @cttz_sext_zero_def_vec(<2 x i32> %x) {
112 ; CHECK-LABEL: @cttz_sext_zero_def_vec(
113 ; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
114 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[TMP1]], i1 false)
115 ; CHECK-NEXT: ret <2 x i64> [[TMP2]]
117 %s = sext <2 x i32> %x to <2 x i64>
118 %tz = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %s, i1 false)