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