Sanjay Patel | 7ad3dbe | 2017-05-23 16:53:05 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 3 | |
| 4 | ; icmp u/s (a ^ signmask), (b ^ signmask) --> icmp s/u a, b |
| 5 | |
| 6 | define i1 @slt_to_ult(i8 %x, i8 %y) { |
| 7 | ; CHECK-LABEL: @slt_to_ult( |
| 8 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 %x, %y |
| 9 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 10 | ; |
| 11 | %a = xor i8 %x, 128 |
| 12 | %b = xor i8 %y, 128 |
| 13 | %cmp = icmp slt i8 %a, %b |
| 14 | ret i1 %cmp |
| 15 | } |
| 16 | |
| 17 | ; PR33138 - https://bugs.llvm.org/show_bug.cgi?id=33138 |
| 18 | |
| 19 | define <2 x i1> @slt_to_ult_splat(<2 x i8> %x, <2 x i8> %y) { |
| 20 | ; CHECK-LABEL: @slt_to_ult_splat( |
Sanjay Patel | d3106ad | 2017-05-23 17:29:58 +0000 | [diff] [blame] | 21 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> %x, %y |
Sanjay Patel | 7ad3dbe | 2017-05-23 16:53:05 +0000 | [diff] [blame] | 22 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 23 | ; |
| 24 | %a = xor <2 x i8> %x, <i8 128, i8 128> |
| 25 | %b = xor <2 x i8> %y, <i8 128, i8 128> |
| 26 | %cmp = icmp slt <2 x i8> %a, %b |
| 27 | ret <2 x i1> %cmp |
| 28 | } |
| 29 | |
| 30 | ; Make sure that unsigned -> signed works too. |
| 31 | |
| 32 | define i1 @ult_to_slt(i8 %x, i8 %y) { |
| 33 | ; CHECK-LABEL: @ult_to_slt( |
| 34 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 %x, %y |
| 35 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 36 | ; |
| 37 | %a = xor i8 %x, 128 |
| 38 | %b = xor i8 %y, 128 |
| 39 | %cmp = icmp ult i8 %a, %b |
| 40 | ret i1 %cmp |
| 41 | } |
| 42 | |
| 43 | define <2 x i1> @ult_to_slt_splat(<2 x i8> %x, <2 x i8> %y) { |
| 44 | ; CHECK-LABEL: @ult_to_slt_splat( |
Sanjay Patel | d3106ad | 2017-05-23 17:29:58 +0000 | [diff] [blame] | 45 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> %x, %y |
Sanjay Patel | 7ad3dbe | 2017-05-23 16:53:05 +0000 | [diff] [blame] | 46 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 47 | ; |
| 48 | %a = xor <2 x i8> %x, <i8 128, i8 128> |
| 49 | %b = xor <2 x i8> %y, <i8 128, i8 128> |
| 50 | %cmp = icmp ult <2 x i8> %a, %b |
| 51 | ret <2 x i1> %cmp |
| 52 | } |
| 53 | |
| 54 | ; icmp u/s (a ^ maxsignval), (b ^ maxsignval) --> icmp s/u' a, b |
| 55 | |
| 56 | define i1 @slt_to_ugt(i8 %x, i8 %y) { |
| 57 | ; CHECK-LABEL: @slt_to_ugt( |
| 58 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 %x, %y |
| 59 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 60 | ; |
| 61 | %a = xor i8 %x, 127 |
| 62 | %b = xor i8 %y, 127 |
| 63 | %cmp = icmp slt i8 %a, %b |
| 64 | ret i1 %cmp |
| 65 | } |
| 66 | |
| 67 | define <2 x i1> @slt_to_ugt_splat(<2 x i8> %x, <2 x i8> %y) { |
| 68 | ; CHECK-LABEL: @slt_to_ugt_splat( |
Sanjay Patel | d3106ad | 2017-05-23 17:29:58 +0000 | [diff] [blame] | 69 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x, %y |
Sanjay Patel | 7ad3dbe | 2017-05-23 16:53:05 +0000 | [diff] [blame] | 70 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 71 | ; |
| 72 | %a = xor <2 x i8> %x, <i8 127, i8 127> |
| 73 | %b = xor <2 x i8> %y, <i8 127, i8 127> |
| 74 | %cmp = icmp slt <2 x i8> %a, %b |
| 75 | ret <2 x i1> %cmp |
| 76 | } |
| 77 | |
| 78 | ; Make sure that unsigned -> signed works too. |
| 79 | |
| 80 | define i1 @ult_to_sgt(i8 %x, i8 %y) { |
| 81 | ; CHECK-LABEL: @ult_to_sgt( |
| 82 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 %x, %y |
| 83 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 84 | ; |
| 85 | %a = xor i8 %x, 127 |
| 86 | %b = xor i8 %y, 127 |
| 87 | %cmp = icmp ult i8 %a, %b |
| 88 | ret i1 %cmp |
| 89 | } |
| 90 | |
| 91 | define <2 x i1> @ult_to_sgt_splat(<2 x i8> %x, <2 x i8> %y) { |
| 92 | ; CHECK-LABEL: @ult_to_sgt_splat( |
Sanjay Patel | d3106ad | 2017-05-23 17:29:58 +0000 | [diff] [blame] | 93 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> %x, %y |
Sanjay Patel | 7ad3dbe | 2017-05-23 16:53:05 +0000 | [diff] [blame] | 94 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 95 | ; |
| 96 | %a = xor <2 x i8> %x, <i8 127, i8 127> |
| 97 | %b = xor <2 x i8> %y, <i8 127, i8 127> |
| 98 | %cmp = icmp ult <2 x i8> %a, %b |
| 99 | ret <2 x i1> %cmp |
| 100 | } |
| 101 | |
| 102 | ; icmp u/s (a ^ signmask), C --> icmp s/u a, C' |
| 103 | |
| 104 | define i1 @sge_to_ugt(i8 %x) { |
| 105 | ; CHECK-LABEL: @sge_to_ugt( |
| 106 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 %x, -114 |
| 107 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 108 | ; |
| 109 | %a = xor i8 %x, 128 |
| 110 | %cmp = icmp sge i8 %a, 15 |
| 111 | ret i1 %cmp |
| 112 | } |
| 113 | |
| 114 | define <2 x i1> @sge_to_ugt_splat(<2 x i8> %x) { |
| 115 | ; CHECK-LABEL: @sge_to_ugt_splat( |
| 116 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x, <i8 -114, i8 -114> |
| 117 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 118 | ; |
| 119 | %a = xor <2 x i8> %x, <i8 128, i8 128> |
| 120 | %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15> |
| 121 | ret <2 x i1> %cmp |
| 122 | } |
| 123 | |
| 124 | ; Make sure that unsigned -> signed works too. |
| 125 | |
| 126 | define i1 @uge_to_sgt(i8 %x) { |
| 127 | ; CHECK-LABEL: @uge_to_sgt( |
| 128 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 %x, -114 |
| 129 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 130 | ; |
| 131 | %a = xor i8 %x, 128 |
| 132 | %cmp = icmp uge i8 %a, 15 |
| 133 | ret i1 %cmp |
| 134 | } |
| 135 | |
| 136 | define <2 x i1> @uge_to_sgt_splat(<2 x i8> %x) { |
| 137 | ; CHECK-LABEL: @uge_to_sgt_splat( |
| 138 | ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> %x, <i8 -114, i8 -114> |
| 139 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 140 | ; |
| 141 | %a = xor <2 x i8> %x, <i8 128, i8 128> |
| 142 | %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15> |
| 143 | ret <2 x i1> %cmp |
| 144 | } |
| 145 | |
| 146 | ; icmp u/s (a ^ maxsignval), C --> icmp s/u' a, C' |
| 147 | |
| 148 | define i1 @sge_to_ult(i8 %x) { |
| 149 | ; CHECK-LABEL: @sge_to_ult( |
| 150 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 %x, 113 |
| 151 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 152 | ; |
| 153 | %a = xor i8 %x, 127 |
| 154 | %cmp = icmp sge i8 %a, 15 |
| 155 | ret i1 %cmp |
| 156 | } |
| 157 | |
| 158 | define <2 x i1> @sge_to_ult_splat(<2 x i8> %x) { |
| 159 | ; CHECK-LABEL: @sge_to_ult_splat( |
| 160 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> %x, <i8 113, i8 113> |
| 161 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 162 | ; |
| 163 | %a = xor <2 x i8> %x, <i8 127, i8 127> |
| 164 | %cmp = icmp sge <2 x i8> %a, <i8 15, i8 15> |
| 165 | ret <2 x i1> %cmp |
| 166 | } |
| 167 | |
| 168 | ; Make sure that unsigned -> signed works too. |
| 169 | |
| 170 | define i1 @uge_to_slt(i8 %x) { |
| 171 | ; CHECK-LABEL: @uge_to_slt( |
| 172 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 %x, 113 |
| 173 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 174 | ; |
| 175 | %a = xor i8 %x, 127 |
| 176 | %cmp = icmp uge i8 %a, 15 |
| 177 | ret i1 %cmp |
| 178 | } |
| 179 | |
| 180 | define <2 x i1> @uge_to_slt_splat(<2 x i8> %x) { |
| 181 | ; CHECK-LABEL: @uge_to_slt_splat( |
| 182 | ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> %x, <i8 113, i8 113> |
| 183 | ; CHECK-NEXT: ret <2 x i1> [[CMP]] |
| 184 | ; |
| 185 | %a = xor <2 x i8> %x, <i8 127, i8 127> |
| 186 | %cmp = icmp uge <2 x i8> %a, <i8 15, i8 15> |
| 187 | ret <2 x i1> %cmp |
| 188 | } |
| 189 | |
Sanjay Patel | 6232406 | 2017-05-24 14:56:51 +0000 | [diff] [blame] | 190 | ; PR33138, part 2: https://bugs.llvm.org/show_bug.cgi?id=33138 |
Sanjay Patel | d1e8119 | 2017-06-22 15:46:54 +0000 | [diff] [blame] | 191 | ; Bitcast canonicalization ensures that we recognize the signbit constant. |
Sanjay Patel | 6232406 | 2017-05-24 14:56:51 +0000 | [diff] [blame] | 192 | |
| 193 | define <8 x i1> @sgt_to_ugt_bitcasted_splat(<2 x i32> %x, <2 x i32> %y) { |
| 194 | ; CHECK-LABEL: @sgt_to_ugt_bitcasted_splat( |
Sanjay Patel | d1e8119 | 2017-06-22 15:46:54 +0000 | [diff] [blame] | 195 | ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i32> %x to <8 x i8> |
| 196 | ; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i32> %y to <8 x i8> |
| 197 | ; CHECK-NEXT: [[E:%.*]] = icmp ugt <8 x i8> [[TMP1]], [[TMP2]] |
Sanjay Patel | 6232406 | 2017-05-24 14:56:51 +0000 | [diff] [blame] | 198 | ; CHECK-NEXT: ret <8 x i1> [[E]] |
| 199 | ; |
| 200 | %a = xor <2 x i32> %x, <i32 2155905152, i32 2155905152> ; 0x80808080 |
| 201 | %b = xor <2 x i32> %y, <i32 2155905152, i32 2155905152> |
| 202 | %c = bitcast <2 x i32> %a to <8 x i8> |
| 203 | %d = bitcast <2 x i32> %b to <8 x i8> |
| 204 | %e = icmp sgt <8 x i8> %c, %d |
| 205 | ret <8 x i1> %e |
| 206 | } |
| 207 | |
Sanjay Patel | d1e8119 | 2017-06-22 15:46:54 +0000 | [diff] [blame] | 208 | ; Bitcast canonicalization ensures that we recognize the signbit constant. |
Sanjay Patel | 6232406 | 2017-05-24 14:56:51 +0000 | [diff] [blame] | 209 | |
| 210 | define <2 x i1> @negative_simplify_splat(<4 x i8> %x) { |
| 211 | ; CHECK-LABEL: @negative_simplify_splat( |
Sanjay Patel | d1e8119 | 2017-06-22 15:46:54 +0000 | [diff] [blame] | 212 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
Sanjay Patel | 6232406 | 2017-05-24 14:56:51 +0000 | [diff] [blame] | 213 | ; |
| 214 | %a = or <4 x i8> %x, <i8 0, i8 128, i8 0, i8 128> |
| 215 | %b = bitcast <4 x i8> %a to <2 x i16> |
| 216 | %c = icmp sgt <2 x i16> %b, zeroinitializer |
| 217 | ret <2 x i1> %c |
| 218 | } |
| 219 | |