Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Side by Side Diff: test/unittests/compiler/common-operator-reducer-unittest.cc

Issue 2170343002: [turbofan] Change Float64Max/Float64Min to JavaScript semantics. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mips/mips64 ports. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/common-operator.h" 5 #include "src/compiler/common-operator.h"
6 #include "src/compiler/common-operator-reducer.h" 6 #include "src/compiler/common-operator-reducer.h"
7 #include "src/compiler/machine-operator.h" 7 #include "src/compiler/machine-operator.h"
8 #include "src/compiler/operator.h" 8 #include "src/compiler/operator.h"
9 #include "src/compiler/simplified-operator.h" 9 #include "src/compiler/simplified-operator.h"
10 #include "src/machine-type.h" 10 #include "src/machine-type.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 Node* phi = graph()->NewNode( 317 Node* phi = graph()->NewNode(
318 common()->Phi(MachineRepresentation::kFloat64, 2), vtrue, vfalse, merge); 318 common()->Phi(MachineRepresentation::kFloat64, 2), vtrue, vfalse, merge);
319 StrictMock<MockAdvancedReducerEditor> editor; 319 StrictMock<MockAdvancedReducerEditor> editor;
320 EXPECT_CALL(editor, Revisit(merge)); 320 EXPECT_CALL(editor, Revisit(merge));
321 Reduction r = Reduce(&editor, phi); 321 Reduction r = Reduce(&editor, phi);
322 ASSERT_TRUE(r.Changed()); 322 ASSERT_TRUE(r.Changed());
323 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); 323 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0));
324 } 324 }
325 325
326 326
327 TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) {
328 Node* p0 = Parameter(0);
329 Node* p1 = Parameter(1);
330 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
331 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
332 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
333 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
334 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
335 Node* phi = graph()->NewNode(
336 common()->Phi(MachineRepresentation::kFloat32, 2), p1, p0, merge);
337 StrictMock<MockAdvancedReducerEditor> editor;
338 EXPECT_CALL(editor, Revisit(merge));
339 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Max);
340 ASSERT_TRUE(r.Changed());
341 EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0));
342 }
343
344
345 TEST_F(CommonOperatorReducerTest, PhiToFloat64Max) {
346 Node* p0 = Parameter(0);
347 Node* p1 = Parameter(1);
348 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
349 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
350 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
351 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
352 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
353 Node* phi = graph()->NewNode(
354 common()->Phi(MachineRepresentation::kFloat64, 2), p1, p0, merge);
355 StrictMock<MockAdvancedReducerEditor> editor;
356 EXPECT_CALL(editor, Revisit(merge));
357 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Max);
358 ASSERT_TRUE(r.Changed());
359 EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0));
360 }
361
362
363 TEST_F(CommonOperatorReducerTest, PhiToFloat32Min) {
364 Node* p0 = Parameter(0);
365 Node* p1 = Parameter(1);
366 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
367 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
368 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
369 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
370 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
371 Node* phi = graph()->NewNode(
372 common()->Phi(MachineRepresentation::kFloat32, 2), p0, p1, merge);
373 StrictMock<MockAdvancedReducerEditor> editor;
374 EXPECT_CALL(editor, Revisit(merge));
375 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Min);
376 ASSERT_TRUE(r.Changed());
377 EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1));
378 }
379
380
381 TEST_F(CommonOperatorReducerTest, PhiToFloat64Min) {
382 Node* p0 = Parameter(0);
383 Node* p1 = Parameter(1);
384 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
385 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
386 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
387 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
388 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
389 Node* phi = graph()->NewNode(
390 common()->Phi(MachineRepresentation::kFloat64, 2), p0, p1, merge);
391 StrictMock<MockAdvancedReducerEditor> editor;
392 EXPECT_CALL(editor, Revisit(merge));
393 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Min);
394 ASSERT_TRUE(r.Changed());
395 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1));
396 }
397
398
399 // ----------------------------------------------------------------------------- 327 // -----------------------------------------------------------------------------
400 // Return 328 // Return
401 329
402 330
403 TEST_F(CommonOperatorReducerTest, ReturnWithPhiAndEffectPhiAndMerge) { 331 TEST_F(CommonOperatorReducerTest, ReturnWithPhiAndEffectPhiAndMerge) {
404 Node* cond = Parameter(2); 332 Node* cond = Parameter(2);
405 Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start()); 333 Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start());
406 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); 334 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
407 Node* etrue = graph()->start(); 335 Node* etrue = graph()->start();
408 Node* vtrue = Parameter(0); 336 Node* vtrue = Parameter(0);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 Node* c0 = Float64Constant(0.0); 435 Node* c0 = Float64Constant(0.0);
508 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); 436 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0);
509 Node* select = 437 Node* select =
510 graph()->NewNode(common()->Select(MachineRepresentation::kFloat64), check, 438 graph()->NewNode(common()->Select(MachineRepresentation::kFloat64), check,
511 p0, graph()->NewNode(machine()->Float64Sub(), c0, p0)); 439 p0, graph()->NewNode(machine()->Float64Sub(), c0, p0));
512 Reduction r = Reduce(select); 440 Reduction r = Reduce(select);
513 ASSERT_TRUE(r.Changed()); 441 ASSERT_TRUE(r.Changed());
514 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); 442 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0));
515 } 443 }
516 444
517
518 TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) {
519 Node* p0 = Parameter(0);
520 Node* p1 = Parameter(1);
521 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
522 Node* select = graph()->NewNode(
523 common()->Select(MachineRepresentation::kFloat32), check, p1, p0);
524 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Max);
525 ASSERT_TRUE(r.Changed());
526 EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0));
527 }
528
529
530 TEST_F(CommonOperatorReducerTest, SelectToFloat64Max) {
531 Node* p0 = Parameter(0);
532 Node* p1 = Parameter(1);
533 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
534 Node* select = graph()->NewNode(
535 common()->Select(MachineRepresentation::kFloat64), check, p1, p0);
536 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Max);
537 ASSERT_TRUE(r.Changed());
538 EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0));
539 }
540
541
542 TEST_F(CommonOperatorReducerTest, SelectToFloat32Min) {
543 Node* p0 = Parameter(0);
544 Node* p1 = Parameter(1);
545 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
546 Node* select = graph()->NewNode(
547 common()->Select(MachineRepresentation::kFloat32), check, p0, p1);
548 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Min);
549 ASSERT_TRUE(r.Changed());
550 EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1));
551 }
552
553
554 TEST_F(CommonOperatorReducerTest, SelectToFloat64Min) {
555 Node* p0 = Parameter(0);
556 Node* p1 = Parameter(1);
557 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
558 Node* select = graph()->NewNode(
559 common()->Select(MachineRepresentation::kFloat64), check, p0, p1);
560 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min);
561 ASSERT_TRUE(r.Changed());
562 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1));
563 }
564
565 } // namespace compiler 445 } // namespace compiler
566 } // namespace internal 446 } // namespace internal
567 } // namespace v8 447 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698