Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/common-operator.h" |
| 6 | #include "src/compiler/graph.h" |
| 7 | #include "src/compiler/machine-operator.h" |
| 8 | #include "src/compiler/node.h" |
| 9 | #include "src/compiler/node-matchers.h" |
| 10 | #include "src/compiler/opcodes.h" |
| 11 | |
| 12 | #include "test/unittests/compiler/graph-unittest.h" |
| 13 | #include "test/unittests/test-utils.h" |
| 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | namespace compiler { |
| 18 | |
| 19 | class NodeMatcherTest : public GraphTest { |
| 20 | public: |
| 21 | NodeMatcherTest() : machine_(zone()) {} |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | ~NodeMatcherTest() override {} |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | |
| 24 | MachineOperatorBuilder* machine() { return &machine_; } |
| 25 | |
| 26 | private: |
| 27 | MachineOperatorBuilder machine_; |
| 28 | }; |
| 29 | |
| 30 | namespace { |
| 31 | |
| 32 | template <class Matcher> |
| 33 | void CheckBaseWithIndexAndDisplacement(Matcher* matcher, Node* index, int scale, |
| 34 | Node* base, Node* displacement) { |
| 35 | EXPECT_TRUE(matcher->matches()); |
| 36 | EXPECT_EQ(index, matcher->index()); |
| 37 | EXPECT_EQ(scale, matcher->scale()); |
| 38 | EXPECT_EQ(base, matcher->base()); |
| 39 | EXPECT_EQ(displacement, matcher->displacement()); |
| 40 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | |
| 42 | } // namespace |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 43 | |
| 44 | |
| 45 | TEST_F(NodeMatcherTest, ScaledWithOffset32Matcher) { |
| 46 | graph()->SetStart(graph()->NewNode(common()->Start(0))); |
| 47 | |
| 48 | const Operator* d0_op = common()->Int32Constant(0); |
| 49 | Node* d0 = graph()->NewNode(d0_op); |
| 50 | USE(d0); |
| 51 | const Operator* d1_op = common()->Int32Constant(1); |
| 52 | Node* d1 = graph()->NewNode(d1_op); |
| 53 | USE(d1); |
| 54 | const Operator* d2_op = common()->Int32Constant(2); |
| 55 | Node* d2 = graph()->NewNode(d2_op); |
| 56 | USE(d2); |
| 57 | const Operator* d3_op = common()->Int32Constant(3); |
| 58 | Node* d3 = graph()->NewNode(d3_op); |
| 59 | USE(d3); |
| 60 | const Operator* d4_op = common()->Int32Constant(4); |
| 61 | Node* d4 = graph()->NewNode(d4_op); |
| 62 | USE(d4); |
| 63 | const Operator* d5_op = common()->Int32Constant(5); |
| 64 | Node* d5 = graph()->NewNode(d5_op); |
| 65 | USE(d5); |
| 66 | const Operator* d7_op = common()->Int32Constant(7); |
| 67 | Node* d7 = graph()->NewNode(d7_op); |
| 68 | USE(d4); |
| 69 | const Operator* d8_op = common()->Int32Constant(8); |
| 70 | Node* d8 = graph()->NewNode(d8_op); |
| 71 | USE(d8); |
| 72 | const Operator* d9_op = common()->Int32Constant(9); |
| 73 | Node* d9 = graph()->NewNode(d9_op); |
| 74 | USE(d9); |
| 75 | const Operator* d15_op = common()->Int32Constant(15); |
| 76 | Node* d15 = graph()->NewNode(d15_op); |
| 77 | USE(d15); |
| 78 | |
| 79 | const Operator* b0_op = common()->Parameter(0); |
| 80 | Node* b0 = graph()->NewNode(b0_op, graph()->start()); |
| 81 | USE(b0); |
| 82 | const Operator* b1_op = common()->Parameter(1); |
| 83 | Node* b1 = graph()->NewNode(b1_op, graph()->start()); |
| 84 | USE(b0); |
| 85 | |
| 86 | const Operator* p1_op = common()->Parameter(3); |
| 87 | Node* p1 = graph()->NewNode(p1_op, graph()->start()); |
| 88 | USE(p1); |
| 89 | |
| 90 | const Operator* a_op = machine()->Int32Add(); |
| 91 | USE(a_op); |
| 92 | |
| 93 | const Operator* m_op = machine()->Int32Mul(); |
| 94 | Node* m1 = graph()->NewNode(m_op, p1, d1); |
| 95 | Node* m2 = graph()->NewNode(m_op, p1, d2); |
| 96 | Node* m3 = graph()->NewNode(m_op, p1, d3); |
| 97 | Node* m4 = graph()->NewNode(m_op, p1, d4); |
| 98 | Node* m5 = graph()->NewNode(m_op, p1, d5); |
| 99 | Node* m7 = graph()->NewNode(m_op, p1, d7); |
| 100 | Node* m8 = graph()->NewNode(m_op, p1, d8); |
| 101 | Node* m9 = graph()->NewNode(m_op, p1, d9); |
| 102 | USE(m1); |
| 103 | USE(m2); |
| 104 | USE(m3); |
| 105 | USE(m4); |
| 106 | USE(m5); |
| 107 | USE(m7); |
| 108 | USE(m8); |
| 109 | USE(m9); |
| 110 | |
| 111 | const Operator* s_op = machine()->Word32Shl(); |
| 112 | Node* s0 = graph()->NewNode(s_op, p1, d0); |
| 113 | Node* s1 = graph()->NewNode(s_op, p1, d1); |
| 114 | Node* s2 = graph()->NewNode(s_op, p1, d2); |
| 115 | Node* s3 = graph()->NewNode(s_op, p1, d3); |
| 116 | Node* s4 = graph()->NewNode(s_op, p1, d4); |
| 117 | USE(s0); |
| 118 | USE(s1); |
| 119 | USE(s2); |
| 120 | USE(s3); |
| 121 | USE(s4); |
| 122 | |
| 123 | // 1 INPUT |
| 124 | |
| 125 | // Only relevant test dases is Checking for non-match. |
| 126 | BaseWithIndexAndDisplacement32Matcher match0(d15); |
| 127 | EXPECT_FALSE(match0.matches()); |
| 128 | |
| 129 | // 2 INPUT |
| 130 | |
| 131 | // (B0 + B1) -> [B0, 0, B1, NULL] |
| 132 | BaseWithIndexAndDisplacement32Matcher match1(graph()->NewNode(a_op, b0, b1)); |
| 133 | CheckBaseWithIndexAndDisplacement(&match1, b1, 0, b0, NULL); |
| 134 | |
| 135 | // (B0 + D15) -> [NULL, 0, B0, D15] |
| 136 | BaseWithIndexAndDisplacement32Matcher match2(graph()->NewNode(a_op, b0, d15)); |
| 137 | CheckBaseWithIndexAndDisplacement(&match2, NULL, 0, b0, d15); |
| 138 | |
| 139 | // (D15 + B0) -> [NULL, 0, B0, D15] |
| 140 | BaseWithIndexAndDisplacement32Matcher match3(graph()->NewNode(a_op, d15, b0)); |
| 141 | CheckBaseWithIndexAndDisplacement(&match3, NULL, 0, b0, d15); |
| 142 | |
| 143 | // (B0 + M1) -> [p1, 0, B0, NULL] |
| 144 | BaseWithIndexAndDisplacement32Matcher match4(graph()->NewNode(a_op, b0, m1)); |
| 145 | CheckBaseWithIndexAndDisplacement(&match4, p1, 0, b0, NULL); |
| 146 | |
| 147 | // (M1 + B0) -> [p1, 0, B0, NULL] |
| 148 | m1 = graph()->NewNode(m_op, p1, d1); |
| 149 | BaseWithIndexAndDisplacement32Matcher match5(graph()->NewNode(a_op, m1, b0)); |
| 150 | CheckBaseWithIndexAndDisplacement(&match5, p1, 0, b0, NULL); |
| 151 | |
| 152 | // (D15 + M1) -> [P1, 0, NULL, D15] |
| 153 | m1 = graph()->NewNode(m_op, p1, d1); |
| 154 | BaseWithIndexAndDisplacement32Matcher match6(graph()->NewNode(a_op, d15, m1)); |
| 155 | CheckBaseWithIndexAndDisplacement(&match6, p1, 0, NULL, d15); |
| 156 | |
| 157 | // (M1 + D15) -> [P1, 0, NULL, D15] |
| 158 | m1 = graph()->NewNode(m_op, p1, d1); |
| 159 | BaseWithIndexAndDisplacement32Matcher match7(graph()->NewNode(a_op, m1, d15)); |
| 160 | CheckBaseWithIndexAndDisplacement(&match7, p1, 0, NULL, d15); |
| 161 | |
| 162 | // (B0 + S0) -> [p1, 0, B0, NULL] |
| 163 | BaseWithIndexAndDisplacement32Matcher match8(graph()->NewNode(a_op, b0, s0)); |
| 164 | CheckBaseWithIndexAndDisplacement(&match8, p1, 0, b0, NULL); |
| 165 | |
| 166 | // (S0 + B0) -> [p1, 0, B0, NULL] |
| 167 | s0 = graph()->NewNode(s_op, p1, d0); |
| 168 | BaseWithIndexAndDisplacement32Matcher match9(graph()->NewNode(a_op, s0, b0)); |
| 169 | CheckBaseWithIndexAndDisplacement(&match9, p1, 0, b0, NULL); |
| 170 | |
| 171 | // (D15 + S0) -> [P1, 0, NULL, D15] |
| 172 | s0 = graph()->NewNode(s_op, p1, d0); |
| 173 | BaseWithIndexAndDisplacement32Matcher match10( |
| 174 | graph()->NewNode(a_op, d15, s0)); |
| 175 | CheckBaseWithIndexAndDisplacement(&match10, p1, 0, NULL, d15); |
| 176 | |
| 177 | // (S0 + D15) -> [P1, 0, NULL, D15] |
| 178 | s0 = graph()->NewNode(s_op, p1, d0); |
| 179 | BaseWithIndexAndDisplacement32Matcher match11( |
| 180 | graph()->NewNode(a_op, s0, d15)); |
| 181 | CheckBaseWithIndexAndDisplacement(&match11, p1, 0, NULL, d15); |
| 182 | |
| 183 | // (B0 + M2) -> [p1, 1, B0, NULL] |
| 184 | BaseWithIndexAndDisplacement32Matcher match12(graph()->NewNode(a_op, b0, m2)); |
| 185 | CheckBaseWithIndexAndDisplacement(&match12, p1, 1, b0, NULL); |
| 186 | |
| 187 | // (M2 + B0) -> [p1, 1, B0, NULL] |
| 188 | m2 = graph()->NewNode(m_op, p1, d2); |
| 189 | BaseWithIndexAndDisplacement32Matcher match13(graph()->NewNode(a_op, m2, b0)); |
| 190 | CheckBaseWithIndexAndDisplacement(&match13, p1, 1, b0, NULL); |
| 191 | |
| 192 | // (D15 + M2) -> [P1, 1, NULL, D15] |
| 193 | m2 = graph()->NewNode(m_op, p1, d2); |
| 194 | BaseWithIndexAndDisplacement32Matcher match14( |
| 195 | graph()->NewNode(a_op, d15, m2)); |
| 196 | CheckBaseWithIndexAndDisplacement(&match14, p1, 1, NULL, d15); |
| 197 | |
| 198 | // (M2 + D15) -> [P1, 1, NULL, D15] |
| 199 | m2 = graph()->NewNode(m_op, p1, d2); |
| 200 | BaseWithIndexAndDisplacement32Matcher match15( |
| 201 | graph()->NewNode(a_op, m2, d15)); |
| 202 | CheckBaseWithIndexAndDisplacement(&match15, p1, 1, NULL, d15); |
| 203 | |
| 204 | // (B0 + S1) -> [p1, 1, B0, NULL] |
| 205 | BaseWithIndexAndDisplacement32Matcher match16(graph()->NewNode(a_op, b0, s1)); |
| 206 | CheckBaseWithIndexAndDisplacement(&match16, p1, 1, b0, NULL); |
| 207 | |
| 208 | // (S1 + B0) -> [p1, 1, B0, NULL] |
| 209 | s1 = graph()->NewNode(s_op, p1, d1); |
| 210 | BaseWithIndexAndDisplacement32Matcher match17(graph()->NewNode(a_op, s1, b0)); |
| 211 | CheckBaseWithIndexAndDisplacement(&match17, p1, 1, b0, NULL); |
| 212 | |
| 213 | // (D15 + S1) -> [P1, 1, NULL, D15] |
| 214 | s1 = graph()->NewNode(s_op, p1, d1); |
| 215 | BaseWithIndexAndDisplacement32Matcher match18( |
| 216 | graph()->NewNode(a_op, d15, s1)); |
| 217 | CheckBaseWithIndexAndDisplacement(&match18, p1, 1, NULL, d15); |
| 218 | |
| 219 | // (S1 + D15) -> [P1, 1, NULL, D15] |
| 220 | s1 = graph()->NewNode(s_op, p1, d1); |
| 221 | BaseWithIndexAndDisplacement32Matcher match19( |
| 222 | graph()->NewNode(a_op, s1, d15)); |
| 223 | CheckBaseWithIndexAndDisplacement(&match19, p1, 1, NULL, d15); |
| 224 | |
| 225 | // (B0 + M4) -> [p1, 2, B0, NULL] |
| 226 | BaseWithIndexAndDisplacement32Matcher match20(graph()->NewNode(a_op, b0, m4)); |
| 227 | CheckBaseWithIndexAndDisplacement(&match20, p1, 2, b0, NULL); |
| 228 | |
| 229 | // (M4 + B0) -> [p1, 2, B0, NULL] |
| 230 | m4 = graph()->NewNode(m_op, p1, d4); |
| 231 | BaseWithIndexAndDisplacement32Matcher match21(graph()->NewNode(a_op, m4, b0)); |
| 232 | CheckBaseWithIndexAndDisplacement(&match21, p1, 2, b0, NULL); |
| 233 | |
| 234 | // (D15 + M4) -> [p1, 2, NULL, D15] |
| 235 | m4 = graph()->NewNode(m_op, p1, d4); |
| 236 | BaseWithIndexAndDisplacement32Matcher match22( |
| 237 | graph()->NewNode(a_op, d15, m4)); |
| 238 | CheckBaseWithIndexAndDisplacement(&match22, p1, 2, NULL, d15); |
| 239 | |
| 240 | // (M4 + D15) -> [p1, 2, NULL, D15] |
| 241 | m4 = graph()->NewNode(m_op, p1, d4); |
| 242 | BaseWithIndexAndDisplacement32Matcher match23( |
| 243 | graph()->NewNode(a_op, m4, d15)); |
| 244 | CheckBaseWithIndexAndDisplacement(&match23, p1, 2, NULL, d15); |
| 245 | |
| 246 | // (B0 + S2) -> [p1, 2, B0, NULL] |
| 247 | BaseWithIndexAndDisplacement32Matcher match24(graph()->NewNode(a_op, b0, s2)); |
| 248 | CheckBaseWithIndexAndDisplacement(&match24, p1, 2, b0, NULL); |
| 249 | |
| 250 | // (S2 + B0) -> [p1, 2, B0, NULL] |
| 251 | s2 = graph()->NewNode(s_op, p1, d2); |
| 252 | BaseWithIndexAndDisplacement32Matcher match25(graph()->NewNode(a_op, s2, b0)); |
| 253 | CheckBaseWithIndexAndDisplacement(&match25, p1, 2, b0, NULL); |
| 254 | |
| 255 | // (D15 + S2) -> [p1, 2, NULL, D15] |
| 256 | s2 = graph()->NewNode(s_op, p1, d2); |
| 257 | BaseWithIndexAndDisplacement32Matcher match26( |
| 258 | graph()->NewNode(a_op, d15, s2)); |
| 259 | CheckBaseWithIndexAndDisplacement(&match26, p1, 2, NULL, d15); |
| 260 | |
| 261 | // (S2 + D15) -> [p1, 2, NULL, D15] |
| 262 | s2 = graph()->NewNode(s_op, p1, d2); |
| 263 | BaseWithIndexAndDisplacement32Matcher match27( |
| 264 | graph()->NewNode(a_op, s2, d15)); |
| 265 | CheckBaseWithIndexAndDisplacement(&match27, p1, 2, NULL, d15); |
| 266 | |
| 267 | // (B0 + M8) -> [p1, 2, B0, NULL] |
| 268 | BaseWithIndexAndDisplacement32Matcher match28(graph()->NewNode(a_op, b0, m8)); |
| 269 | CheckBaseWithIndexAndDisplacement(&match28, p1, 3, b0, NULL); |
| 270 | |
| 271 | // (M8 + B0) -> [p1, 2, B0, NULL] |
| 272 | m8 = graph()->NewNode(m_op, p1, d8); |
| 273 | BaseWithIndexAndDisplacement32Matcher match29(graph()->NewNode(a_op, m8, b0)); |
| 274 | CheckBaseWithIndexAndDisplacement(&match29, p1, 3, b0, NULL); |
| 275 | |
| 276 | // (D15 + M8) -> [p1, 2, NULL, D15] |
| 277 | m8 = graph()->NewNode(m_op, p1, d8); |
| 278 | BaseWithIndexAndDisplacement32Matcher match30( |
| 279 | graph()->NewNode(a_op, d15, m8)); |
| 280 | CheckBaseWithIndexAndDisplacement(&match30, p1, 3, NULL, d15); |
| 281 | |
| 282 | // (M8 + D15) -> [p1, 2, NULL, D15] |
| 283 | m8 = graph()->NewNode(m_op, p1, d8); |
| 284 | BaseWithIndexAndDisplacement32Matcher match31( |
| 285 | graph()->NewNode(a_op, m8, d15)); |
| 286 | CheckBaseWithIndexAndDisplacement(&match31, p1, 3, NULL, d15); |
| 287 | |
| 288 | // (B0 + S3) -> [p1, 2, B0, NULL] |
| 289 | BaseWithIndexAndDisplacement32Matcher match32(graph()->NewNode(a_op, b0, s3)); |
| 290 | CheckBaseWithIndexAndDisplacement(&match32, p1, 3, b0, NULL); |
| 291 | |
| 292 | // (S3 + B0) -> [p1, 2, B0, NULL] |
| 293 | s3 = graph()->NewNode(s_op, p1, d3); |
| 294 | BaseWithIndexAndDisplacement32Matcher match33(graph()->NewNode(a_op, s3, b0)); |
| 295 | CheckBaseWithIndexAndDisplacement(&match33, p1, 3, b0, NULL); |
| 296 | |
| 297 | // (D15 + S3) -> [p1, 2, NULL, D15] |
| 298 | s3 = graph()->NewNode(s_op, p1, d3); |
| 299 | BaseWithIndexAndDisplacement32Matcher match34( |
| 300 | graph()->NewNode(a_op, d15, s3)); |
| 301 | CheckBaseWithIndexAndDisplacement(&match34, p1, 3, NULL, d15); |
| 302 | |
| 303 | // (S3 + D15) -> [p1, 2, NULL, D15] |
| 304 | s3 = graph()->NewNode(s_op, p1, d3); |
| 305 | BaseWithIndexAndDisplacement32Matcher match35( |
| 306 | graph()->NewNode(a_op, s3, d15)); |
| 307 | CheckBaseWithIndexAndDisplacement(&match35, p1, 3, NULL, d15); |
| 308 | |
| 309 | // 2 INPUT - NEGATIVE CASES |
| 310 | |
| 311 | // (M3 + B1) -> [B0, 0, M3, NULL] |
| 312 | BaseWithIndexAndDisplacement32Matcher match36(graph()->NewNode(a_op, b1, m3)); |
| 313 | CheckBaseWithIndexAndDisplacement(&match36, m3, 0, b1, NULL); |
| 314 | |
| 315 | // (S4 + B1) -> [B0, 0, S4, NULL] |
| 316 | BaseWithIndexAndDisplacement32Matcher match37(graph()->NewNode(a_op, b1, s4)); |
| 317 | CheckBaseWithIndexAndDisplacement(&match37, s4, 0, b1, NULL); |
| 318 | |
| 319 | // 3 INPUT |
| 320 | |
| 321 | // (D15 + S3) + B0 -> [p1, 2, b0, d15] |
| 322 | s3 = graph()->NewNode(s_op, p1, d3); |
| 323 | BaseWithIndexAndDisplacement32Matcher match38( |
| 324 | graph()->NewNode(a_op, graph()->NewNode(a_op, d15, s3), b0)); |
| 325 | CheckBaseWithIndexAndDisplacement(&match38, p1, 3, b0, d15); |
| 326 | |
| 327 | // (B0 + D15) + S3 -> [p1, 2, b0, d15] |
| 328 | s3 = graph()->NewNode(s_op, p1, d3); |
| 329 | BaseWithIndexAndDisplacement32Matcher match39( |
| 330 | graph()->NewNode(a_op, graph()->NewNode(a_op, b0, d15), s3)); |
| 331 | CheckBaseWithIndexAndDisplacement(&match39, p1, 3, b0, d15); |
| 332 | |
| 333 | // (S3 + B0) + D15 -> [p1, 2, b0, d15] |
| 334 | s3 = graph()->NewNode(s_op, p1, d3); |
| 335 | BaseWithIndexAndDisplacement32Matcher match40( |
| 336 | graph()->NewNode(a_op, graph()->NewNode(a_op, s3, b0), d15)); |
| 337 | CheckBaseWithIndexAndDisplacement(&match40, p1, 3, b0, d15); |
| 338 | |
| 339 | // D15 + (S3 + B0) -> [p1, 2, b0, d15] |
| 340 | s3 = graph()->NewNode(s_op, p1, d3); |
| 341 | BaseWithIndexAndDisplacement32Matcher match41( |
| 342 | graph()->NewNode(a_op, d15, graph()->NewNode(a_op, s3, b0))); |
| 343 | CheckBaseWithIndexAndDisplacement(&match41, p1, 3, b0, d15); |
| 344 | |
| 345 | // B0 + (D15 + S3) -> [p1, 2, b0, d15] |
| 346 | s3 = graph()->NewNode(s_op, p1, d3); |
| 347 | BaseWithIndexAndDisplacement32Matcher match42( |
| 348 | graph()->NewNode(a_op, b0, graph()->NewNode(a_op, d15, s3))); |
| 349 | CheckBaseWithIndexAndDisplacement(&match42, p1, 3, b0, d15); |
| 350 | |
| 351 | // S3 + (B0 + D15) -> [p1, 2, b0, d15] |
| 352 | s3 = graph()->NewNode(s_op, p1, d3); |
| 353 | BaseWithIndexAndDisplacement32Matcher match43( |
| 354 | graph()->NewNode(a_op, s3, graph()->NewNode(a_op, b0, d15))); |
| 355 | CheckBaseWithIndexAndDisplacement(&match43, p1, 3, b0, d15); |
| 356 | |
| 357 | // Check that scales that require using the base address work dorrectly. |
| 358 | } |
| 359 | |
| 360 | |
| 361 | TEST_F(NodeMatcherTest, ScaledWithOffset64Matcher) { |
| 362 | graph()->SetStart(graph()->NewNode(common()->Start(0))); |
| 363 | |
| 364 | const Operator* d0_op = common()->Int64Constant(0); |
| 365 | Node* d0 = graph()->NewNode(d0_op); |
| 366 | USE(d0); |
| 367 | const Operator* d1_op = common()->Int64Constant(1); |
| 368 | Node* d1 = graph()->NewNode(d1_op); |
| 369 | USE(d1); |
| 370 | const Operator* d2_op = common()->Int64Constant(2); |
| 371 | Node* d2 = graph()->NewNode(d2_op); |
| 372 | USE(d2); |
| 373 | const Operator* d3_op = common()->Int64Constant(3); |
| 374 | Node* d3 = graph()->NewNode(d3_op); |
| 375 | USE(d3); |
| 376 | const Operator* d4_op = common()->Int64Constant(4); |
| 377 | Node* d4 = graph()->NewNode(d4_op); |
| 378 | USE(d4); |
| 379 | const Operator* d5_op = common()->Int64Constant(5); |
| 380 | Node* d5 = graph()->NewNode(d5_op); |
| 381 | USE(d5); |
| 382 | const Operator* d7_op = common()->Int64Constant(7); |
| 383 | Node* d7 = graph()->NewNode(d7_op); |
| 384 | USE(d7); |
| 385 | const Operator* d8_op = common()->Int64Constant(8); |
| 386 | Node* d8 = graph()->NewNode(d8_op); |
| 387 | USE(d8); |
| 388 | const Operator* d9_op = common()->Int64Constant(9); |
| 389 | Node* d9 = graph()->NewNode(d9_op); |
| 390 | USE(d8); |
| 391 | const Operator* d15_op = common()->Int64Constant(15); |
| 392 | Node* d15 = graph()->NewNode(d15_op); |
| 393 | USE(d15); |
| 394 | const Operator* d15_32_op = common()->Int32Constant(15); |
| 395 | Node* d15_32 = graph()->NewNode(d15_32_op); |
| 396 | USE(d15_32); |
| 397 | |
| 398 | const Operator* b0_op = common()->Parameter(0); |
| 399 | Node* b0 = graph()->NewNode(b0_op, graph()->start()); |
| 400 | USE(b0); |
| 401 | const Operator* b1_op = common()->Parameter(1); |
| 402 | Node* b1 = graph()->NewNode(b1_op, graph()->start()); |
| 403 | USE(b0); |
| 404 | |
| 405 | const Operator* p1_op = common()->Parameter(3); |
| 406 | Node* p1 = graph()->NewNode(p1_op, graph()->start()); |
| 407 | USE(p1); |
| 408 | |
| 409 | const Operator* a_op = machine()->Int64Add(); |
| 410 | USE(a_op); |
| 411 | |
| 412 | const Operator* m_op = machine()->Int64Mul(); |
| 413 | Node* m1 = graph()->NewNode(m_op, p1, d1); |
| 414 | Node* m2 = graph()->NewNode(m_op, p1, d2); |
| 415 | Node* m3 = graph()->NewNode(m_op, p1, d3); |
| 416 | Node* m4 = graph()->NewNode(m_op, p1, d4); |
| 417 | Node* m5 = graph()->NewNode(m_op, p1, d5); |
| 418 | Node* m7 = graph()->NewNode(m_op, p1, d7); |
| 419 | Node* m8 = graph()->NewNode(m_op, p1, d8); |
| 420 | Node* m9 = graph()->NewNode(m_op, p1, d9); |
| 421 | USE(m1); |
| 422 | USE(m2); |
| 423 | USE(m3); |
| 424 | USE(m4); |
| 425 | USE(m5); |
| 426 | USE(m7); |
| 427 | USE(m8); |
| 428 | USE(m9); |
| 429 | |
| 430 | const Operator* s_op = machine()->Word64Shl(); |
| 431 | Node* s0 = graph()->NewNode(s_op, p1, d0); |
| 432 | Node* s1 = graph()->NewNode(s_op, p1, d1); |
| 433 | Node* s2 = graph()->NewNode(s_op, p1, d2); |
| 434 | Node* s3 = graph()->NewNode(s_op, p1, d3); |
| 435 | Node* s4 = graph()->NewNode(s_op, p1, d4); |
| 436 | USE(s0); |
| 437 | USE(s1); |
| 438 | USE(s2); |
| 439 | USE(s3); |
| 440 | USE(s4); |
| 441 | |
| 442 | // 1 INPUT |
| 443 | |
| 444 | // Only relevant test dases is Checking for non-match. |
| 445 | BaseWithIndexAndDisplacement64Matcher match0(d15); |
| 446 | EXPECT_FALSE(match0.matches()); |
| 447 | |
| 448 | // 2 INPUT |
| 449 | |
| 450 | // (B0 + B1) -> [B0, 0, B1, NULL] |
| 451 | BaseWithIndexAndDisplacement64Matcher match1(graph()->NewNode(a_op, b0, b1)); |
| 452 | CheckBaseWithIndexAndDisplacement(&match1, b1, 0, b0, NULL); |
| 453 | |
| 454 | // (B0 + D15) -> [NULL, 0, B0, D15] |
| 455 | BaseWithIndexAndDisplacement64Matcher match2(graph()->NewNode(a_op, b0, d15)); |
| 456 | CheckBaseWithIndexAndDisplacement(&match2, NULL, 0, b0, d15); |
| 457 | |
| 458 | BaseWithIndexAndDisplacement64Matcher match2_32( |
| 459 | graph()->NewNode(a_op, b0, d15_32)); |
| 460 | CheckBaseWithIndexAndDisplacement(&match2_32, NULL, 0, b0, d15_32); |
| 461 | |
| 462 | // (D15 + B0) -> [NULL, 0, B0, D15] |
| 463 | BaseWithIndexAndDisplacement64Matcher match3(graph()->NewNode(a_op, d15, b0)); |
| 464 | CheckBaseWithIndexAndDisplacement(&match3, NULL, 0, b0, d15); |
| 465 | |
| 466 | // (B0 + M1) -> [p1, 0, B0, NULL] |
| 467 | BaseWithIndexAndDisplacement64Matcher match4(graph()->NewNode(a_op, b0, m1)); |
| 468 | CheckBaseWithIndexAndDisplacement(&match4, p1, 0, b0, NULL); |
| 469 | |
| 470 | // (M1 + B0) -> [p1, 0, B0, NULL] |
| 471 | m1 = graph()->NewNode(m_op, p1, d1); |
| 472 | BaseWithIndexAndDisplacement64Matcher match5(graph()->NewNode(a_op, m1, b0)); |
| 473 | CheckBaseWithIndexAndDisplacement(&match5, p1, 0, b0, NULL); |
| 474 | |
| 475 | // (D15 + M1) -> [P1, 0, NULL, D15] |
| 476 | m1 = graph()->NewNode(m_op, p1, d1); |
| 477 | BaseWithIndexAndDisplacement64Matcher match6(graph()->NewNode(a_op, d15, m1)); |
| 478 | CheckBaseWithIndexAndDisplacement(&match6, p1, 0, NULL, d15); |
| 479 | |
| 480 | // (M1 + D15) -> [P1, 0, NULL, D15] |
| 481 | m1 = graph()->NewNode(m_op, p1, d1); |
| 482 | BaseWithIndexAndDisplacement64Matcher match7(graph()->NewNode(a_op, m1, d15)); |
| 483 | CheckBaseWithIndexAndDisplacement(&match7, p1, 0, NULL, d15); |
| 484 | |
| 485 | // (B0 + S0) -> [p1, 0, B0, NULL] |
| 486 | BaseWithIndexAndDisplacement64Matcher match8(graph()->NewNode(a_op, b0, s0)); |
| 487 | CheckBaseWithIndexAndDisplacement(&match8, p1, 0, b0, NULL); |
| 488 | |
| 489 | // (S0 + B0) -> [p1, 0, B0, NULL] |
| 490 | s0 = graph()->NewNode(s_op, p1, d0); |
| 491 | BaseWithIndexAndDisplacement64Matcher match9(graph()->NewNode(a_op, s0, b0)); |
| 492 | CheckBaseWithIndexAndDisplacement(&match9, p1, 0, b0, NULL); |
| 493 | |
| 494 | // (D15 + S0) -> [P1, 0, NULL, D15] |
| 495 | s0 = graph()->NewNode(s_op, p1, d0); |
| 496 | BaseWithIndexAndDisplacement64Matcher match10( |
| 497 | graph()->NewNode(a_op, d15, s0)); |
| 498 | CheckBaseWithIndexAndDisplacement(&match10, p1, 0, NULL, d15); |
| 499 | |
| 500 | // (S0 + D15) -> [P1, 0, NULL, D15] |
| 501 | s0 = graph()->NewNode(s_op, p1, d0); |
| 502 | BaseWithIndexAndDisplacement64Matcher match11( |
| 503 | graph()->NewNode(a_op, s0, d15)); |
| 504 | CheckBaseWithIndexAndDisplacement(&match11, p1, 0, NULL, d15); |
| 505 | |
| 506 | // (B0 + M2) -> [p1, 1, B0, NULL] |
| 507 | BaseWithIndexAndDisplacement64Matcher match12(graph()->NewNode(a_op, b0, m2)); |
| 508 | CheckBaseWithIndexAndDisplacement(&match12, p1, 1, b0, NULL); |
| 509 | |
| 510 | // (M2 + B0) -> [p1, 1, B0, NULL] |
| 511 | m2 = graph()->NewNode(m_op, p1, d2); |
| 512 | BaseWithIndexAndDisplacement64Matcher match13(graph()->NewNode(a_op, m2, b0)); |
| 513 | CheckBaseWithIndexAndDisplacement(&match13, p1, 1, b0, NULL); |
| 514 | |
| 515 | // (D15 + M2) -> [P1, 1, NULL, D15] |
| 516 | m2 = graph()->NewNode(m_op, p1, d2); |
| 517 | BaseWithIndexAndDisplacement64Matcher match14( |
| 518 | graph()->NewNode(a_op, d15, m2)); |
| 519 | CheckBaseWithIndexAndDisplacement(&match14, p1, 1, NULL, d15); |
| 520 | |
| 521 | // (M2 + D15) -> [P1, 1, NULL, D15] |
| 522 | m2 = graph()->NewNode(m_op, p1, d2); |
| 523 | BaseWithIndexAndDisplacement64Matcher match15( |
| 524 | graph()->NewNode(a_op, m2, d15)); |
| 525 | CheckBaseWithIndexAndDisplacement(&match15, p1, 1, NULL, d15); |
| 526 | |
| 527 | // (B0 + S1) -> [p1, 1, B0, NULL] |
| 528 | BaseWithIndexAndDisplacement64Matcher match16(graph()->NewNode(a_op, b0, s1)); |
| 529 | CheckBaseWithIndexAndDisplacement(&match16, p1, 1, b0, NULL); |
| 530 | |
| 531 | // (S1 + B0) -> [p1, 1, B0, NULL] |
| 532 | s1 = graph()->NewNode(s_op, p1, d1); |
| 533 | BaseWithIndexAndDisplacement64Matcher match17(graph()->NewNode(a_op, s1, b0)); |
| 534 | CheckBaseWithIndexAndDisplacement(&match17, p1, 1, b0, NULL); |
| 535 | |
| 536 | // (D15 + S1) -> [P1, 1, NULL, D15] |
| 537 | s1 = graph()->NewNode(s_op, p1, d1); |
| 538 | BaseWithIndexAndDisplacement64Matcher match18( |
| 539 | graph()->NewNode(a_op, d15, s1)); |
| 540 | CheckBaseWithIndexAndDisplacement(&match18, p1, 1, NULL, d15); |
| 541 | |
| 542 | // (S1 + D15) -> [P1, 1, NULL, D15] |
| 543 | s1 = graph()->NewNode(s_op, p1, d1); |
| 544 | BaseWithIndexAndDisplacement64Matcher match19( |
| 545 | graph()->NewNode(a_op, s1, d15)); |
| 546 | CheckBaseWithIndexAndDisplacement(&match19, p1, 1, NULL, d15); |
| 547 | |
| 548 | // (B0 + M4) -> [p1, 2, B0, NULL] |
| 549 | BaseWithIndexAndDisplacement64Matcher match20(graph()->NewNode(a_op, b0, m4)); |
| 550 | CheckBaseWithIndexAndDisplacement(&match20, p1, 2, b0, NULL); |
| 551 | |
| 552 | // (M4 + B0) -> [p1, 2, B0, NULL] |
| 553 | m4 = graph()->NewNode(m_op, p1, d4); |
| 554 | BaseWithIndexAndDisplacement64Matcher match21(graph()->NewNode(a_op, m4, b0)); |
| 555 | CheckBaseWithIndexAndDisplacement(&match21, p1, 2, b0, NULL); |
| 556 | |
| 557 | // (D15 + M4) -> [p1, 2, NULL, D15] |
| 558 | m4 = graph()->NewNode(m_op, p1, d4); |
| 559 | BaseWithIndexAndDisplacement64Matcher match22( |
| 560 | graph()->NewNode(a_op, d15, m4)); |
| 561 | CheckBaseWithIndexAndDisplacement(&match22, p1, 2, NULL, d15); |
| 562 | |
| 563 | // (M4 + D15) -> [p1, 2, NULL, D15] |
| 564 | m4 = graph()->NewNode(m_op, p1, d4); |
| 565 | BaseWithIndexAndDisplacement64Matcher match23( |
| 566 | graph()->NewNode(a_op, m4, d15)); |
| 567 | CheckBaseWithIndexAndDisplacement(&match23, p1, 2, NULL, d15); |
| 568 | |
| 569 | // (B0 + S2) -> [p1, 2, B0, NULL] |
| 570 | BaseWithIndexAndDisplacement64Matcher match24(graph()->NewNode(a_op, b0, s2)); |
| 571 | CheckBaseWithIndexAndDisplacement(&match24, p1, 2, b0, NULL); |
| 572 | |
| 573 | // (S2 + B0) -> [p1, 2, B0, NULL] |
| 574 | s2 = graph()->NewNode(s_op, p1, d2); |
| 575 | BaseWithIndexAndDisplacement64Matcher match25(graph()->NewNode(a_op, s2, b0)); |
| 576 | CheckBaseWithIndexAndDisplacement(&match25, p1, 2, b0, NULL); |
| 577 | |
| 578 | // (D15 + S2) -> [p1, 2, NULL, D15] |
| 579 | s2 = graph()->NewNode(s_op, p1, d2); |
| 580 | BaseWithIndexAndDisplacement64Matcher match26( |
| 581 | graph()->NewNode(a_op, d15, s2)); |
| 582 | CheckBaseWithIndexAndDisplacement(&match26, p1, 2, NULL, d15); |
| 583 | |
| 584 | // (S2 + D15) -> [p1, 2, NULL, D15] |
| 585 | s2 = graph()->NewNode(s_op, p1, d2); |
| 586 | BaseWithIndexAndDisplacement64Matcher match27( |
| 587 | graph()->NewNode(a_op, s2, d15)); |
| 588 | CheckBaseWithIndexAndDisplacement(&match27, p1, 2, NULL, d15); |
| 589 | |
| 590 | // (B0 + M8) -> [p1, 2, B0, NULL] |
| 591 | BaseWithIndexAndDisplacement64Matcher match28(graph()->NewNode(a_op, b0, m8)); |
| 592 | CheckBaseWithIndexAndDisplacement(&match28, p1, 3, b0, NULL); |
| 593 | |
| 594 | // (M8 + B0) -> [p1, 2, B0, NULL] |
| 595 | m8 = graph()->NewNode(m_op, p1, d8); |
| 596 | BaseWithIndexAndDisplacement64Matcher match29(graph()->NewNode(a_op, m8, b0)); |
| 597 | CheckBaseWithIndexAndDisplacement(&match29, p1, 3, b0, NULL); |
| 598 | |
| 599 | // (D15 + M8) -> [p1, 2, NULL, D15] |
| 600 | m8 = graph()->NewNode(m_op, p1, d8); |
| 601 | BaseWithIndexAndDisplacement64Matcher match30( |
| 602 | graph()->NewNode(a_op, d15, m8)); |
| 603 | CheckBaseWithIndexAndDisplacement(&match30, p1, 3, NULL, d15); |
| 604 | |
| 605 | // (M8 + D15) -> [p1, 2, NULL, D15] |
| 606 | m8 = graph()->NewNode(m_op, p1, d8); |
| 607 | BaseWithIndexAndDisplacement64Matcher match31( |
| 608 | graph()->NewNode(a_op, m8, d15)); |
| 609 | CheckBaseWithIndexAndDisplacement(&match31, p1, 3, NULL, d15); |
| 610 | |
| 611 | // (B0 + S3) -> [p1, 2, B0, NULL] |
| 612 | BaseWithIndexAndDisplacement64Matcher match64(graph()->NewNode(a_op, b0, s3)); |
| 613 | CheckBaseWithIndexAndDisplacement(&match64, p1, 3, b0, NULL); |
| 614 | |
| 615 | // (S3 + B0) -> [p1, 2, B0, NULL] |
| 616 | s3 = graph()->NewNode(s_op, p1, d3); |
| 617 | BaseWithIndexAndDisplacement64Matcher match33(graph()->NewNode(a_op, s3, b0)); |
| 618 | CheckBaseWithIndexAndDisplacement(&match33, p1, 3, b0, NULL); |
| 619 | |
| 620 | // (D15 + S3) -> [p1, 2, NULL, D15] |
| 621 | s3 = graph()->NewNode(s_op, p1, d3); |
| 622 | BaseWithIndexAndDisplacement64Matcher match34( |
| 623 | graph()->NewNode(a_op, d15, s3)); |
| 624 | CheckBaseWithIndexAndDisplacement(&match34, p1, 3, NULL, d15); |
| 625 | |
| 626 | // (S3 + D15) -> [p1, 2, NULL, D15] |
| 627 | s3 = graph()->NewNode(s_op, p1, d3); |
| 628 | BaseWithIndexAndDisplacement64Matcher match35( |
| 629 | graph()->NewNode(a_op, s3, d15)); |
| 630 | CheckBaseWithIndexAndDisplacement(&match35, p1, 3, NULL, d15); |
| 631 | |
| 632 | // 2 INPUT - NEGATIVE CASES |
| 633 | |
| 634 | // (M3 + B1) -> [B0, 0, M3, NULL] |
| 635 | BaseWithIndexAndDisplacement64Matcher match36(graph()->NewNode(a_op, b1, m3)); |
| 636 | CheckBaseWithIndexAndDisplacement(&match36, m3, 0, b1, NULL); |
| 637 | |
| 638 | // (S4 + B1) -> [B0, 0, S4, NULL] |
| 639 | BaseWithIndexAndDisplacement64Matcher match37(graph()->NewNode(a_op, b1, s4)); |
| 640 | CheckBaseWithIndexAndDisplacement(&match37, s4, 0, b1, NULL); |
| 641 | |
| 642 | // 3 INPUT |
| 643 | |
| 644 | // (D15 + S3) + B0 -> [p1, 2, b0, d15] |
| 645 | s3 = graph()->NewNode(s_op, p1, d3); |
| 646 | BaseWithIndexAndDisplacement64Matcher match38( |
| 647 | graph()->NewNode(a_op, graph()->NewNode(a_op, d15, s3), b0)); |
| 648 | CheckBaseWithIndexAndDisplacement(&match38, p1, 3, b0, d15); |
| 649 | |
| 650 | // (B0 + D15) + S3 -> [p1, 2, b0, d15] |
| 651 | s3 = graph()->NewNode(s_op, p1, d3); |
| 652 | BaseWithIndexAndDisplacement64Matcher match39( |
| 653 | graph()->NewNode(a_op, graph()->NewNode(a_op, b0, d15), s3)); |
| 654 | CheckBaseWithIndexAndDisplacement(&match39, p1, 3, b0, d15); |
| 655 | |
| 656 | // (S3 + B0) + D15 -> [p1, 2, b0, d15] |
| 657 | s3 = graph()->NewNode(s_op, p1, d3); |
| 658 | BaseWithIndexAndDisplacement64Matcher match40( |
| 659 | graph()->NewNode(a_op, graph()->NewNode(a_op, s3, b0), d15)); |
| 660 | CheckBaseWithIndexAndDisplacement(&match40, p1, 3, b0, d15); |
| 661 | |
| 662 | // D15 + (S3 + B0) -> [p1, 2, b0, d15] |
| 663 | s3 = graph()->NewNode(s_op, p1, d3); |
| 664 | BaseWithIndexAndDisplacement64Matcher match41( |
| 665 | graph()->NewNode(a_op, d15, graph()->NewNode(a_op, s3, b0))); |
| 666 | CheckBaseWithIndexAndDisplacement(&match41, p1, 3, b0, d15); |
| 667 | |
| 668 | // B0 + (D15 + S3) -> [p1, 2, b0, d15] |
| 669 | s3 = graph()->NewNode(s_op, p1, d3); |
| 670 | BaseWithIndexAndDisplacement64Matcher match42( |
| 671 | graph()->NewNode(a_op, b0, graph()->NewNode(a_op, d15, s3))); |
| 672 | CheckBaseWithIndexAndDisplacement(&match42, p1, 3, b0, d15); |
| 673 | |
| 674 | // S3 + (B0 + D15) -> [p1, 2, b0, d15] |
| 675 | s3 = graph()->NewNode(s_op, p1, d3); |
| 676 | BaseWithIndexAndDisplacement64Matcher match43( |
| 677 | graph()->NewNode(a_op, s3, graph()->NewNode(a_op, b0, d15))); |
| 678 | CheckBaseWithIndexAndDisplacement(&match43, p1, 3, b0, d15); |
| 679 | |
| 680 | // 2 INPUT with non-power of 2 scale |
| 681 | |
| 682 | // (M3 + D15) -> [p1, 1, p1, D15] |
| 683 | m3 = graph()->NewNode(m_op, p1, d3); |
| 684 | BaseWithIndexAndDisplacement64Matcher match44( |
| 685 | graph()->NewNode(a_op, m3, d15)); |
| 686 | CheckBaseWithIndexAndDisplacement(&match44, p1, 1, p1, d15); |
| 687 | |
| 688 | // (M5 + D15) -> [p1, 2, p1, D15] |
| 689 | m5 = graph()->NewNode(m_op, p1, d5); |
| 690 | BaseWithIndexAndDisplacement64Matcher match45( |
| 691 | graph()->NewNode(a_op, m5, d15)); |
| 692 | CheckBaseWithIndexAndDisplacement(&match45, p1, 2, p1, d15); |
| 693 | |
| 694 | // (M9 + D15) -> [p1, 3, p1, D15] |
| 695 | m9 = graph()->NewNode(m_op, p1, d9); |
| 696 | BaseWithIndexAndDisplacement64Matcher match46( |
| 697 | graph()->NewNode(a_op, m9, d15)); |
| 698 | CheckBaseWithIndexAndDisplacement(&match46, p1, 3, p1, d15); |
| 699 | |
| 700 | // 3 INPUT negative cases: non-power of 2 scale but with a base |
| 701 | |
| 702 | // ((M3 + B0) + D15) -> [m3, 0, b0, D15] |
| 703 | m3 = graph()->NewNode(m_op, p1, d3); |
| 704 | Node* temp = graph()->NewNode(a_op, m3, b0); |
| 705 | BaseWithIndexAndDisplacement64Matcher match47( |
| 706 | graph()->NewNode(a_op, temp, d15)); |
| 707 | CheckBaseWithIndexAndDisplacement(&match47, m3, 0, b0, d15); |
| 708 | |
| 709 | // (M3 + (B0 + D15)) -> [m3, 0, b0, D15] |
| 710 | m3 = graph()->NewNode(m_op, p1, d3); |
| 711 | temp = graph()->NewNode(a_op, d15, b0); |
| 712 | BaseWithIndexAndDisplacement64Matcher match48( |
| 713 | graph()->NewNode(a_op, m3, temp)); |
| 714 | CheckBaseWithIndexAndDisplacement(&match48, m3, 0, b0, d15); |
| 715 | |
| 716 | // ((B0 + M3) + D15) -> [m3, 0, b0, D15] |
| 717 | m3 = graph()->NewNode(m_op, p1, d3); |
| 718 | temp = graph()->NewNode(a_op, b0, m3); |
| 719 | BaseWithIndexAndDisplacement64Matcher match49( |
| 720 | graph()->NewNode(a_op, temp, d15)); |
| 721 | CheckBaseWithIndexAndDisplacement(&match49, m3, 0, b0, d15); |
| 722 | |
| 723 | // (M3 + (D15 + B0)) -> [m3, 0, b0, D15] |
| 724 | m3 = graph()->NewNode(m_op, p1, d3); |
| 725 | temp = graph()->NewNode(a_op, b0, d15); |
| 726 | BaseWithIndexAndDisplacement64Matcher match50( |
| 727 | graph()->NewNode(a_op, m3, temp)); |
| 728 | CheckBaseWithIndexAndDisplacement(&match50, m3, 0, b0, d15); |
| 729 | } |
| 730 | |
| 731 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 732 | TEST_F(NodeMatcherTest, BranchMatcher_match) { |
| 733 | Node* zero = graph()->NewNode(common()->Int32Constant(0)); |
| 734 | |
| 735 | { |
| 736 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 737 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 738 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 739 | BranchMatcher matcher(branch); |
| 740 | EXPECT_TRUE(matcher.Matched()); |
| 741 | EXPECT_EQ(branch, matcher.Branch()); |
| 742 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 743 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 744 | } |
| 745 | |
| 746 | { |
| 747 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 748 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 749 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 750 | BranchMatcher matcher(branch); |
| 751 | EXPECT_TRUE(matcher.Matched()); |
| 752 | EXPECT_EQ(branch, matcher.Branch()); |
| 753 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 754 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 755 | } |
| 756 | |
| 757 | { |
| 758 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 759 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 760 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 761 | Node* other = graph()->NewNode(common()->IfValue(33), branch); |
| 762 | BranchMatcher matcher(branch); |
| 763 | EXPECT_TRUE(matcher.Matched()); |
| 764 | EXPECT_EQ(branch, matcher.Branch()); |
| 765 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 766 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 767 | USE(other); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | |
| 772 | TEST_F(NodeMatcherTest, BranchMatcher_fail) { |
| 773 | Node* zero = graph()->NewNode(common()->Int32Constant(0)); |
| 774 | |
| 775 | { |
| 776 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 777 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 778 | BranchMatcher matcher(branch); |
| 779 | EXPECT_FALSE(matcher.Matched()); |
| 780 | USE(if_true); |
| 781 | } |
| 782 | |
| 783 | { |
| 784 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 785 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 786 | BranchMatcher matcher(branch); |
| 787 | EXPECT_FALSE(matcher.Matched()); |
| 788 | USE(if_false); |
| 789 | } |
| 790 | |
| 791 | { |
| 792 | BranchMatcher matcher(zero); |
| 793 | EXPECT_FALSE(matcher.Matched()); |
| 794 | } |
| 795 | |
| 796 | { |
| 797 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 798 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 799 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 800 | EXPECT_TRUE(BranchMatcher(branch).Matched()); |
| 801 | EXPECT_FALSE(BranchMatcher(if_true).Matched()); |
| 802 | EXPECT_FALSE(BranchMatcher(if_false).Matched()); |
| 803 | } |
| 804 | |
| 805 | { |
| 806 | Node* sw = graph()->NewNode(common()->Switch(5), zero, graph()->start()); |
| 807 | Node* if_true = graph()->NewNode(common()->IfTrue(), sw); |
| 808 | Node* if_false = graph()->NewNode(common()->IfFalse(), sw); |
| 809 | EXPECT_FALSE(BranchMatcher(sw).Matched()); |
| 810 | EXPECT_FALSE(BranchMatcher(if_true).Matched()); |
| 811 | EXPECT_FALSE(BranchMatcher(if_false).Matched()); |
| 812 | } |
| 813 | |
| 814 | { |
| 815 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 816 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 817 | Node* if_value = graph()->NewNode(common()->IfValue(2), branch); |
| 818 | BranchMatcher matcher(branch); |
| 819 | EXPECT_FALSE(matcher.Matched()); |
| 820 | EXPECT_FALSE(BranchMatcher(if_true).Matched()); |
| 821 | EXPECT_FALSE(BranchMatcher(if_value).Matched()); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | TEST_F(NodeMatcherTest, DiamondMatcher_match) { |
| 827 | Node* zero = graph()->NewNode(common()->Int32Constant(0)); |
| 828 | |
| 829 | { |
| 830 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 831 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 832 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 833 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 834 | DiamondMatcher matcher(merge); |
| 835 | EXPECT_TRUE(matcher.Matched()); |
| 836 | EXPECT_EQ(branch, matcher.Branch()); |
| 837 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 838 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 839 | EXPECT_EQ(merge, matcher.Merge()); |
| 840 | } |
| 841 | |
| 842 | { |
| 843 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 844 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 845 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 846 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 847 | DiamondMatcher matcher(merge); |
| 848 | EXPECT_TRUE(matcher.Matched()); |
| 849 | EXPECT_EQ(branch, matcher.Branch()); |
| 850 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 851 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 852 | EXPECT_EQ(merge, matcher.Merge()); |
| 853 | } |
| 854 | |
| 855 | { |
| 856 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 857 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 858 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 859 | Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_true); |
| 860 | DiamondMatcher matcher(merge); |
| 861 | EXPECT_TRUE(matcher.Matched()); |
| 862 | EXPECT_EQ(branch, matcher.Branch()); |
| 863 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 864 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 865 | EXPECT_EQ(merge, matcher.Merge()); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | |
| 870 | TEST_F(NodeMatcherTest, DiamondMatcher_fail) { |
| 871 | Node* zero = graph()->NewNode(common()->Int32Constant(0)); |
| 872 | |
| 873 | { |
| 874 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 875 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 876 | Node* if_value = graph()->NewNode(common()->IfValue(1), branch); |
| 877 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_value); |
| 878 | DiamondMatcher matcher(merge); |
| 879 | EXPECT_FALSE(matcher.Matched()); |
| 880 | } |
| 881 | |
| 882 | { |
| 883 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 884 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 885 | Node* if_value = graph()->NewNode(common()->IfValue(1), branch); |
| 886 | Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_value); |
| 887 | DiamondMatcher matcher(merge); |
| 888 | EXPECT_FALSE(matcher.Matched()); |
| 889 | } |
| 890 | |
| 891 | { |
| 892 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 893 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 894 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 895 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 896 | DiamondMatcher matcher(merge); |
| 897 | EXPECT_TRUE(matcher.Matched()); |
| 898 | EXPECT_EQ(branch, matcher.Branch()); |
| 899 | EXPECT_EQ(if_true, matcher.IfTrue()); |
| 900 | EXPECT_EQ(if_false, matcher.IfFalse()); |
| 901 | EXPECT_EQ(merge, matcher.Merge()); |
| 902 | |
| 903 | EXPECT_FALSE(DiamondMatcher(branch).Matched()); // Must be the merge. |
| 904 | EXPECT_FALSE(DiamondMatcher(if_true).Matched()); |
| 905 | EXPECT_FALSE(DiamondMatcher(if_false).Matched()); |
| 906 | } |
| 907 | |
| 908 | { |
| 909 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 910 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 911 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 912 | Node* merge = graph()->NewNode(common()->Merge(3), if_true, if_false, |
| 913 | graph()->start()); |
| 914 | DiamondMatcher matcher(merge); |
| 915 | EXPECT_FALSE(matcher.Matched()); // Too many inputs to merge. |
| 916 | } |
| 917 | |
| 918 | { |
| 919 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 920 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 921 | Node* if_false = graph()->start(); |
| 922 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 923 | DiamondMatcher matcher(merge); |
| 924 | EXPECT_FALSE(matcher.Matched()); |
| 925 | } |
| 926 | |
| 927 | { |
| 928 | Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 929 | Node* if_true = graph()->start(); |
| 930 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 931 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 932 | DiamondMatcher matcher(merge); |
| 933 | EXPECT_FALSE(matcher.Matched()); |
| 934 | } |
| 935 | |
| 936 | { |
| 937 | Node* branch1 = |
| 938 | graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 939 | Node* branch2 = |
| 940 | graph()->NewNode(common()->Branch(), zero, graph()->start()); |
| 941 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch1); |
| 942 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch2); |
| 943 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 944 | DiamondMatcher matcher(merge); |
| 945 | EXPECT_FALSE(matcher.Matched()); |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 950 | } // namespace compiler |
| 951 | } // namespace internal |
| 952 | } // namespace v8 |