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 | |
| 52 | define i1 @and_of_icmps1(i32 %b) { |
| 53 | ; CHECK-LABEL: @and_of_icmps1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 54 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 55 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 56 | %1 = add nsw i32 %b, 2 |
| 57 | %2 = icmp slt i32 %1, 4 |
| 58 | %cmp3 = icmp sgt i32 %b, 2 |
| 59 | %cmp = and i1 %2, %cmp3 |
| 60 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | define i1 @and_of_icmps2(i32 %b) { |
| 64 | ; CHECK-LABEL: @and_of_icmps2( |
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 i32 %b, 2 |
| 68 | %2 = icmp ule i32 %1, 3 |
| 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 | |
| 74 | define i1 @and_of_icmps3(i32 %b) { |
| 75 | ; CHECK-LABEL: @and_of_icmps3( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 76 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 77 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 78 | %1 = add nsw i32 %b, 2 |
| 79 | %2 = icmp sle i32 %1, 3 |
| 80 | %cmp3 = icmp sgt i32 %b, 2 |
| 81 | %cmp = and i1 %2, %cmp3 |
| 82 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | define i1 @and_of_icmps4(i32 %b) { |
| 86 | ; CHECK-LABEL: @and_of_icmps4( |
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 nuw i32 %b, 2 |
| 90 | %2 = icmp ult i32 %1, 4 |
| 91 | %cmp3 = icmp ugt 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 | |
| 96 | define i1 @and_of_icmps5(i32 %b) { |
| 97 | ; CHECK-LABEL: @and_of_icmps5( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 98 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 99 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 100 | %1 = add nuw i32 %b, 2 |
| 101 | %2 = icmp ule i32 %1, 3 |
| 102 | %cmp3 = icmp ugt i32 %b, 2 |
| 103 | %cmp = and i1 %2, %cmp3 |
| 104 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | define i1 @or_of_icmps0(i32 %b) { |
| 108 | ; CHECK-LABEL: @or_of_icmps0( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 109 | ; CHECK-NEXT: ret i1 true |
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 i32 %b, 2 |
| 112 | %2 = icmp uge i32 %1, 4 |
| 113 | %cmp3 = icmp sle i32 %b, 2 |
| 114 | %cmp = or i1 %2, %cmp3 |
| 115 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | define i1 @or_of_icmps1(i32 %b) { |
| 119 | ; CHECK-LABEL: @or_of_icmps1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 120 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 121 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 122 | %1 = add nsw i32 %b, 2 |
| 123 | %2 = icmp sge i32 %1, 4 |
| 124 | %cmp3 = icmp sle i32 %b, 2 |
| 125 | %cmp = or i1 %2, %cmp3 |
| 126 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | define i1 @or_of_icmps2(i32 %b) { |
| 130 | ; CHECK-LABEL: @or_of_icmps2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 131 | ; CHECK-NEXT: ret i1 true |
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 i32 %b, 2 |
| 134 | %2 = icmp ugt i32 %1, 3 |
| 135 | %cmp3 = icmp sle i32 %b, 2 |
| 136 | %cmp = or i1 %2, %cmp3 |
| 137 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | define i1 @or_of_icmps3(i32 %b) { |
| 141 | ; CHECK-LABEL: @or_of_icmps3( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 142 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 143 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 144 | %1 = add nsw i32 %b, 2 |
| 145 | %2 = icmp sgt i32 %1, 3 |
| 146 | %cmp3 = icmp sle i32 %b, 2 |
| 147 | %cmp = or i1 %2, %cmp3 |
| 148 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | define i1 @or_of_icmps4(i32 %b) { |
| 152 | ; CHECK-LABEL: @or_of_icmps4( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 153 | ; CHECK-NEXT: ret i1 true |
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 uge i32 %1, 4 |
| 157 | %cmp3 = icmp ule i32 %b, 2 |
| 158 | %cmp = or i1 %2, %cmp3 |
| 159 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | define i1 @or_of_icmps5(i32 %b) { |
| 163 | ; CHECK-LABEL: @or_of_icmps5( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 164 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 165 | ; |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 166 | %1 = add nuw i32 %b, 2 |
| 167 | %2 = icmp ugt i32 %1, 3 |
| 168 | %cmp3 = icmp ule i32 %b, 2 |
| 169 | %cmp = or i1 %2, %cmp3 |
| 170 | ret i1 %cmp |
David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 171 | } |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 172 | |
| 173 | define i32 @neg_nuw(i32 %x) { |
| 174 | ; CHECK-LABEL: @neg_nuw( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 175 | ; CHECK-NEXT: ret i32 0 |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 176 | ; |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 177 | %neg = sub nuw i32 0, %x |
| 178 | ret i32 %neg |
David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 179 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 180 | |
| 181 | define i1 @and_icmp1(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 182 | ; CHECK-LABEL: @and_icmp1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 183 | ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 %x, %y |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 184 | ; CHECK-NEXT: ret i1 [[TMP1]] |
| 185 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 186 | %1 = icmp ult i32 %x, %y |
| 187 | %2 = icmp ne i32 %y, 0 |
| 188 | %3 = and i1 %1, %2 |
| 189 | ret i1 %3 |
| 190 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 191 | |
David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 192 | define i1 @and_icmp2(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 193 | ; CHECK-LABEL: @and_icmp2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 194 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 195 | ; |
David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 196 | %1 = icmp ult i32 %x, %y |
| 197 | %2 = icmp eq i32 %y, 0 |
| 198 | %3 = and i1 %1, %2 |
| 199 | ret i1 %3 |
| 200 | } |
David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 201 | |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 202 | define i1 @or_icmp1(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 203 | ; CHECK-LABEL: @or_icmp1( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 204 | ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 %y, 0 |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 205 | ; CHECK-NEXT: ret i1 [[TMP1]] |
| 206 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 207 | %1 = icmp ult i32 %x, %y |
| 208 | %2 = icmp ne i32 %y, 0 |
| 209 | %3 = or i1 %1, %2 |
| 210 | ret i1 %3 |
| 211 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 212 | |
| 213 | define i1 @or_icmp2(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 214 | ; CHECK-LABEL: @or_icmp2( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 215 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 216 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 217 | %1 = icmp uge i32 %x, %y |
| 218 | %2 = icmp ne i32 %y, 0 |
| 219 | %3 = or i1 %1, %2 |
| 220 | ret i1 %3 |
| 221 | } |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 222 | |
| 223 | define i1 @or_icmp3(i32 %x, i32 %y) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 224 | ; CHECK-LABEL: @or_icmp3( |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 225 | ; CHECK-NEXT: [[TMP1:%.*]] = icmp uge i32 %x, %y |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 226 | ; CHECK-NEXT: ret i1 [[TMP1]] |
| 227 | ; |
David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 228 | %1 = icmp uge i32 %x, %y |
| 229 | %2 = icmp eq i32 %y, 0 |
| 230 | %3 = or i1 %1, %2 |
| 231 | ret i1 %3 |
| 232 | } |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 233 | |
Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame^] | 234 | define i32 @and_of_zexted_icmps(i32 %i) { |
| 235 | ; CHECK-LABEL: @and_of_zexted_icmps( |
| 236 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %i, 0 |
| 237 | ; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32 |
| 238 | ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 %i, 4 |
| 239 | ; CHECK-NEXT: [[CONV2:%.*]] = zext i1 [[CMP1]] to i32 |
| 240 | ; CHECK-NEXT: [[AND:%.*]] = and i32 [[CONV]], [[CONV2]] |
| 241 | ; CHECK-NEXT: ret i32 [[AND]] |
| 242 | ; |
| 243 | %cmp = icmp eq i32 %i, 0 |
| 244 | %conv = zext i1 %cmp to i32 |
| 245 | %cmp1 = icmp ugt i32 %i, 4 |
| 246 | %conv2 = zext i1 %cmp1 to i32 |
| 247 | %and = and i32 %conv, %conv2 |
| 248 | ret i32 %and |
| 249 | } |
| 250 | |
| 251 | define <4 x i32> @and_of_zexted_icmps_vec(<4 x i32> %i) { |
| 252 | ; CHECK-LABEL: @and_of_zexted_icmps_vec( |
| 253 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i32> %i, zeroinitializer |
| 254 | ; CHECK-NEXT: [[CONV:%.*]] = zext <4 x i1> [[CMP]] to <4 x i32> |
| 255 | ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt <4 x i32> %i, zeroinitializer |
| 256 | ; CHECK-NEXT: [[CONV2:%.*]] = zext <4 x i1> [[CMP1]] to <4 x i32> |
| 257 | ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[CONV]], [[CONV2]] |
| 258 | ; CHECK-NEXT: ret <4 x i32> [[AND]] |
| 259 | ; |
| 260 | %cmp = icmp eq <4 x i32> %i, zeroinitializer |
| 261 | %conv = zext <4 x i1> %cmp to <4 x i32> |
| 262 | %cmp1 = icmp slt <4 x i32> %i, zeroinitializer |
| 263 | %conv2 = zext <4 x i1> %cmp1 to <4 x i32> |
| 264 | %and = and <4 x i32> %conv, %conv2 |
| 265 | ret <4 x i32> %and |
| 266 | } |
| 267 | |