1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 ; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682
6 ; All of these can be simplified to a constant true or false value.
7 ; * slt i32 %b, 0 -> false
8 ; * sgt i32 %b, -1 -> true
10 define i1 @i32_cast_cmp_slt_int_0_uitofp_float(i32 %i) {
11 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float(
12 ; CHECK-NEXT: ret i1 false
14 %f = uitofp i32 %i to float
15 %b = bitcast float %f to i32
16 %cmp = icmp slt i32 %b, 0
20 define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_float_vec(<2 x i32> %i) {
21 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec(
22 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
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 slt <2 x i32> %b, <i32 0, i32 0>
30 define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_float_vec_poison(<3 x i32> %i) {
31 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec_poison(
32 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
34 %f = uitofp <3 x i32> %i to <3 x float>
35 %b = bitcast <3 x float> %f to <3 x i32>
36 %cmp = icmp slt <3 x i32> %b, <i32 0, i32 poison, i32 0>
40 define i1 @i32_cast_cmp_sgt_int_m1_uitofp_float(i32 %i) {
41 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float(
42 ; CHECK-NEXT: ret i1 true
44 %f = uitofp i32 %i to float
45 %b = bitcast float %f to i32
46 %cmp = icmp sgt i32 %b, -1
50 define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec(<2 x i32> %i) {
51 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec(
52 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
54 %f = uitofp <2 x i32> %i to <2 x float>
55 %b = bitcast <2 x float> %f to <2 x i32>
56 %cmp = icmp sgt <2 x i32> %b, <i32 -1, i32 -1>
60 define i1 @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_mismatch(<2 x i32> %i) {
61 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_mismatch(
62 ; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float>
63 ; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to i64
64 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[B]], -1
65 ; CHECK-NEXT: ret i1 [[CMP]]
67 %f = uitofp <2 x i32> %i to <2 x float>
68 %b = bitcast <2 x float> %f to i64
69 %cmp = icmp sgt i64 %b, -1
73 define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_poison(<3 x i32> %i) {
74 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_poison(
75 ; CHECK-NEXT: ret <3 x i1> splat (i1 true)
77 %f = uitofp <3 x i32> %i to <3 x float>
78 %b = bitcast <3 x float> %f to <3 x i32>
79 %cmp = icmp sgt <3 x i32> %b, <i32 -1, i32 poison, i32 -1>
83 define i1 @i32_cast_cmp_slt_int_0_uitofp_double(i32 %i) {
84 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double(
85 ; CHECK-NEXT: ret i1 false
87 %f = uitofp i32 %i to double
88 %b = bitcast double %f to i64
89 %cmp = icmp slt i64 %b, 0
93 define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec(<2 x i32> %i) {
94 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec(
95 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
97 %f = uitofp <2 x i32> %i to <2 x double>
98 %b = bitcast <2 x double> %f to <2 x i64>
99 %cmp = icmp slt <2 x i64> %b, <i64 0, i64 0>
103 define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec_poison(<3 x i32> %i) {
104 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec_poison(
105 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
107 %f = uitofp <3 x i32> %i to <3 x double>
108 %b = bitcast <3 x double> %f to <3 x i64>
109 %cmp = icmp slt <3 x i64> %b, <i64 0, i64 poison, i64 0>
113 define i1 @i32_cast_cmp_sgt_int_m1_uitofp_double(i32 %i) {
114 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double(
115 ; CHECK-NEXT: ret i1 true
117 %f = uitofp i32 %i to double
118 %b = bitcast double %f to i64
119 %cmp = icmp sgt i64 %b, -1
123 define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(<2 x i32> %i) {
124 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(
125 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
127 %f = uitofp <2 x i32> %i to <2 x double>
128 %b = bitcast <2 x double> %f to <2 x i64>
129 %cmp = icmp sgt <2 x i64> %b, <i64 -1, i64 -1>
133 define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_poison(<3 x i32> %i) {
134 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_poison(
135 ; CHECK-NEXT: ret <3 x i1> splat (i1 true)
137 %f = uitofp <3 x i32> %i to <3 x double>
138 %b = bitcast <3 x double> %f to <3 x i64>
139 %cmp = icmp sgt <3 x i64> %b, <i64 -1, i64 poison, i64 -1>
143 define i1 @i32_cast_cmp_slt_int_0_uitofp_half(i32 %i) {
144 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half(
145 ; CHECK-NEXT: ret i1 false
147 %f = uitofp i32 %i to half
148 %b = bitcast half %f to i16
149 %cmp = icmp slt i16 %b, 0
153 define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec(<2 x i32> %i) {
154 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec(
155 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
157 %f = uitofp <2 x i32> %i to <2 x half>
158 %b = bitcast <2 x half> %f to <2 x i16>
159 %cmp = icmp slt <2 x i16> %b, <i16 0, i16 0>
163 define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec_poison(<3 x i32> %i) {
164 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec_poison(
165 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
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 slt <3 x i16> %b, <i16 0, i16 poison, i16 0>
173 define i1 @i32_cast_cmp_sgt_int_m1_uitofp_half(i32 %i) {
174 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half(
175 ; CHECK-NEXT: ret i1 true
177 %f = uitofp i32 %i to half
178 %b = bitcast half %f to i16
179 %cmp = icmp sgt i16 %b, -1
183 define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(<2 x i32> %i) {
184 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(
185 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
187 %f = uitofp <2 x i32> %i to <2 x half>
188 %b = bitcast <2 x half> %f to <2 x i16>
189 %cmp = icmp sgt <2 x i16> %b, <i16 -1, i16 -1>
193 define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_poison(<3 x i32> %i) {
194 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_poison(
195 ; CHECK-NEXT: ret <3 x i1> splat (i1 true)
197 %f = uitofp <3 x i32> %i to <3 x half>
198 %b = bitcast <3 x half> %f to <3 x i16>
199 %cmp = icmp sgt <3 x i16> %b, <i16 -1, i16 poison, i16 -1>