blob: 3e5a68ce78236b2f838cb6497c744a5890d34fd7 [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
Roman Lebedev978aae72018-03-14 17:31:08 +00004; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682
5
Roman Lebedev6aca3352018-03-15 16:17:46 +00006; All of these can be simplified to a constant true or false value.
Roman Lebedev978aae72018-03-14 17:31:08 +00007; * slt i32 %b, 0 -> false
8; * sgt i32 %b, -1 -> true
9
Roman Lebedev6aca3352018-03-15 16:17:46 +000010; FIXME: m_Zero does not handle undef elements in vectors.
11
Roman Lebedev978aae72018-03-14 17:31:08 +000012define i1 @i32_cast_cmp_slt_int_0_uitofp_float(i32 %i) {
13; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float(
Roman Lebedev6aca3352018-03-15 16:17:46 +000014; CHECK-NEXT: ret i1 false
Roman Lebedev978aae72018-03-14 17:31:08 +000015;
16 %f = uitofp i32 %i to float
17 %b = bitcast float %f to i32
18 %cmp = icmp slt i32 %b, 0
19 ret i1 %cmp
20}
21
22define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_float_vec(<2 x i32> %i) {
23; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec(
Roman Lebedev6aca3352018-03-15 16:17:46 +000024; CHECK-NEXT: ret <2 x i1> zeroinitializer
Roman Lebedev978aae72018-03-14 17:31:08 +000025;
26 %f = uitofp <2 x i32> %i to <2 x float>
27 %b = bitcast <2 x float> %f to <2 x i32>
28 %cmp = icmp slt <2 x i32> %b, <i32 0, i32 0>
29 ret <2 x i1> %cmp
30}
31
32define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_float_vec_undef(<3 x i32> %i) {
33; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec_undef(
34; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x float>
35; CHECK-NEXT: [[B:%.*]] = bitcast <3 x float> [[F]] to <3 x i32>
36; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i32> [[B]], <i32 0, i32 undef, i32 0>
37; CHECK-NEXT: ret <3 x i1> [[CMP]]
38;
39 %f = uitofp <3 x i32> %i to <3 x float>
40 %b = bitcast <3 x float> %f to <3 x i32>
41 %cmp = icmp slt <3 x i32> %b, <i32 0, i32 undef, i32 0>
42 ret <3 x i1> %cmp
43}
44
45define i1 @i32_cast_cmp_sgt_int_m1_uitofp_float(i32 %i) {
46; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float(
Roman Lebedev6aca3352018-03-15 16:17:46 +000047; CHECK-NEXT: ret i1 true
Roman Lebedev978aae72018-03-14 17:31:08 +000048;
49 %f = uitofp i32 %i to float
50 %b = bitcast float %f to i32
51 %cmp = icmp sgt i32 %b, -1
52 ret i1 %cmp
53}
54
55define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec(<2 x i32> %i) {
56; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec(
Roman Lebedev6aca3352018-03-15 16:17:46 +000057; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
Roman Lebedev978aae72018-03-14 17:31:08 +000058;
59 %f = uitofp <2 x i32> %i to <2 x float>
60 %b = bitcast <2 x float> %f to <2 x i32>
61 %cmp = icmp sgt <2 x i32> %b, <i32 -1, i32 -1>
62 ret <2 x i1> %cmp
63}
64
65define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_undef(<3 x i32> %i) {
66; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_undef(
Roman Lebedev6aca3352018-03-15 16:17:46 +000067; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true>
Roman Lebedev978aae72018-03-14 17:31:08 +000068;
69 %f = uitofp <3 x i32> %i to <3 x float>
70 %b = bitcast <3 x float> %f to <3 x i32>
71 %cmp = icmp sgt <3 x i32> %b, <i32 -1, i32 undef, i32 -1>
72 ret <3 x i1> %cmp
73}
74
75define i1 @i32_cast_cmp_slt_int_0_uitofp_double(i32 %i) {
76; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double(
Roman Lebedev6aca3352018-03-15 16:17:46 +000077; CHECK-NEXT: ret i1 false
Roman Lebedev978aae72018-03-14 17:31:08 +000078;
79 %f = uitofp i32 %i to double
80 %b = bitcast double %f to i64
81 %cmp = icmp slt i64 %b, 0
82 ret i1 %cmp
83}
84
85define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec(<2 x i32> %i) {
86; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec(
Roman Lebedev6aca3352018-03-15 16:17:46 +000087; CHECK-NEXT: ret <2 x i1> zeroinitializer
Roman Lebedev978aae72018-03-14 17:31:08 +000088;
89 %f = uitofp <2 x i32> %i to <2 x double>
90 %b = bitcast <2 x double> %f to <2 x i64>
91 %cmp = icmp slt <2 x i64> %b, <i64 0, i64 0>
92 ret <2 x i1> %cmp
93}
94
95define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
96; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec_undef(
97; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x double>
98; CHECK-NEXT: [[B:%.*]] = bitcast <3 x double> [[F]] to <3 x i64>
99; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i64> [[B]], <i64 0, i64 undef, i64 0>
100; CHECK-NEXT: ret <3 x i1> [[CMP]]
101;
102 %f = uitofp <3 x i32> %i to <3 x double>
103 %b = bitcast <3 x double> %f to <3 x i64>
104 %cmp = icmp slt <3 x i64> %b, <i64 0, i64 undef, i64 0>
105 ret <3 x i1> %cmp
106}
107
108define i1 @i32_cast_cmp_sgt_int_m1_uitofp_double(i32 %i) {
109; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000110; CHECK-NEXT: ret i1 true
Roman Lebedev978aae72018-03-14 17:31:08 +0000111;
112 %f = uitofp i32 %i to double
113 %b = bitcast double %f to i64
114 %cmp = icmp sgt i64 %b, -1
115 ret i1 %cmp
116}
117
118define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(<2 x i32> %i) {
119; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000120; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
Roman Lebedev978aae72018-03-14 17:31:08 +0000121;
122 %f = uitofp <2 x i32> %i to <2 x double>
123 %b = bitcast <2 x double> %f to <2 x i64>
124 %cmp = icmp sgt <2 x i64> %b, <i64 -1, i64 -1>
125 ret <2 x i1> %cmp
126}
127
128define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_undef(<3 x i32> %i) {
129; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_undef(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000130; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true>
Roman Lebedev978aae72018-03-14 17:31:08 +0000131;
132 %f = uitofp <3 x i32> %i to <3 x double>
133 %b = bitcast <3 x double> %f to <3 x i64>
134 %cmp = icmp sgt <3 x i64> %b, <i64 -1, i64 undef, i64 -1>
135 ret <3 x i1> %cmp
136}
137
138define i1 @i32_cast_cmp_slt_int_0_uitofp_half(i32 %i) {
139; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000140; CHECK-NEXT: ret i1 false
Roman Lebedev978aae72018-03-14 17:31:08 +0000141;
142 %f = uitofp i32 %i to half
143 %b = bitcast half %f to i16
144 %cmp = icmp slt i16 %b, 0
145 ret i1 %cmp
146}
147
148define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec(<2 x i32> %i) {
149; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000150; CHECK-NEXT: ret <2 x i1> zeroinitializer
Roman Lebedev978aae72018-03-14 17:31:08 +0000151;
152 %f = uitofp <2 x i32> %i to <2 x half>
153 %b = bitcast <2 x half> %f to <2 x i16>
154 %cmp = icmp slt <2 x i16> %b, <i16 0, i16 0>
155 ret <2 x i1> %cmp
156}
157
158define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec_undef(<3 x i32> %i) {
159; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec_undef(
160; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x half>
161; CHECK-NEXT: [[B:%.*]] = bitcast <3 x half> [[F]] to <3 x i16>
162; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i16> [[B]], <i16 0, i16 undef, i16 0>
163; CHECK-NEXT: ret <3 x i1> [[CMP]]
164;
165 %f = uitofp <3 x i32> %i to <3 x half>
166 %b = bitcast <3 x half> %f to <3 x i16>
167 %cmp = icmp slt <3 x i16> %b, <i16 0, i16 undef, i16 0>
168 ret <3 x i1> %cmp
169}
170
171define i1 @i32_cast_cmp_sgt_int_m1_uitofp_half(i32 %i) {
172; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000173; CHECK-NEXT: ret i1 true
Roman Lebedev978aae72018-03-14 17:31:08 +0000174;
175 %f = uitofp i32 %i to half
176 %b = bitcast half %f to i16
177 %cmp = icmp sgt i16 %b, -1
178 ret i1 %cmp
179}
180
181define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(<2 x i32> %i) {
182; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000183; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
Roman Lebedev978aae72018-03-14 17:31:08 +0000184;
185 %f = uitofp <2 x i32> %i to <2 x half>
186 %b = bitcast <2 x half> %f to <2 x i16>
187 %cmp = icmp sgt <2 x i16> %b, <i16 -1, i16 -1>
188 ret <2 x i1> %cmp
189}
190
191define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_undef(<3 x i32> %i) {
192; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_undef(
Roman Lebedev6aca3352018-03-15 16:17:46 +0000193; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true>
Roman Lebedev978aae72018-03-14 17:31:08 +0000194;
195 %f = uitofp <3 x i32> %i to <3 x half>
196 %b = bitcast <3 x half> %f to <3 x i16>
197 %cmp = icmp sgt <3 x i16> %b, <i16 -1, i16 undef, i16 -1>
198 ret <3 x i1> %cmp
199}