Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 3 | |
Sanjay Patel | 308eb22 | 2017-02-18 21:51:14 +0000 | [diff] [blame^] | 4 | ; add nsw (xor X, signbit), signbit --> X |
| 5 | |
| 6 | define <2 x i32> @add_nsw_signbit(<2 x i32> %x) { |
| 7 | ; CHECK-LABEL: @add_nsw_signbit( |
| 8 | ; CHECK-NEXT: [[Y:%.*]] = xor <2 x i32> %x, <i32 -2147483648, i32 -2147483648> |
| 9 | ; CHECK-NEXT: [[Z:%.*]] = add nsw <2 x i32> [[Y]], <i32 -2147483648, i32 -2147483648> |
| 10 | ; CHECK-NEXT: ret <2 x i32> [[Z]] |
| 11 | ; |
| 12 | %y = xor <2 x i32> %x, <i32 -2147483648, i32 -2147483648> |
| 13 | %z = add nsw <2 x i32> %y, <i32 -2147483648, i32 -2147483648> |
| 14 | ret <2 x i32> %z |
| 15 | } |
| 16 | |
| 17 | ; add nuw (xor X, signbit), signbit --> X |
| 18 | |
| 19 | define <2 x i5> @add_nuw_signbit(<2 x i5> %x) { |
| 20 | ; CHECK-LABEL: @add_nuw_signbit( |
| 21 | ; CHECK-NEXT: [[Y:%.*]] = xor <2 x i5> %x, <i5 -16, i5 -16> |
| 22 | ; CHECK-NEXT: [[Z:%.*]] = add nuw <2 x i5> [[Y]], <i5 -16, i5 -16> |
| 23 | ; CHECK-NEXT: ret <2 x i5> [[Z]] |
| 24 | ; |
| 25 | %y = xor <2 x i5> %x, <i5 -16, i5 -16> |
| 26 | %z = add nuw <2 x i5> %y, <i5 -16, i5 -16> |
| 27 | ret <2 x i5> %z |
| 28 | } |
| 29 | |
Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 30 | define i64 @pow2(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 31 | ; CHECK-LABEL: @pow2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 32 | ; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, %x |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 33 | ; CHECK-NEXT: [[X2:%.*]] = and i32 %x, [[NEGX]] |
| 34 | ; CHECK-NEXT: [[E:%.*]] = zext i32 [[X2]] to i64 |
| 35 | ; CHECK-NEXT: ret i64 [[E]] |
| 36 | ; |
Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 37 | %negx = sub i32 0, %x |
| 38 | %x2 = and i32 %x, %negx |
| 39 | %e = zext i32 %x2 to i64 |
| 40 | %nege = sub i64 0, %e |
| 41 | %e2 = and i64 %e, %nege |
| 42 | ret i64 %e2 |
Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 43 | } |
Duncan Sands | 985ba63 | 2011-10-28 18:30:05 +0000 | [diff] [blame] | 44 | |
| 45 | define i64 @pow2b(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 46 | ; CHECK-LABEL: @pow2b( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 47 | ; CHECK-NEXT: [[SH:%.*]] = shl i32 2, %x |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 48 | ; CHECK-NEXT: [[E:%.*]] = zext i32 [[SH]] to i64 |
| 49 | ; CHECK-NEXT: ret i64 [[E]] |
| 50 | ; |
Duncan Sands | 985ba63 | 2011-10-28 18:30:05 +0000 | [diff] [blame] | 51 | %sh = shl i32 2, %x |
| 52 | %e = zext i32 %sh to i64 |
| 53 | %nege = sub i64 0, %e |
| 54 | %e2 = and i64 %e, %nege |
| 55 | ret i64 %e2 |
Duncan Sands | 985ba63 | 2011-10-28 18:30:05 +0000 | [diff] [blame] | 56 | } |
David Majnemer | cd4fbcd | 2014-07-31 04:49:18 +0000 | [diff] [blame] | 57 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 58 | define i1 @and_of_icmps0(i32 %b) { |
| 59 | ; CHECK-LABEL: @and_of_icmps0( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 60 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 61 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 62 | %1 = add i32 %b, 2 |
| 63 | %2 = icmp ult i32 %1, 4 |
| 64 | %cmp3 = icmp sgt i32 %b, 2 |
| 65 | %cmp = and i1 %2, %cmp3 |
| 66 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 69 | define <2 x i1> @and_of_icmps0_vec(<2 x i32> %b) { |
| 70 | ; CHECK-LABEL: @and_of_icmps0_vec( |
| 71 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| 72 | ; |
| 73 | %1 = add <2 x i32> %b, <i32 2, i32 2> |
| 74 | %2 = icmp ult <2 x i32> %1, <i32 4, i32 4> |
| 75 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> |
| 76 | %cmp = and <2 x i1> %2, %cmp3 |
| 77 | ret <2 x i1> %cmp |
| 78 | } |
| 79 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 80 | define i1 @and_of_icmps1(i32 %b) { |
| 81 | ; CHECK-LABEL: @and_of_icmps1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 82 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 83 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 84 | %1 = add nsw i32 %b, 2 |
| 85 | %2 = icmp slt i32 %1, 4 |
| 86 | %cmp3 = icmp sgt i32 %b, 2 |
| 87 | %cmp = and i1 %2, %cmp3 |
| 88 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 91 | define <2 x i1> @and_of_icmps1_vec(<2 x i32> %b) { |
| 92 | ; CHECK-LABEL: @and_of_icmps1_vec( |
| 93 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| 94 | ; |
| 95 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> |
| 96 | %2 = icmp slt <2 x i32> %1, <i32 4, i32 4> |
| 97 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> |
| 98 | %cmp = and <2 x i1> %2, %cmp3 |
| 99 | ret <2 x i1> %cmp |
| 100 | } |
| 101 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 102 | define i1 @and_of_icmps2(i32 %b) { |
| 103 | ; CHECK-LABEL: @and_of_icmps2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 104 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 105 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 106 | %1 = add i32 %b, 2 |
| 107 | %2 = icmp ule i32 %1, 3 |
| 108 | %cmp3 = icmp sgt i32 %b, 2 |
| 109 | %cmp = and i1 %2, %cmp3 |
| 110 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 113 | define <2 x i1> @and_of_icmps2_vec(<2 x i32> %b) { |
| 114 | ; CHECK-LABEL: @and_of_icmps2_vec( |
| 115 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| 116 | ; |
| 117 | %1 = add <2 x i32> %b, <i32 2, i32 2> |
| 118 | %2 = icmp ule <2 x i32> %1, <i32 3, i32 3> |
| 119 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> |
| 120 | %cmp = and <2 x i1> %2, %cmp3 |
| 121 | ret <2 x i1> %cmp |
| 122 | } |
| 123 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 124 | define i1 @and_of_icmps3(i32 %b) { |
| 125 | ; CHECK-LABEL: @and_of_icmps3( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 126 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 127 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 128 | %1 = add nsw i32 %b, 2 |
| 129 | %2 = icmp sle i32 %1, 3 |
| 130 | %cmp3 = icmp sgt i32 %b, 2 |
| 131 | %cmp = and i1 %2, %cmp3 |
| 132 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 135 | define <2 x i1> @and_of_icmps3_vec(<2 x i32> %b) { |
| 136 | ; CHECK-LABEL: @and_of_icmps3_vec( |
| 137 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| 138 | ; |
| 139 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> |
| 140 | %2 = icmp sle <2 x i32> %1, <i32 3, i32 3> |
| 141 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> |
| 142 | %cmp = and <2 x i1> %2, %cmp3 |
| 143 | ret <2 x i1> %cmp |
| 144 | } |
| 145 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 146 | define i1 @and_of_icmps4(i32 %b) { |
| 147 | ; CHECK-LABEL: @and_of_icmps4( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 148 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 149 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 150 | %1 = add nuw i32 %b, 2 |
| 151 | %2 = icmp ult i32 %1, 4 |
| 152 | %cmp3 = icmp ugt i32 %b, 2 |
| 153 | %cmp = and i1 %2, %cmp3 |
| 154 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 157 | define <2 x i1> @and_of_icmps4_vec(<2 x i32> %b) { |
| 158 | ; CHECK-LABEL: @and_of_icmps4_vec( |
| 159 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| 160 | ; |
| 161 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> |
| 162 | %2 = icmp ult <2 x i32> %1, <i32 4, i32 4> |
| 163 | %cmp3 = icmp ugt <2 x i32> %b, <i32 2, i32 2> |
| 164 | %cmp = and <2 x i1> %2, %cmp3 |
| 165 | ret <2 x i1> %cmp |
| 166 | } |
| 167 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 168 | define i1 @and_of_icmps5(i32 %b) { |
| 169 | ; CHECK-LABEL: @and_of_icmps5( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 170 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 171 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 172 | %1 = add nuw i32 %b, 2 |
| 173 | %2 = icmp ule i32 %1, 3 |
| 174 | %cmp3 = icmp ugt i32 %b, 2 |
| 175 | %cmp = and i1 %2, %cmp3 |
| 176 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 179 | define <2 x i1> @and_of_icmps5_vec(<2 x i32> %b) { |
| 180 | ; CHECK-LABEL: @and_of_icmps5_vec( |
| 181 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
| 182 | ; |
| 183 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> |
| 184 | %2 = icmp ule <2 x i32> %1, <i32 3, i32 3> |
| 185 | %cmp3 = icmp ugt <2 x i32> %b, <i32 2, i32 2> |
| 186 | %cmp = and <2 x i1> %2, %cmp3 |
| 187 | ret <2 x i1> %cmp |
| 188 | } |
| 189 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 190 | define i1 @or_of_icmps0(i32 %b) { |
| 191 | ; CHECK-LABEL: @or_of_icmps0( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 192 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 193 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 194 | %1 = add i32 %b, 2 |
| 195 | %2 = icmp uge i32 %1, 4 |
| 196 | %cmp3 = icmp sle i32 %b, 2 |
| 197 | %cmp = or i1 %2, %cmp3 |
| 198 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 201 | define <2 x i1> @or_of_icmps0_vec(<2 x i32> %b) { |
| 202 | ; CHECK-LABEL: @or_of_icmps0_vec( |
Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 203 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 204 | ; |
| 205 | %1 = add <2 x i32> %b, <i32 2, i32 2> |
| 206 | %2 = icmp uge <2 x i32> %1, <i32 4, i32 4> |
| 207 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> |
| 208 | %cmp = or <2 x i1> %2, %cmp3 |
| 209 | ret <2 x i1> %cmp |
| 210 | } |
| 211 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 212 | define i1 @or_of_icmps1(i32 %b) { |
| 213 | ; CHECK-LABEL: @or_of_icmps1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 214 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 215 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 216 | %1 = add nsw i32 %b, 2 |
| 217 | %2 = icmp sge i32 %1, 4 |
| 218 | %cmp3 = icmp sle i32 %b, 2 |
| 219 | %cmp = or i1 %2, %cmp3 |
| 220 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 223 | define <2 x i1> @or_of_icmps1_vec(<2 x i32> %b) { |
| 224 | ; CHECK-LABEL: @or_of_icmps1_vec( |
Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 225 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 226 | ; |
| 227 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> |
| 228 | %2 = icmp sge <2 x i32> %1, <i32 4, i32 4> |
| 229 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> |
| 230 | %cmp = or <2 x i1> %2, %cmp3 |
| 231 | ret <2 x i1> %cmp |
| 232 | } |
| 233 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 234 | define i1 @or_of_icmps2(i32 %b) { |
| 235 | ; CHECK-LABEL: @or_of_icmps2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 236 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 237 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 238 | %1 = add i32 %b, 2 |
| 239 | %2 = icmp ugt i32 %1, 3 |
| 240 | %cmp3 = icmp sle i32 %b, 2 |
| 241 | %cmp = or i1 %2, %cmp3 |
| 242 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 245 | define <2 x i1> @or_of_icmps2_vec(<2 x i32> %b) { |
| 246 | ; CHECK-LABEL: @or_of_icmps2_vec( |
Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 247 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 248 | ; |
| 249 | %1 = add <2 x i32> %b, <i32 2, i32 2> |
| 250 | %2 = icmp ugt <2 x i32> %1, <i32 3, i32 3> |
| 251 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> |
| 252 | %cmp = or <2 x i1> %2, %cmp3 |
| 253 | ret <2 x i1> %cmp |
| 254 | } |
| 255 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 256 | define i1 @or_of_icmps3(i32 %b) { |
| 257 | ; CHECK-LABEL: @or_of_icmps3( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 258 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 259 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 260 | %1 = add nsw i32 %b, 2 |
| 261 | %2 = icmp sgt i32 %1, 3 |
| 262 | %cmp3 = icmp sle i32 %b, 2 |
| 263 | %cmp = or i1 %2, %cmp3 |
| 264 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 267 | define <2 x i1> @or_of_icmps3_vec(<2 x i32> %b) { |
| 268 | ; CHECK-LABEL: @or_of_icmps3_vec( |
Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 269 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 270 | ; |
| 271 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> |
| 272 | %2 = icmp sgt <2 x i32> %1, <i32 3, i32 3> |
| 273 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> |
| 274 | %cmp = or <2 x i1> %2, %cmp3 |
| 275 | ret <2 x i1> %cmp |
| 276 | } |
| 277 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 278 | define i1 @or_of_icmps4(i32 %b) { |
| 279 | ; CHECK-LABEL: @or_of_icmps4( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 280 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 281 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 282 | %1 = add nuw i32 %b, 2 |
| 283 | %2 = icmp uge i32 %1, 4 |
| 284 | %cmp3 = icmp ule i32 %b, 2 |
| 285 | %cmp = or i1 %2, %cmp3 |
| 286 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 289 | define <2 x i1> @or_of_icmps4_vec(<2 x i32> %b) { |
| 290 | ; CHECK-LABEL: @or_of_icmps4_vec( |
Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 291 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 292 | ; |
| 293 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> |
| 294 | %2 = icmp uge <2 x i32> %1, <i32 4, i32 4> |
| 295 | %cmp3 = icmp ule <2 x i32> %b, <i32 2, i32 2> |
| 296 | %cmp = or <2 x i1> %2, %cmp3 |
| 297 | ret <2 x i1> %cmp |
| 298 | } |
| 299 | |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 300 | define i1 @or_of_icmps5(i32 %b) { |
| 301 | ; CHECK-LABEL: @or_of_icmps5( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 302 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 303 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 304 | %1 = add nuw i32 %b, 2 |
| 305 | %2 = icmp ugt i32 %1, 3 |
| 306 | %cmp3 = icmp ule i32 %b, 2 |
| 307 | %cmp = or i1 %2, %cmp3 |
| 308 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 309 | } |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 310 | |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 311 | define <2 x i1> @or_of_icmps5_vec(<2 x i32> %b) { |
| 312 | ; CHECK-LABEL: @or_of_icmps5_vec( |
Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 313 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 314 | ; |
| 315 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> |
| 316 | %2 = icmp ugt <2 x i32> %1, <i32 3, i32 3> |
| 317 | %cmp3 = icmp ule <2 x i32> %b, <i32 2, i32 2> |
| 318 | %cmp = or <2 x i1> %2, %cmp3 |
| 319 | ret <2 x i1> %cmp |
| 320 | } |
| 321 | |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 322 | define i32 @neg_nuw(i32 %x) { |
| 323 | ; CHECK-LABEL: @neg_nuw( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 324 | ; CHECK-NEXT: ret i32 0 |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 325 | ; |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 326 | %neg = sub nuw i32 0, %x |
| 327 | ret i32 %neg |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 328 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 329 | |
| 330 | define i1 @and_icmp1(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 331 | ; CHECK-LABEL: @and_icmp1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 332 | ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 %x, %y |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 333 | ; CHECK-NEXT: ret i1 [[TMP1]] |
| 334 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 335 | %1 = icmp ult i32 %x, %y |
| 336 | %2 = icmp ne i32 %y, 0 |
| 337 | %3 = and i1 %1, %2 |
| 338 | ret i1 %3 |
| 339 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 340 | |
David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 341 | define i1 @and_icmp2(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 342 | ; CHECK-LABEL: @and_icmp2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 343 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 344 | ; |
David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 345 | %1 = icmp ult i32 %x, %y |
| 346 | %2 = icmp eq i32 %y, 0 |
| 347 | %3 = and i1 %1, %2 |
| 348 | ret i1 %3 |
| 349 | } |
David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 350 | |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 351 | define i1 @or_icmp1(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 352 | ; CHECK-LABEL: @or_icmp1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 353 | ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 %y, 0 |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 354 | ; CHECK-NEXT: ret i1 [[TMP1]] |
| 355 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 356 | %1 = icmp ult i32 %x, %y |
| 357 | %2 = icmp ne i32 %y, 0 |
| 358 | %3 = or i1 %1, %2 |
| 359 | ret i1 %3 |
| 360 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 361 | |
| 362 | define i1 @or_icmp2(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 363 | ; CHECK-LABEL: @or_icmp2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 364 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 365 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 366 | %1 = icmp uge i32 %x, %y |
| 367 | %2 = icmp ne i32 %y, 0 |
| 368 | %3 = or i1 %1, %2 |
| 369 | ret i1 %3 |
| 370 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 371 | |
| 372 | define i1 @or_icmp3(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 373 | ; CHECK-LABEL: @or_icmp3( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 374 | ; CHECK-NEXT: [[TMP1:%.*]] = icmp uge i32 %x, %y |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 375 | ; CHECK-NEXT: ret i1 [[TMP1]] |
| 376 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 377 | %1 = icmp uge i32 %x, %y |
| 378 | %2 = icmp eq i32 %y, 0 |
| 379 | %3 = or i1 %1, %2 |
| 380 | ret i1 %3 |
| 381 | } |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 382 | |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 383 | define i1 @disjoint_cmps(i32 %A) { |
| 384 | ; CHECK-LABEL: @disjoint_cmps( |
| 385 | ; CHECK-NEXT: ret i1 false |
| 386 | ; |
| 387 | %B = icmp eq i32 %A, 1 |
| 388 | %C = icmp sge i32 %A, 3 |
| 389 | %D = and i1 %B, %C |
| 390 | ret i1 %D |
| 391 | } |
| 392 | |
| 393 | define i1 @disjoint_cmps2(i32 %X) { |
| 394 | ; CHECK-LABEL: @disjoint_cmps2( |
| 395 | ; CHECK-NEXT: ret i1 false |
| 396 | ; |
| 397 | %a = icmp ult i32 %X, 31 |
| 398 | %b = icmp slt i32 %X, 0 |
| 399 | %c = and i1 %a, %b |
| 400 | ret i1 %c |
| 401 | } |
| 402 | |
| 403 | ; PR27869 - Look through casts to eliminate cmps and bitwise logic. |
| 404 | |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 405 | define i32 @and_of_zexted_icmps(i32 %i) { |
| 406 | ; CHECK-LABEL: @and_of_zexted_icmps( |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 407 | ; CHECK-NEXT: ret i32 0 |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 408 | ; |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 409 | %cmp0 = icmp eq i32 %i, 0 |
| 410 | %conv0 = zext i1 %cmp0 to i32 |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 411 | %cmp1 = icmp ugt i32 %i, 4 |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 412 | %conv1 = zext i1 %cmp1 to i32 |
| 413 | %and = and i32 %conv0, %conv1 |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 414 | ret i32 %and |
| 415 | } |
| 416 | |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 417 | ; Make sure vectors work too. |
| 418 | |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 419 | define <4 x i32> @and_of_zexted_icmps_vec(<4 x i32> %i) { |
| 420 | ; CHECK-LABEL: @and_of_zexted_icmps_vec( |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 421 | ; CHECK-NEXT: ret <4 x i32> zeroinitializer |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 422 | ; |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 423 | %cmp0 = icmp eq <4 x i32> %i, zeroinitializer |
| 424 | %conv0 = zext <4 x i1> %cmp0 to <4 x i32> |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 425 | %cmp1 = icmp slt <4 x i32> %i, zeroinitializer |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 426 | %conv1 = zext <4 x i1> %cmp1 to <4 x i32> |
| 427 | %and = and <4 x i32> %conv0, %conv1 |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 428 | ret <4 x i32> %and |
| 429 | } |
| 430 | |
Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 431 | ; Try a different cast and weird types. |
| 432 | |
| 433 | define i5 @and_of_sexted_icmps(i3 %i) { |
| 434 | ; CHECK-LABEL: @and_of_sexted_icmps( |
| 435 | ; CHECK-NEXT: ret i5 0 |
| 436 | ; |
| 437 | %cmp0 = icmp eq i3 %i, 0 |
| 438 | %conv0 = sext i1 %cmp0 to i5 |
| 439 | %cmp1 = icmp ugt i3 %i, 1 |
| 440 | %conv1 = sext i1 %cmp1 to i5 |
| 441 | %and = and i5 %conv0, %conv1 |
| 442 | ret i5 %and |
| 443 | } |
| 444 | |
| 445 | ; Try a different cast and weird vector types. |
| 446 | |
| 447 | define i3 @and_of_bitcast_icmps_vec(<3 x i65> %i) { |
| 448 | ; CHECK-LABEL: @and_of_bitcast_icmps_vec( |
| 449 | ; CHECK-NEXT: ret i3 0 |
| 450 | ; |
| 451 | %cmp0 = icmp sgt <3 x i65> %i, zeroinitializer |
| 452 | %conv0 = bitcast <3 x i1> %cmp0 to i3 |
| 453 | %cmp1 = icmp slt <3 x i65> %i, zeroinitializer |
| 454 | %conv1 = bitcast <3 x i1> %cmp1 to i3 |
| 455 | %and = and i3 %conv0, %conv1 |
| 456 | ret i3 %and |
| 457 | } |
| 458 | |
| 459 | ; We can't do this if the casts are different. |
| 460 | |
| 461 | define i16 @and_of_different_cast_icmps(i8 %i) { |
| 462 | ; CHECK-LABEL: @and_of_different_cast_icmps( |
| 463 | ; CHECK-NEXT: [[CMP0:%.*]] = icmp eq i8 %i, 0 |
| 464 | ; CHECK-NEXT: [[CONV0:%.*]] = zext i1 [[CMP0]] to i16 |
| 465 | ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 %i, 1 |
| 466 | ; CHECK-NEXT: [[CONV1:%.*]] = sext i1 [[CMP1]] to i16 |
| 467 | ; CHECK-NEXT: [[AND:%.*]] = and i16 [[CONV0]], [[CONV1]] |
| 468 | ; CHECK-NEXT: ret i16 [[AND]] |
| 469 | ; |
| 470 | %cmp0 = icmp eq i8 %i, 0 |
| 471 | %conv0 = zext i1 %cmp0 to i16 |
| 472 | %cmp1 = icmp eq i8 %i, 1 |
| 473 | %conv1 = sext i1 %cmp1 to i16 |
| 474 | %and = and i16 %conv0, %conv1 |
| 475 | ret i16 %and |
| 476 | } |
| 477 | |
| 478 | define <2 x i3> @and_of_different_cast_icmps_vec(<2 x i8> %i, <2 x i16> %j) { |
| 479 | ; CHECK-LABEL: @and_of_different_cast_icmps_vec( |
| 480 | ; CHECK-NEXT: [[CMP0:%.*]] = icmp eq <2 x i8> %i, zeroinitializer |
| 481 | ; CHECK-NEXT: [[CONV0:%.*]] = zext <2 x i1> [[CMP0]] to <2 x i3> |
| 482 | ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt <2 x i16> %j, <i16 1, i16 1> |
| 483 | ; CHECK-NEXT: [[CONV1:%.*]] = zext <2 x i1> [[CMP1]] to <2 x i3> |
| 484 | ; CHECK-NEXT: [[AND:%.*]] = and <2 x i3> [[CONV0]], [[CONV1]] |
| 485 | ; CHECK-NEXT: ret <2 x i3> [[AND]] |
| 486 | ; |
| 487 | %cmp0 = icmp eq <2 x i8> %i, zeroinitializer |
| 488 | %conv0 = zext <2 x i1> %cmp0 to <2 x i3> |
| 489 | %cmp1 = icmp ugt <2 x i16> %j, <i16 1, i16 1> |
| 490 | %conv1 = zext <2 x i1> %cmp1 to <2 x i3> |
| 491 | %and = and <2 x i3> %conv0, %conv1 |
| 492 | ret <2 x i3> %and |
| 493 | } |
| 494 | |