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