| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| Roman Lebedev | 60d2444 | 2018-03-14 17:59:12 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 3 | |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 4 | ; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682 |
| 5 | |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 6 | ; All of these can be simplified to a constant true or false value. |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 7 | ; * slt i32 %b, 0 -> false |
| 8 | ; * sgt i32 %b, -1 -> true |
| 9 | |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 10 | ; FIXME: m_Zero does not handle undef elements in vectors. |
| 11 | |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 12 | define i1 @i32_cast_cmp_slt_int_0_uitofp_float(i32 %i) { |
| 13 | ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_float( |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 14 | ; CHECK-NEXT: ret i1 false |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 15 | ; |
| 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 | |
| 22 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 24 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 25 | ; |
| 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 | |
| 32 | define <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 | |
| 45 | define i1 @i32_cast_cmp_sgt_int_m1_uitofp_float(i32 %i) { |
| 46 | ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_float( |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 47 | ; CHECK-NEXT: ret i1 true |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 48 | ; |
| 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 | |
| 55 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 57 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 58 | ; |
| 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 | |
| 65 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 67 | ; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true> |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 68 | ; |
| 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 | |
| 75 | define i1 @i32_cast_cmp_slt_int_0_uitofp_double(i32 %i) { |
| 76 | ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_double( |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 77 | ; CHECK-NEXT: ret i1 false |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 78 | ; |
| 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 | |
| 85 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 87 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 88 | ; |
| 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 | |
| 95 | define <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 | |
| 108 | define i1 @i32_cast_cmp_sgt_int_m1_uitofp_double(i32 %i) { |
| 109 | ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_double( |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 110 | ; CHECK-NEXT: ret i1 true |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 111 | ; |
| 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 | |
| 118 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 120 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 121 | ; |
| 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 | |
| 128 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 130 | ; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true> |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 131 | ; |
| 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 | |
| 138 | define i1 @i32_cast_cmp_slt_int_0_uitofp_half(i32 %i) { |
| 139 | ; CHECK-LABEL: @i32_cast_cmp_slt_int_0_uitofp_half( |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 140 | ; CHECK-NEXT: ret i1 false |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 141 | ; |
| 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 | |
| 148 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 150 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 151 | ; |
| 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 | |
| 158 | define <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 | |
| 171 | define i1 @i32_cast_cmp_sgt_int_m1_uitofp_half(i32 %i) { |
| 172 | ; CHECK-LABEL: @i32_cast_cmp_sgt_int_m1_uitofp_half( |
| Roman Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 173 | ; CHECK-NEXT: ret i1 true |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 174 | ; |
| 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 | |
| 181 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 183 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 184 | ; |
| 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 | |
| 191 | define <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 Lebedev | 6aca335 | 2018-03-15 16:17:46 +0000 | [diff] [blame] | 193 | ; CHECK-NEXT: ret <3 x i1> <i1 true, i1 true, i1 true> |
| Roman Lebedev | 978aae7 | 2018-03-14 17:31:08 +0000 | [diff] [blame] | 194 | ; |
| 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 | } |