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_undef(<3 x i32> %i) {
31 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float_vec_undef(
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 undef, 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> <i1 true, 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 <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_undef(<3 x i32> %i) {
61 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float_vec_undef(
62 ; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true>
64 %f = uitofp <3 x i32> %i to <3 x float>
65 %b = bitcast <3 x float> %f to <3 x i32>
66 %cmp = icmp sgt <3 x i32> %b, <i32 -1, i32 undef, i32 -1>
70 define i1 @i32_cast_cmp_slt_int_0_uitofp_double(i32 %i) {
71 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double(
72 ; CHECK-NEXT: ret i1 false
74 %f = uitofp i32 %i to double
75 %b = bitcast double %f to i64
76 %cmp = icmp slt i64 %b, 0
80 define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec(<2 x i32> %i) {
81 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec(
82 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
84 %f = uitofp <2 x i32> %i to <2 x double>
85 %b = bitcast <2 x double> %f to <2 x i64>
86 %cmp = icmp slt <2 x i64> %b, <i64 0, i64 0>
90 define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
91 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double_vec_undef(
92 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
94 %f = uitofp <3 x i32> %i to <3 x double>
95 %b = bitcast <3 x double> %f to <3 x i64>
96 %cmp = icmp slt <3 x i64> %b, <i64 0, i64 undef, i64 0>
100 define i1 @i32_cast_cmp_sgt_int_m1_uitofp_double(i32 %i) {
101 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double(
102 ; CHECK-NEXT: ret i1 true
104 %f = uitofp i32 %i to double
105 %b = bitcast double %f to i64
106 %cmp = icmp sgt i64 %b, -1
110 define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(<2 x i32> %i) {
111 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec(
112 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
114 %f = uitofp <2 x i32> %i to <2 x double>
115 %b = bitcast <2 x double> %f to <2 x i64>
116 %cmp = icmp sgt <2 x i64> %b, <i64 -1, i64 -1>
120 define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_undef(<3 x i32> %i) {
121 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double_vec_undef(
122 ; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true>
124 %f = uitofp <3 x i32> %i to <3 x double>
125 %b = bitcast <3 x double> %f to <3 x i64>
126 %cmp = icmp sgt <3 x i64> %b, <i64 -1, i64 undef, i64 -1>
130 define i1 @i32_cast_cmp_slt_int_0_uitofp_half(i32 %i) {
131 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half(
132 ; CHECK-NEXT: ret i1 false
134 %f = uitofp i32 %i to half
135 %b = bitcast half %f to i16
136 %cmp = icmp slt i16 %b, 0
140 define <2 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec(<2 x i32> %i) {
141 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec(
142 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
144 %f = uitofp <2 x i32> %i to <2 x half>
145 %b = bitcast <2 x half> %f to <2 x i16>
146 %cmp = icmp slt <2 x i16> %b, <i16 0, i16 0>
150 define <3 x i1> @i32_cast_cmp_slt_int_0_uitofp_half_vec_undef(<3 x i32> %i) {
151 ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half_vec_undef(
152 ; CHECK-NEXT: ret <3 x i1> zeroinitializer
154 %f = uitofp <3 x i32> %i to <3 x half>
155 %b = bitcast <3 x half> %f to <3 x i16>
156 %cmp = icmp slt <3 x i16> %b, <i16 0, i16 undef, i16 0>
160 define i1 @i32_cast_cmp_sgt_int_m1_uitofp_half(i32 %i) {
161 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half(
162 ; CHECK-NEXT: ret i1 true
164 %f = uitofp i32 %i to half
165 %b = bitcast half %f to i16
166 %cmp = icmp sgt i16 %b, -1
170 define <2 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(<2 x i32> %i) {
171 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec(
172 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
174 %f = uitofp <2 x i32> %i to <2 x half>
175 %b = bitcast <2 x half> %f to <2 x i16>
176 %cmp = icmp sgt <2 x i16> %b, <i16 -1, i16 -1>
180 define <3 x i1> @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_undef(<3 x i32> %i) {
181 ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half_vec_undef(
182 ; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true>
184 %f = uitofp <3 x i32> %i to <3 x half>
185 %b = bitcast <3 x half> %f to <3 x i16>
186 %cmp = icmp sgt <3 x i16> %b, <i16 -1, i16 undef, i16 -1>