1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682
5
6; In *all* of these, uitofp and bitcast should be instcombine'd out.
7
8define i1 @i32_cast_cmp_eq_int_0_uitofp_float(i32 %i) {
9; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float(
10; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
11; CHECK-NEXT:    ret i1 [[CMP]]
12;
13  %f = uitofp i32 %i to float
14  %b = bitcast float %f to i32
15  %cmp = icmp eq i32 %b, 0
16  ret i1 %cmp
17}
18
19define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_float_vec(<2 x i32> %i) {
20; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float_vec(
21; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <2 x i32> [[I:%.*]], zeroinitializer
22; CHECK-NEXT:    ret <2 x i1> [[CMP]]
23;
24  %f = uitofp <2 x i32> %i to  <2 x float>
25  %b = bitcast <2 x float> %f to <2 x i32>
26  %cmp = icmp eq <2 x i32> %b, <i32 0, i32 0>
27  ret <2 x i1> %cmp
28}
29
30define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_float_vec_undef(<3 x i32> %i) {
31; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float_vec_undef(
32; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <3 x i32> [[I:%.*]], zeroinitializer
33; CHECK-NEXT:    ret <3 x i1> [[CMP]]
34;
35  %f = uitofp <3 x i32> %i to <3 x float>
36  %b = bitcast <3 x float> %f to <3 x i32>
37  %cmp = icmp eq <3 x i32> %b, <i32 0, i32 undef, i32 0>
38  ret <3 x i1> %cmp
39}
40
41define i1 @i32_cast_cmp_ne_int_0_uitofp_float(i32 %i) {
42; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float(
43; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
44; CHECK-NEXT:    ret i1 [[CMP]]
45;
46  %f = uitofp i32 %i to float
47  %b = bitcast float %f to i32
48  %cmp = icmp ne i32 %b, 0
49  ret i1 %cmp
50}
51
52define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_float_vec(<2 x i32> %i) {
53; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float_vec(
54; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i32> [[I:%.*]], zeroinitializer
55; CHECK-NEXT:    ret <2 x i1> [[CMP]]
56;
57  %f = uitofp <2 x i32> %i to  <2 x float>
58  %b = bitcast <2 x float> %f to <2 x i32>
59  %cmp = icmp ne <2 x i32> %b, <i32 0, i32 0>
60  ret <2 x i1> %cmp
61}
62
63define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_float_vec_undef(<3 x i32> %i) {
64; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float_vec_undef(
65; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <3 x i32> [[I:%.*]], zeroinitializer
66; CHECK-NEXT:    ret <3 x i1> [[CMP]]
67;
68  %f = uitofp <3 x i32> %i to <3 x float>
69  %b = bitcast <3 x float> %f to <3 x i32>
70  %cmp = icmp ne <3 x i32> %b, <i32 0, i32 undef, i32 0>
71  ret <3 x i1> %cmp
72}
73
74define i1 @i32_cast_cmp_eq_int_0_uitofp_double(i32 %i) {
75; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double(
76; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
77; CHECK-NEXT:    ret i1 [[CMP]]
78;
79  %f = uitofp i32 %i to double
80  %b = bitcast double %f to i64
81  %cmp = icmp eq i64 %b, 0
82  ret i1 %cmp
83}
84
85define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_double_vec(<2 x i32> %i) {
86; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double_vec(
87; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <2 x i32> [[I:%.*]], zeroinitializer
88; CHECK-NEXT:    ret <2 x i1> [[CMP]]
89;
90  %f = uitofp <2 x i32> %i to  <2 x double>
91  %b = bitcast <2 x double> %f to <2 x i64>
92  %cmp = icmp eq <2 x i64> %b, <i64 0, i64 0>
93  ret <2 x i1> %cmp
94}
95
96define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
97; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double_vec_undef(
98; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <3 x i32> [[I:%.*]], zeroinitializer
99; CHECK-NEXT:    ret <3 x i1> [[CMP]]
100;
101  %f = uitofp <3 x i32> %i to <3 x double>
102  %b = bitcast <3 x double> %f to <3 x i64>
103  %cmp = icmp eq <3 x i64> %b, <i64 0, i64 undef, i64 0>
104  ret <3 x i1> %cmp
105}
106
107define i1 @i32_cast_cmp_ne_int_0_uitofp_double(i32 %i) {
108; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double(
109; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
110; CHECK-NEXT:    ret i1 [[CMP]]
111;
112  %f = uitofp i32 %i to double
113  %b = bitcast double %f to i64
114  %cmp = icmp ne i64 %b, 0
115  ret i1 %cmp
116}
117
118define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_double_vec(<2 x i32> %i) {
119; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double_vec(
120; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i32> [[I:%.*]], zeroinitializer
121; CHECK-NEXT:    ret <2 x i1> [[CMP]]
122;
123  %f = uitofp <2 x i32> %i to  <2 x double>
124  %b = bitcast <2 x double> %f to <2 x i64>
125  %cmp = icmp ne <2 x i64> %b, <i64 0, i64 0>
126  ret <2 x i1> %cmp
127}
128
129define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
130; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double_vec_undef(
131; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <3 x i32> [[I:%.*]], zeroinitializer
132; CHECK-NEXT:    ret <3 x i1> [[CMP]]
133;
134  %f = uitofp <3 x i32> %i to <3 x double>
135  %b = bitcast <3 x double> %f to <3 x i64>
136  %cmp = icmp ne <3 x i64> %b, <i64 0, i64 undef, i64 0>
137  ret <3 x i1> %cmp
138}
139
140define i1 @i32_cast_cmp_eq_int_0_uitofp_half(i32 %i) {
141; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half(
142; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
143; CHECK-NEXT:    ret i1 [[CMP]]
144;
145  %f = uitofp i32 %i to half
146  %b = bitcast half %f to i16
147  %cmp = icmp eq i16 %b, 0
148  ret i1 %cmp
149}
150
151define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_half_vec(<2 x i32> %i) {
152; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half_vec(
153; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <2 x i32> [[I:%.*]], zeroinitializer
154; CHECK-NEXT:    ret <2 x i1> [[CMP]]
155;
156  %f = uitofp <2 x i32> %i to  <2 x half>
157  %b = bitcast <2 x half> %f to <2 x i16>
158  %cmp = icmp eq <2 x i16> %b, <i16 0, i16 0>
159  ret <2 x i1> %cmp
160}
161
162define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_half_vec_undef(<3 x i32> %i) {
163; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half_vec_undef(
164; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <3 x i32> [[I:%.*]], zeroinitializer
165; CHECK-NEXT:    ret <3 x i1> [[CMP]]
166;
167  %f = uitofp <3 x i32> %i to <3 x half>
168  %b = bitcast <3 x half> %f to <3 x i16>
169  %cmp = icmp eq <3 x i16> %b, <i16 0, i16 undef, i16 0>
170  ret <3 x i1> %cmp
171}
172
173define i1 @i32_cast_cmp_ne_int_0_uitofp_half(i32 %i) {
174; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half(
175; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
176; CHECK-NEXT:    ret i1 [[CMP]]
177;
178  %f = uitofp i32 %i to half
179  %b = bitcast half %f to i16
180  %cmp = icmp ne i16 %b, 0
181  ret i1 %cmp
182}
183
184define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_half_vec(<2 x i32> %i) {
185; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half_vec(
186; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i32> [[I:%.*]], zeroinitializer
187; CHECK-NEXT:    ret <2 x i1> [[CMP]]
188;
189  %f = uitofp <2 x i32> %i to  <2 x half>
190  %b = bitcast <2 x half> %f to <2 x i16>
191  %cmp = icmp ne <2 x i16> %b, <i16 0, i16 0>
192  ret <2 x i1> %cmp
193}
194
195define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_half_vec_undef(<3 x i32> %i) {
196; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half_vec_undef(
197; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <3 x i32> [[I:%.*]], zeroinitializer
198; CHECK-NEXT:    ret <3 x i1> [[CMP]]
199;
200  %f = uitofp <3 x i32> %i to <3 x half>
201  %b = bitcast <3 x half> %f to <3 x i16>
202  %cmp = icmp ne <3 x i16> %b, <i16 0, i16 undef, i16 0>
203  ret <3 x i1> %cmp
204}
205