blob: d64f66c2c6da4a8d190f3f252b45c0d10861e174 [file] [log] [blame]
Roman Lebedev978aae72018-03-14 17:31:08 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
Roman Lebedev60d24442018-03-14 17:59:12 +00002; RUN: opt < %s -instsimplify -S | FileCheck %s
Roman Lebedev978aae72018-03-14 17:31:08 +00003
4; target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5
6; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682
7
8; FIXME: All of these can be simplified to a constant true or false value.
9; * slt i32 %b, 0 -> false
10; * sgt i32 %b, -1 -> true
11
12define i1 @i32_cast_cmp_slt_int_0_uitofp_float(i32 %i) {
13; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float(
14; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
15; CHECK-NEXT: [[B:%.*]] = bitcast float [[F]] to i32
16; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[B]], 0
17; CHECK-NEXT: ret i1 [[CMP]]
18;
19 %f = uitofp i32 %i to float
20 %b = bitcast float %f to i32
21 %cmp = icmp slt i32 %b, 0
22 ret i1 %cmp
23}
24
25define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_float_vec(<2 x i32> %i) {
26; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec(
27; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float>
28; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to <2 x i32>
29; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[B]], zeroinitializer
30; CHECK-NEXT: ret <2 x i1> [[CMP]]
31;
32 %f = uitofp <2 x i32> %i to <2 x float>
33 %b = bitcast <2 x float> %f to <2 x i32>
34 %cmp = icmp slt <2 x i32> %b, <i32 0, i32 0>
35 ret <2 x i1> %cmp
36}
37
38define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_float_vec_undef(<3 x i32> %i) {
39; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec_undef(
40; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x float>
41; CHECK-NEXT: [[B:%.*]] = bitcast <3 x float> [[F]] to <3 x i32>
42; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i32> [[B]], <i32 0, i32 undef, i32 0>
43; CHECK-NEXT: ret <3 x i1> [[CMP]]
44;
45 %f = uitofp <3 x i32> %i to <3 x float>
46 %b = bitcast <3 x float> %f to <3 x i32>
47 %cmp = icmp slt <3 x i32> %b, <i32 0, i32 undef, i32 0>
48 ret <3 x i1> %cmp
49}
50
51define i1 @i32_cast_cmp_sgt_int_m1_uitofp_float(i32 %i) {
52; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float(
53; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
54; CHECK-NEXT: [[B:%.*]] = bitcast float [[F]] to i32
55; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[B]], -1
56; CHECK-NEXT: ret i1 [[CMP]]
57;
58 %f = uitofp i32 %i to float
59 %b = bitcast float %f to i32
60 %cmp = icmp sgt i32 %b, -1
61 ret i1 %cmp
62}
63
64define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec(<2 x i32> %i) {
65; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec(
66; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float>
67; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to <2 x i32>
68; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[B]], <i32 -1, i32 -1>
69; CHECK-NEXT: ret <2 x i1> [[CMP]]
70;
71 %f = uitofp <2 x i32> %i to <2 x float>
72 %b = bitcast <2 x float> %f to <2 x i32>
73 %cmp = icmp sgt <2 x i32> %b, <i32 -1, i32 -1>
74 ret <2 x i1> %cmp
75}
76
77define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_undef(<3 x i32> %i) {
78; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_undef(
79; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x float>
80; CHECK-NEXT: [[B:%.*]] = bitcast <3 x float> [[F]] to <3 x i32>
81; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i32> [[B]], <i32 -1, i32 undef, i32 -1>
82; CHECK-NEXT: ret <3 x i1> [[CMP]]
83;
84 %f = uitofp <3 x i32> %i to <3 x float>
85 %b = bitcast <3 x float> %f to <3 x i32>
86 %cmp = icmp sgt <3 x i32> %b, <i32 -1, i32 undef, i32 -1>
87 ret <3 x i1> %cmp
88}
89
90define i1 @i32_cast_cmp_slt_int_0_uitofp_double(i32 %i) {
91; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double(
92; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to double
93; CHECK-NEXT: [[B:%.*]] = bitcast double [[F]] to i64
94; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[B]], 0
95; CHECK-NEXT: ret i1 [[CMP]]
96;
97 %f = uitofp i32 %i to double
98 %b = bitcast double %f to i64
99 %cmp = icmp slt i64 %b, 0
100 ret i1 %cmp
101}
102
103define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec(<2 x i32> %i) {
104; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec(
105; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x double>
106; CHECK-NEXT: [[B:%.*]] = bitcast <2 x double> [[F]] to <2 x i64>
107; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i64> [[B]], zeroinitializer
108; CHECK-NEXT: ret <2 x i1> [[CMP]]
109;
110 %f = uitofp <2 x i32> %i to <2 x double>
111 %b = bitcast <2 x double> %f to <2 x i64>
112 %cmp = icmp slt <2 x i64> %b, <i64 0, i64 0>
113 ret <2 x i1> %cmp
114}
115
116define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
117; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec_undef(
118; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x double>
119; CHECK-NEXT: [[B:%.*]] = bitcast <3 x double> [[F]] to <3 x i64>
120; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i64> [[B]], <i64 0, i64 undef, i64 0>
121; CHECK-NEXT: ret <3 x i1> [[CMP]]
122;
123 %f = uitofp <3 x i32> %i to <3 x double>
124 %b = bitcast <3 x double> %f to <3 x i64>
125 %cmp = icmp slt <3 x i64> %b, <i64 0, i64 undef, i64 0>
126 ret <3 x i1> %cmp
127}
128
129define i1 @i32_cast_cmp_sgt_int_m1_uitofp_double(i32 %i) {
130; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double(
131; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to double
132; CHECK-NEXT: [[B:%.*]] = bitcast double [[F]] to i64
133; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[B]], -1
134; CHECK-NEXT: ret i1 [[CMP]]
135;
136 %f = uitofp i32 %i to double
137 %b = bitcast double %f to i64
138 %cmp = icmp sgt i64 %b, -1
139 ret i1 %cmp
140}
141
142define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(<2 x i32> %i) {
143; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(
144; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x double>
145; CHECK-NEXT: [[B:%.*]] = bitcast <2 x double> [[F]] to <2 x i64>
146; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i64> [[B]], <i64 -1, i64 -1>
147; CHECK-NEXT: ret <2 x i1> [[CMP]]
148;
149 %f = uitofp <2 x i32> %i to <2 x double>
150 %b = bitcast <2 x double> %f to <2 x i64>
151 %cmp = icmp sgt <2 x i64> %b, <i64 -1, i64 -1>
152 ret <2 x i1> %cmp
153}
154
155define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_undef(<3 x i32> %i) {
156; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_undef(
157; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x double>
158; CHECK-NEXT: [[B:%.*]] = bitcast <3 x double> [[F]] to <3 x i64>
159; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i64> [[B]], <i64 -1, i64 undef, i64 -1>
160; CHECK-NEXT: ret <3 x i1> [[CMP]]
161;
162 %f = uitofp <3 x i32> %i to <3 x double>
163 %b = bitcast <3 x double> %f to <3 x i64>
164 %cmp = icmp sgt <3 x i64> %b, <i64 -1, i64 undef, i64 -1>
165 ret <3 x i1> %cmp
166}
167
168define i1 @i32_cast_cmp_slt_int_0_uitofp_half(i32 %i) {
169; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half(
170; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to half
171; CHECK-NEXT: [[B:%.*]] = bitcast half [[F]] to i16
172; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[B]], 0
173; CHECK-NEXT: ret i1 [[CMP]]
174;
175 %f = uitofp i32 %i to half
176 %b = bitcast half %f to i16
177 %cmp = icmp slt i16 %b, 0
178 ret i1 %cmp
179}
180
181define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec(<2 x i32> %i) {
182; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec(
183; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x half>
184; CHECK-NEXT: [[B:%.*]] = bitcast <2 x half> [[F]] to <2 x i16>
185; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i16> [[B]], zeroinitializer
186; CHECK-NEXT: ret <2 x i1> [[CMP]]
187;
188 %f = uitofp <2 x i32> %i to <2 x half>
189 %b = bitcast <2 x half> %f to <2 x i16>
190 %cmp = icmp slt <2 x i16> %b, <i16 0, i16 0>
191 ret <2 x i1> %cmp
192}
193
194define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec_undef(<3 x i32> %i) {
195; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec_undef(
196; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x half>
197; CHECK-NEXT: [[B:%.*]] = bitcast <3 x half> [[F]] to <3 x i16>
198; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i16> [[B]], <i16 0, i16 undef, i16 0>
199; CHECK-NEXT: ret <3 x i1> [[CMP]]
200;
201 %f = uitofp <3 x i32> %i to <3 x half>
202 %b = bitcast <3 x half> %f to <3 x i16>
203 %cmp = icmp slt <3 x i16> %b, <i16 0, i16 undef, i16 0>
204 ret <3 x i1> %cmp
205}
206
207define i1 @i32_cast_cmp_sgt_int_m1_uitofp_half(i32 %i) {
208; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half(
209; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to half
210; CHECK-NEXT: [[B:%.*]] = bitcast half [[F]] to i16
211; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i16 [[B]], -1
212; CHECK-NEXT: ret i1 [[CMP]]
213;
214 %f = uitofp i32 %i to half
215 %b = bitcast half %f to i16
216 %cmp = icmp sgt i16 %b, -1
217 ret i1 %cmp
218}
219
220define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(<2 x i32> %i) {
221; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(
222; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x half>
223; CHECK-NEXT: [[B:%.*]] = bitcast <2 x half> [[F]] to <2 x i16>
224; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i16> [[B]], <i16 -1, i16 -1>
225; CHECK-NEXT: ret <2 x i1> [[CMP]]
226;
227 %f = uitofp <2 x i32> %i to <2 x half>
228 %b = bitcast <2 x half> %f to <2 x i16>
229 %cmp = icmp sgt <2 x i16> %b, <i16 -1, i16 -1>
230 ret <2 x i1> %cmp
231}
232
233define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_undef(<3 x i32> %i) {
234; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_undef(
235; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x half>
236; CHECK-NEXT: [[B:%.*]] = bitcast <3 x half> [[F]] to <3 x i16>
237; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i16> [[B]], <i16 -1, i16 undef, i16 -1>
238; CHECK-NEXT: ret <3 x i1> [[CMP]]
239;
240 %f = uitofp <3 x i32> %i to <3 x half>
241 %b = bitcast <3 x half> %f to <3 x i16>
242 %cmp = icmp sgt <3 x i16> %b, <i16 -1, i16 undef, i16 -1>
243 ret <3 x i1> %cmp
244}