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

Side by Side Diff: test/cctest/compiler/test-js-typed-lowering.cc

Issue 1092353002: [strong] Disallow implicit conversions for binary arithmetic operations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase :( Created 5 years, 8 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/js-graph.h" 5 #include "src/compiler/js-graph.h"
6 #include "src/compiler/js-typed-lowering.h" 6 #include "src/compiler/js-typed-lowering.h"
7 #include "src/compiler/machine-operator.h" 7 #include "src/compiler/machine-operator.h"
8 #include "src/compiler/node-properties.h" 8 #include "src/compiler/node-properties.h"
9 #include "src/compiler/opcodes.h" 9 #include "src/compiler/opcodes.h"
10 #include "src/compiler/operator-properties.h" 10 #include "src/compiler/operator-properties.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 #if 0 220 #if 0
221 TEST(StringBinops) { 221 TEST(StringBinops) {
222 JSTypedLoweringTester R; 222 JSTypedLoweringTester R;
223 223
224 for (size_t i = 0; i < arraysize(kStringTypes); ++i) { 224 for (size_t i = 0; i < arraysize(kStringTypes); ++i) {
225 Node* p0 = R.Parameter(kStringTypes[i], 0); 225 Node* p0 = R.Parameter(kStringTypes[i], 0);
226 226
227 for (size_t j = 0; j < arraysize(kStringTypes); ++j) { 227 for (size_t j = 0; j < arraysize(kStringTypes); ++j) {
228 Node* p1 = R.Parameter(kStringTypes[j], 1); 228 Node* p1 = R.Parameter(kStringTypes[j], 1);
229 229
230 Node* add = R.Binop(R.javascript.Add(), p0, p1); 230 Node* add = R.Binop(R.javascript.Add(language_mode), p0, p1);
231 Node* r = R.reduce(add); 231 Node* r = R.reduce(add);
232 232
233 R.CheckPureBinop(IrOpcode::kStringAdd, r); 233 R.CheckPureBinop(IrOpcode::kStringAdd, r);
234 CHECK_EQ(p0, r->InputAt(0)); 234 CHECK_EQ(p0, r->InputAt(0));
235 CHECK_EQ(p1, r->InputAt(1)); 235 CHECK_EQ(p1, r->InputAt(1));
236 } 236 }
237 } 237 }
238 } 238 }
239 #endif 239 #endif
240 240
241 241
242 TEST(AddNumber1) { 242 TEST_WITH_STRONG(AddNumber1) {
243 JSTypedLoweringTester R; 243 JSTypedLoweringTester R;
244 for (size_t i = 0; i < arraysize(kNumberTypes); ++i) { 244 for (size_t i = 0; i < arraysize(kNumberTypes); ++i) {
245 Node* p0 = R.Parameter(kNumberTypes[i], 0); 245 Node* p0 = R.Parameter(kNumberTypes[i], 0);
246 Node* p1 = R.Parameter(kNumberTypes[i], 1); 246 Node* p1 = R.Parameter(kNumberTypes[i], 1);
247 Node* add = R.Binop(R.javascript.Add(), p0, p1); 247 Node* add = R.Binop(R.javascript.Add(language_mode), p0, p1);
248 Node* r = R.reduce(add); 248 Node* r = R.reduce(add);
249 249
250 R.CheckPureBinop(IrOpcode::kNumberAdd, r); 250 R.CheckPureBinop(IrOpcode::kNumberAdd, r);
251 CHECK_EQ(p0, r->InputAt(0)); 251 CHECK_EQ(p0, r->InputAt(0));
252 CHECK_EQ(p1, r->InputAt(1)); 252 CHECK_EQ(p1, r->InputAt(1));
253 } 253 }
254 } 254 }
255 255
256 256
257 TEST(NumberBinops) { 257 TEST_WITH_STRONG(NumberBinops) {
258 JSTypedLoweringTester R; 258 JSTypedLoweringTester R;
259 const Operator* ops[] = { 259 const Operator* ops[] = {
260 R.javascript.Add(), R.simplified.NumberAdd(), 260 R.javascript.Add(language_mode), R.simplified.NumberAdd(),
261 R.javascript.Subtract(), R.simplified.NumberSubtract(), 261 R.javascript.Subtract(language_mode), R.simplified.NumberSubtract(),
262 R.javascript.Multiply(), R.simplified.NumberMultiply(), 262 R.javascript.Multiply(language_mode), R.simplified.NumberMultiply(),
263 R.javascript.Divide(), R.simplified.NumberDivide(), 263 R.javascript.Divide(language_mode), R.simplified.NumberDivide(),
264 R.javascript.Modulus(), R.simplified.NumberModulus(), 264 R.javascript.Modulus(language_mode), R.simplified.NumberModulus(),
265 }; 265 };
266 266
267 for (size_t i = 0; i < arraysize(kNumberTypes); ++i) { 267 for (size_t i = 0; i < arraysize(kNumberTypes); ++i) {
268 Node* p0 = R.Parameter(kNumberTypes[i], 0); 268 Node* p0 = R.Parameter(kNumberTypes[i], 0);
269 269
270 for (size_t j = 0; j < arraysize(kNumberTypes); ++j) { 270 for (size_t j = 0; j < arraysize(kNumberTypes); ++j) {
271 Node* p1 = R.Parameter(kNumberTypes[j], 1); 271 Node* p1 = R.Parameter(kNumberTypes[j], 1);
272 272
273 for (size_t k = 0; k < arraysize(ops); k += 2) { 273 for (size_t k = 0; k < arraysize(ops); k += 2) {
274 Node* add = R.Binop(ops[k], p0, p1); 274 Node* add = R.Binop(ops[k], p0, p1);
(...skipping 19 matching lines...) Expand all
294 double v = OpParameter<double>(new_input); 294 double v = OpParameter<double>(new_input);
295 double e = static_cast<double>(is_signed ? FastD2I(v) : FastD2UI(v)); 295 double e = static_cast<double>(is_signed ? FastD2I(v) : FastD2UI(v));
296 CHECK_EQ(e, v); 296 CHECK_EQ(e, v);
297 } 297 }
298 } 298 }
299 299
300 300
301 // A helper class for testing lowering of bitwise shift operators. 301 // A helper class for testing lowering of bitwise shift operators.
302 class JSBitwiseShiftTypedLoweringTester : public JSTypedLoweringTester { 302 class JSBitwiseShiftTypedLoweringTester : public JSTypedLoweringTester {
303 public: 303 public:
304 explicit JSBitwiseShiftTypedLoweringTester(LanguageMode language_mode)
305 : JSTypedLoweringTester(), language_mode_(language_mode) {
306 int i = 0;
307 set(i++, javascript.ShiftLeft(language_mode_), true);
308 set(i++, machine.Word32Shl(), false);
309 set(i++, javascript.ShiftRight(language_mode_), true);
310 set(i++, machine.Word32Sar(), false);
311 set(i++, javascript.ShiftRightLogical(language_mode_), false);
312 set(i++, machine.Word32Shr(), false);
313 }
304 static const int kNumberOps = 6; 314 static const int kNumberOps = 6;
305 const Operator* ops[kNumberOps]; 315 const Operator* ops[kNumberOps];
306 bool signedness[kNumberOps]; 316 bool signedness[kNumberOps];
307 317
308 JSBitwiseShiftTypedLoweringTester() {
309 int i = 0;
310 set(i++, javascript.ShiftLeft(), true);
311 set(i++, machine.Word32Shl(), false);
312 set(i++, javascript.ShiftRight(), true);
313 set(i++, machine.Word32Sar(), false);
314 set(i++, javascript.ShiftRightLogical(), false);
315 set(i++, machine.Word32Shr(), false);
316 }
317
318 private: 318 private:
319 LanguageMode language_mode_;
319 void set(int idx, const Operator* op, bool s) { 320 void set(int idx, const Operator* op, bool s) {
320 ops[idx] = op; 321 ops[idx] = op;
321 signedness[idx] = s; 322 signedness[idx] = s;
322 } 323 }
323 }; 324 };
324 325
325 326
326 TEST(Int32BitwiseShifts) { 327 TEST(Int32BitwiseShifts) {
327 JSBitwiseShiftTypedLoweringTester R; 328 JSBitwiseShiftTypedLoweringTester R(LanguageMode::SLOPPY);
328 329
329 Type* types[] = { 330 Type* types[] = {
330 Type::SignedSmall(), Type::UnsignedSmall(), Type::Negative32(), 331 Type::SignedSmall(), Type::UnsignedSmall(), Type::Negative32(),
331 Type::Unsigned31(), Type::Unsigned32(), Type::Signed32(), 332 Type::Unsigned31(), Type::Unsigned32(), Type::Signed32(),
332 Type::MinusZero(), Type::NaN(), Type::Undefined(), 333 Type::MinusZero(), Type::NaN(), Type::Undefined(),
333 Type::Null(), Type::Boolean(), Type::Number(), 334 Type::Null(), Type::Boolean(), Type::Number(),
334 Type::PlainNumber(), Type::String()}; 335 Type::PlainNumber(), Type::String()};
335 336
336 for (size_t i = 0; i < arraysize(types); ++i) { 337 for (size_t i = 0; i < arraysize(types); ++i) {
337 Node* p0 = R.Parameter(types[i], 0); 338 Node* p0 = R.Parameter(types[i], 0);
(...skipping 20 matching lines...) Expand all
358 } 359 }
359 } 360 }
360 } 361 }
361 } 362 }
362 } 363 }
363 364
364 365
365 // A helper class for testing lowering of bitwise operators. 366 // A helper class for testing lowering of bitwise operators.
366 class JSBitwiseTypedLoweringTester : public JSTypedLoweringTester { 367 class JSBitwiseTypedLoweringTester : public JSTypedLoweringTester {
367 public: 368 public:
369 explicit JSBitwiseTypedLoweringTester(LanguageMode language_mode)
370 : JSTypedLoweringTester(), language_mode_(language_mode) {
371 int i = 0;
372 set(i++, javascript.BitwiseOr(language_mode_), true);
373 set(i++, machine.Word32Or(), true);
374 set(i++, javascript.BitwiseXor(language_mode_), true);
375 set(i++, machine.Word32Xor(), true);
376 set(i++, javascript.BitwiseAnd(language_mode_), true);
377 set(i++, machine.Word32And(), true);
378 }
368 static const int kNumberOps = 6; 379 static const int kNumberOps = 6;
369 const Operator* ops[kNumberOps]; 380 const Operator* ops[kNumberOps];
370 bool signedness[kNumberOps]; 381 bool signedness[kNumberOps];
371 382
372 JSBitwiseTypedLoweringTester() {
373 int i = 0;
374 set(i++, javascript.BitwiseOr(), true);
375 set(i++, machine.Word32Or(), true);
376 set(i++, javascript.BitwiseXor(), true);
377 set(i++, machine.Word32Xor(), true);
378 set(i++, javascript.BitwiseAnd(), true);
379 set(i++, machine.Word32And(), true);
380 }
381
382 private: 383 private:
384 LanguageMode language_mode_;
383 void set(int idx, const Operator* op, bool s) { 385 void set(int idx, const Operator* op, bool s) {
384 ops[idx] = op; 386 ops[idx] = op;
385 signedness[idx] = s; 387 signedness[idx] = s;
386 } 388 }
387 }; 389 };
388 390
389 391
390 TEST(Int32BitwiseBinops) { 392 TEST(Int32BitwiseBinops) {
391 JSBitwiseTypedLoweringTester R; 393 JSBitwiseTypedLoweringTester R(LanguageMode::SLOPPY);
392 394
393 Type* types[] = { 395 Type* types[] = {
394 Type::SignedSmall(), Type::UnsignedSmall(), Type::Unsigned32(), 396 Type::SignedSmall(), Type::UnsignedSmall(), Type::Unsigned32(),
395 Type::Signed32(), Type::MinusZero(), Type::NaN(), 397 Type::Signed32(), Type::MinusZero(), Type::NaN(),
396 Type::OrderedNumber(), Type::PlainNumber(), Type::Undefined(), 398 Type::OrderedNumber(), Type::PlainNumber(), Type::Undefined(),
397 Type::Null(), Type::Boolean(), Type::Number(), 399 Type::Null(), Type::Boolean(), Type::Number(),
398 Type::String()}; 400 Type::String()};
399 401
400 for (size_t i = 0; i < arraysize(types); ++i) { 402 for (size_t i = 0; i < arraysize(types); ++i) {
401 Node* p0 = R.Parameter(types[i], 0); 403 Node* p0 = R.Parameter(types[i], 0);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 CHECK_EQ(IrOpcode::kHeapConstant, r->opcode()); 574 CHECK_EQ(IrOpcode::kHeapConstant, r->opcode());
573 } 575 }
574 576
575 CHECK_EQ(n, add->InputAt(0)); 577 CHECK_EQ(n, add->InputAt(0));
576 CHECK_EQ(r, add->InputAt(1)); 578 CHECK_EQ(r, add->InputAt(1));
577 R.CheckEffectInput(R.start(), effect_use); 579 R.CheckEffectInput(R.start(), effect_use);
578 } 580 }
579 } 581 }
580 582
581 583
582 TEST(StringComparison) { 584 TEST_WITH_STRONG(StringComparison) {
583 JSTypedLoweringTester R; 585 JSTypedLoweringTester R;
584 586
585 const Operator* ops[] = { 587 const Operator* ops[] = {
586 R.javascript.LessThan(), R.simplified.StringLessThan(), 588 R.javascript.LessThan(language_mode), R.simplified.StringLessThan(),
587 R.javascript.LessThanOrEqual(), R.simplified.StringLessThanOrEqual(), 589 R.javascript.LessThanOrEqual(language_mode),
588 R.javascript.GreaterThan(), R.simplified.StringLessThan(), 590 R.simplified.StringLessThanOrEqual(),
589 R.javascript.GreaterThanOrEqual(), R.simplified.StringLessThanOrEqual()}; 591 R.javascript.GreaterThan(language_mode), R.simplified.StringLessThan(),
592 R.javascript.GreaterThanOrEqual(language_mode),
593 R.simplified.StringLessThanOrEqual()};
590 594
591 for (size_t i = 0; i < arraysize(kStringTypes); i++) { 595 for (size_t i = 0; i < arraysize(kStringTypes); i++) {
592 Node* p0 = R.Parameter(kStringTypes[i], 0); 596 Node* p0 = R.Parameter(kStringTypes[i], 0);
593 for (size_t j = 0; j < arraysize(kStringTypes); j++) { 597 for (size_t j = 0; j < arraysize(kStringTypes); j++) {
594 Node* p1 = R.Parameter(kStringTypes[j], 1); 598 Node* p1 = R.Parameter(kStringTypes[j], 1);
595 599
596 for (size_t k = 0; k < arraysize(ops); k += 2) { 600 for (size_t k = 0; k < arraysize(ops); k += 2) {
597 Node* cmp = R.Binop(ops[k], p0, p1); 601 Node* cmp = R.Binop(ops[k], p0, p1);
598 Node* r = R.reduce(cmp); 602 Node* r = R.reduce(cmp);
599 603
(...skipping 20 matching lines...) Expand all
620 CHECK_EQ(IrOpcode::kBooleanToNumber, converted->opcode()); 624 CHECK_EQ(IrOpcode::kBooleanToNumber, converted->opcode());
621 CHECK_EQ(val, converted->InputAt(0)); 625 CHECK_EQ(val, converted->InputAt(0));
622 } else { 626 } else {
623 if (converted->opcode() == IrOpcode::kNumberConstant) return; 627 if (converted->opcode() == IrOpcode::kNumberConstant) return;
624 CHECK_EQ(IrOpcode::kJSToNumber, converted->opcode()); 628 CHECK_EQ(IrOpcode::kJSToNumber, converted->opcode());
625 CHECK_EQ(val, converted->InputAt(0)); 629 CHECK_EQ(val, converted->InputAt(0));
626 } 630 }
627 } 631 }
628 632
629 633
630 TEST(NumberComparison) { 634 TEST_WITH_STRONG(NumberComparison) {
631 JSTypedLoweringTester R; 635 JSTypedLoweringTester R;
632 636
633 const Operator* ops[] = { 637 const Operator* ops[] = {
634 R.javascript.LessThan(), R.simplified.NumberLessThan(), 638 R.javascript.LessThan(language_mode), R.simplified.NumberLessThan(),
635 R.javascript.LessThanOrEqual(), R.simplified.NumberLessThanOrEqual(), 639 R.javascript.LessThanOrEqual(language_mode),
636 R.javascript.GreaterThan(), R.simplified.NumberLessThan(), 640 R.simplified.NumberLessThanOrEqual(),
637 R.javascript.GreaterThanOrEqual(), R.simplified.NumberLessThanOrEqual()}; 641 R.javascript.GreaterThan(language_mode), R.simplified.NumberLessThan(),
642 R.javascript.GreaterThanOrEqual(language_mode),
643 R.simplified.NumberLessThanOrEqual()};
638 644
639 Node* const p0 = R.Parameter(Type::Number(), 0); 645 Node* const p0 = R.Parameter(Type::Number(), 0);
640 Node* const p1 = R.Parameter(Type::Number(), 1); 646 Node* const p1 = R.Parameter(Type::Number(), 1);
641 647
642 for (size_t k = 0; k < arraysize(ops); k += 2) { 648 for (size_t k = 0; k < arraysize(ops); k += 2) {
643 Node* cmp = R.Binop(ops[k], p0, p1); 649 Node* cmp = R.Binop(ops[k], p0, p1);
644 Node* r = R.reduce(cmp); 650 Node* r = R.reduce(cmp);
645 651
646 R.CheckPureBinop(ops[k + 1], r); 652 R.CheckPureBinop(ops[k + 1], r);
647 if (k >= 4) { 653 if (k >= 4) {
648 // GreaterThan and GreaterThanOrEqual commute the inputs 654 // GreaterThan and GreaterThanOrEqual commute the inputs
649 // and use the LessThan and LessThanOrEqual operators. 655 // and use the LessThan and LessThanOrEqual operators.
650 CheckIsConvertedToNumber(p1, r->InputAt(0)); 656 CheckIsConvertedToNumber(p1, r->InputAt(0));
651 CheckIsConvertedToNumber(p0, r->InputAt(1)); 657 CheckIsConvertedToNumber(p0, r->InputAt(1));
652 } else { 658 } else {
653 CheckIsConvertedToNumber(p0, r->InputAt(0)); 659 CheckIsConvertedToNumber(p0, r->InputAt(0));
654 CheckIsConvertedToNumber(p1, r->InputAt(1)); 660 CheckIsConvertedToNumber(p1, r->InputAt(1));
655 } 661 }
656 } 662 }
657 } 663 }
658 664
659 665
660 TEST(MixedComparison1) { 666 TEST_WITH_STRONG(MixedComparison1) {
661 JSTypedLoweringTester R; 667 JSTypedLoweringTester R;
662 668
663 Type* types[] = {Type::Number(), Type::String(), 669 Type* types[] = {Type::Number(), Type::String(),
664 Type::Union(Type::Number(), Type::String(), R.main_zone())}; 670 Type::Union(Type::Number(), Type::String(), R.main_zone())};
665 671
666 for (size_t i = 0; i < arraysize(types); i++) { 672 for (size_t i = 0; i < arraysize(types); i++) {
667 Node* p0 = R.Parameter(types[i], 0); 673 Node* p0 = R.Parameter(types[i], 0);
668 674
669 for (size_t j = 0; j < arraysize(types); j++) { 675 for (size_t j = 0; j < arraysize(types); j++) {
670 Node* p1 = R.Parameter(types[j], 1); 676 Node* p1 = R.Parameter(types[j], 1);
671 { 677 {
672 Node* cmp = R.Binop(R.javascript.LessThan(), p0, p1); 678 Node* cmp = R.Binop(R.javascript.LessThan(language_mode), p0, p1);
673 Node* r = R.reduce(cmp); 679 Node* r = R.reduce(cmp);
674 680
675 if (!types[i]->Maybe(Type::String()) || 681 if (!types[i]->Maybe(Type::String()) ||
676 !types[j]->Maybe(Type::String())) { 682 !types[j]->Maybe(Type::String())) {
677 if (types[i]->Is(Type::String()) && types[j]->Is(Type::String())) { 683 if (types[i]->Is(Type::String()) && types[j]->Is(Type::String())) {
678 R.CheckPureBinop(R.simplified.StringLessThan(), r); 684 R.CheckPureBinop(R.simplified.StringLessThan(), r);
679 } else { 685 } else {
680 R.CheckPureBinop(R.simplified.NumberLessThan(), r); 686 R.CheckPureBinop(R.simplified.NumberLessThan(), r);
681 } 687 }
682 } else { 688 } else {
683 CHECK_EQ(cmp, r); // No reduction of mixed types. 689 CHECK_EQ(cmp, r); // No reduction of mixed types.
684 } 690 }
685 } 691 }
686 } 692 }
687 } 693 }
688 } 694 }
689 695
690 696
691 TEST(RemoveToNumberEffects) { 697 TEST_WITH_STRONG(RemoveToNumberEffects) {
692 FLAG_turbo_deoptimization = true; 698 FLAG_turbo_deoptimization = true;
693 699
694 JSTypedLoweringTester R; 700 JSTypedLoweringTester R;
695 701
696 Node* effect_use = NULL; 702 Node* effect_use = NULL;
697 for (int i = 0; i < 10; i++) { 703 for (int i = 0; i < 10; i++) {
698 Node* p0 = R.Parameter(Type::Number()); 704 Node* p0 = R.Parameter(Type::Number());
699 Node* ton = R.Unop(R.javascript.ToNumber(), p0); 705 Node* ton = R.Unop(R.javascript.ToNumber(), p0);
700 Node* frame_state = R.EmptyFrameState(R.context()); 706 Node* frame_state = R.EmptyFrameState(R.context());
701 effect_use = NULL; 707 effect_use = NULL;
(...skipping 18 matching lines...) Expand all
720 R.graph.NewNode(R.javascript.ToNumber(), ton, R.context(), 726 R.graph.NewNode(R.javascript.ToNumber(), ton, R.context(),
721 frame_state, ton, R.start()); 727 frame_state, ton, R.start());
722 } else { 728 } else {
723 effect_use = R.graph.NewNode(R.javascript.ToNumber(), ton, 729 effect_use = R.graph.NewNode(R.javascript.ToNumber(), ton,
724 R.context(), ton, R.start()); 730 R.context(), ton, R.start());
725 } 731 }
726 break; 732 break;
727 case 2: 733 case 2:
728 effect_use = R.graph.NewNode(R.common.EffectPhi(1), ton, R.start()); 734 effect_use = R.graph.NewNode(R.common.EffectPhi(1), ton, R.start());
729 case 3: 735 case 3:
730 effect_use = R.graph.NewNode(R.javascript.Add(), ton, ton, R.context(), 736 effect_use = R.graph.NewNode(R.javascript.Add(language_mode), ton, ton,
731 frame_state, frame_state, ton, R.start()); 737 R.context(), frame_state, frame_state, ton,
738 R.start());
732 break; 739 break;
733 case 4: 740 case 4:
734 effect_use = R.graph.NewNode(R.javascript.Add(), p0, p0, R.context(), 741 effect_use = R.graph.NewNode(R.javascript.Add(language_mode), p0, p0,
735 frame_state, frame_state, ton, R.start()); 742 R.context(), frame_state, frame_state, ton,
743 R.start());
736 break; 744 break;
737 case 5: 745 case 5:
738 effect_use = R.graph.NewNode(R.common.Return(), p0, ton, R.start()); 746 effect_use = R.graph.NewNode(R.common.Return(), p0, ton, R.start());
739 break; 747 break;
740 case 6: 748 case 6:
741 effect_use = R.graph.NewNode(R.common.Return(), ton, ton, R.start()); 749 effect_use = R.graph.NewNode(R.common.Return(), ton, ton, R.start());
742 } 750 }
743 751
744 R.CheckEffectInput(R.start(), ton); 752 R.CheckEffectInput(R.start(), ton);
745 if (effect_use != NULL) R.CheckEffectInput(ton, effect_use); 753 if (effect_use != NULL) R.CheckEffectInput(ton, effect_use);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 TEST(StringEquality) { 891 TEST(StringEquality) {
884 JSTypedLoweringTester R; 892 JSTypedLoweringTester R;
885 Node* p0 = R.Parameter(Type::String()); 893 Node* p0 = R.Parameter(Type::String());
886 Node* p1 = R.Parameter(Type::String()); 894 Node* p1 = R.Parameter(Type::String());
887 895
888 CheckEqualityReduction(&R, true, p0, p1, IrOpcode::kStringEqual); 896 CheckEqualityReduction(&R, true, p0, p1, IrOpcode::kStringEqual);
889 CheckEqualityReduction(&R, false, p0, p1, IrOpcode::kStringEqual); 897 CheckEqualityReduction(&R, false, p0, p1, IrOpcode::kStringEqual);
890 } 898 }
891 899
892 900
893 TEST(RemovePureNumberBinopEffects) { 901 TEST_WITH_STRONG(RemovePureNumberBinopEffects) {
894 JSTypedLoweringTester R; 902 JSTypedLoweringTester R;
895 903
896 const Operator* ops[] = { 904 const Operator* ops[] = {
897 R.javascript.Equal(), R.simplified.NumberEqual(), 905 R.javascript.Equal(), R.simplified.NumberEqual(),
898 R.javascript.Add(), R.simplified.NumberAdd(), 906 R.javascript.Add(language_mode), R.simplified.NumberAdd(),
899 R.javascript.Subtract(), R.simplified.NumberSubtract(), 907 R.javascript.Subtract(language_mode), R.simplified.NumberSubtract(),
900 R.javascript.Multiply(), R.simplified.NumberMultiply(), 908 R.javascript.Multiply(language_mode), R.simplified.NumberMultiply(),
901 R.javascript.Divide(), R.simplified.NumberDivide(), 909 R.javascript.Divide(language_mode), R.simplified.NumberDivide(),
902 R.javascript.Modulus(), R.simplified.NumberModulus(), 910 R.javascript.Modulus(language_mode), R.simplified.NumberModulus(),
903 R.javascript.LessThan(), R.simplified.NumberLessThan(), 911 R.javascript.LessThan(language_mode), R.simplified.NumberLessThan(),
904 R.javascript.LessThanOrEqual(), R.simplified.NumberLessThanOrEqual(), 912 R.javascript.LessThanOrEqual(language_mode),
913 R.simplified.NumberLessThanOrEqual(),
905 }; 914 };
906 915
907 for (size_t j = 0; j < arraysize(ops); j += 2) { 916 for (size_t j = 0; j < arraysize(ops); j += 2) {
908 BinopEffectsTester B(ops[j], Type::Number(), Type::Number()); 917 BinopEffectsTester B(ops[j], Type::Number(), Type::Number());
909 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode()); 918 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode());
910 919
911 B.R.CheckPureBinop(B.result->opcode(), B.result); 920 B.R.CheckPureBinop(B.result->opcode(), B.result);
912 921
913 B.CheckNoOp(0); 922 B.CheckNoOp(0);
914 B.CheckNoOp(1); 923 B.CheckNoOp(1);
915 924
916 B.CheckEffectsRemoved(); 925 B.CheckEffectsRemoved();
917 } 926 }
918 } 927 }
919 928
920 929
921 TEST(OrderNumberBinopEffects1) { 930 TEST(OrderNumberBinopEffects1) {
922 JSTypedLoweringTester R; 931 JSTypedLoweringTester R;
923 932
924 const Operator* ops[] = { 933 const Operator* ops[] = {
925 R.javascript.Subtract(), R.simplified.NumberSubtract(), 934 R.javascript.Subtract(LanguageMode::SLOPPY),
926 R.javascript.Multiply(), R.simplified.NumberMultiply(), 935 R.simplified.NumberSubtract(),
927 R.javascript.Divide(), R.simplified.NumberDivide(), 936 R.javascript.Multiply(LanguageMode::SLOPPY),
928 R.javascript.Modulus(), R.simplified.NumberModulus(), 937 R.simplified.NumberMultiply(),
938 R.javascript.Divide(LanguageMode::SLOPPY),
939 R.simplified.NumberDivide(),
940 R.javascript.Modulus(LanguageMode::SLOPPY),
941 R.simplified.NumberModulus(),
929 }; 942 };
930 943
931 for (size_t j = 0; j < arraysize(ops); j += 2) { 944 for (size_t j = 0; j < arraysize(ops); j += 2) {
932 BinopEffectsTester B(ops[j], Type::Symbol(), Type::Symbol()); 945 BinopEffectsTester B(ops[j], Type::Symbol(), Type::Symbol());
933 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode()); 946 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode());
934 947
935 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); 948 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true);
936 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); 949 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true);
937 950
938 CHECK_EQ(B.p0, i0->InputAt(0)); 951 CHECK_EQ(B.p0, i0->InputAt(0));
939 CHECK_EQ(B.p1, i1->InputAt(0)); 952 CHECK_EQ(B.p1, i1->InputAt(0));
940 953
941 // Effects should be ordered start -> i0 -> i1 -> effect_use 954 // Effects should be ordered start -> i0 -> i1 -> effect_use
942 B.CheckEffectOrdering(i0, i1); 955 B.CheckEffectOrdering(i0, i1);
943 } 956 }
944 } 957 }
945 958
946 959
947 TEST(OrderNumberBinopEffects2) { 960 TEST(OrderNumberBinopEffects2) {
948 JSTypedLoweringTester R; 961 JSTypedLoweringTester R;
949 962
950 const Operator* ops[] = { 963 const Operator* ops[] = {
951 R.javascript.Add(), R.simplified.NumberAdd(), 964 R.javascript.Add(LanguageMode::SLOPPY),
952 R.javascript.Subtract(), R.simplified.NumberSubtract(), 965 R.simplified.NumberAdd(),
953 R.javascript.Multiply(), R.simplified.NumberMultiply(), 966 R.javascript.Subtract(LanguageMode::SLOPPY),
954 R.javascript.Divide(), R.simplified.NumberDivide(), 967 R.simplified.NumberSubtract(),
955 R.javascript.Modulus(), R.simplified.NumberModulus(), 968 R.javascript.Multiply(LanguageMode::SLOPPY),
969 R.simplified.NumberMultiply(),
970 R.javascript.Divide(LanguageMode::SLOPPY),
971 R.simplified.NumberDivide(),
972 R.javascript.Modulus(LanguageMode::SLOPPY),
973 R.simplified.NumberModulus(),
956 }; 974 };
957 975
958 for (size_t j = 0; j < arraysize(ops); j += 2) { 976 for (size_t j = 0; j < arraysize(ops); j += 2) {
959 BinopEffectsTester B(ops[j], Type::Number(), Type::Symbol()); 977 BinopEffectsTester B(ops[j], Type::Number(), Type::Symbol());
960 978
961 Node* i0 = B.CheckNoOp(0); 979 Node* i0 = B.CheckNoOp(0);
962 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); 980 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true);
963 981
964 CHECK_EQ(B.p0, i0); 982 CHECK_EQ(B.p0, i0);
965 CHECK_EQ(B.p1, i1->InputAt(0)); 983 CHECK_EQ(B.p1, i1->InputAt(0));
(...skipping 14 matching lines...) Expand all
980 // Effects should be ordered start -> i0 -> effect_use 998 // Effects should be ordered start -> i0 -> effect_use
981 B.CheckEffectOrdering(i0); 999 B.CheckEffectOrdering(i0);
982 } 1000 }
983 } 1001 }
984 1002
985 1003
986 TEST(OrderCompareEffects) { 1004 TEST(OrderCompareEffects) {
987 JSTypedLoweringTester R; 1005 JSTypedLoweringTester R;
988 1006
989 const Operator* ops[] = { 1007 const Operator* ops[] = {
990 R.javascript.GreaterThan(), R.simplified.NumberLessThan(), 1008 R.javascript.GreaterThan(LanguageMode::SLOPPY),
991 R.javascript.GreaterThanOrEqual(), R.simplified.NumberLessThanOrEqual(), 1009 R.simplified.NumberLessThan(),
1010 R.javascript.GreaterThanOrEqual(LanguageMode::SLOPPY),
1011 R.simplified.NumberLessThanOrEqual(),
992 }; 1012 };
993 1013
994 for (size_t j = 0; j < arraysize(ops); j += 2) { 1014 for (size_t j = 0; j < arraysize(ops); j += 2) {
995 BinopEffectsTester B(ops[j], Type::Symbol(), Type::String()); 1015 BinopEffectsTester B(ops[j], Type::Symbol(), Type::String());
996 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode()); 1016 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode());
997 1017
998 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); 1018 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true);
999 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); 1019 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true);
1000 1020
1001 // Inputs should be commuted. 1021 // Inputs should be commuted.
(...skipping 26 matching lines...) Expand all
1028 CHECK_EQ(B.p1, i0); // Should be commuted. 1048 CHECK_EQ(B.p1, i0); // Should be commuted.
1029 CHECK_EQ(B.p0, i1->InputAt(0)); 1049 CHECK_EQ(B.p0, i1->InputAt(0));
1030 1050
1031 // Effects should be ordered start -> i0 -> effect_use 1051 // Effects should be ordered start -> i0 -> effect_use
1032 B.CheckEffectOrdering(i1); 1052 B.CheckEffectOrdering(i1);
1033 } 1053 }
1034 } 1054 }
1035 1055
1036 1056
1037 TEST(Int32BinopEffects) { 1057 TEST(Int32BinopEffects) {
1038 JSBitwiseTypedLoweringTester R; 1058 JSBitwiseTypedLoweringTester R(LanguageMode::SLOPPY);
1039
1040 for (int j = 0; j < R.kNumberOps; j += 2) { 1059 for (int j = 0; j < R.kNumberOps; j += 2) {
1041 bool signed_left = R.signedness[j], signed_right = R.signedness[j + 1]; 1060 bool signed_left = R.signedness[j], signed_right = R.signedness[j + 1];
1042 BinopEffectsTester B(R.ops[j], I32Type(signed_left), I32Type(signed_right)); 1061 BinopEffectsTester B(R.ops[j], I32Type(signed_left), I32Type(signed_right));
1062 printf("%s\n%s\n", R.ops[j + 1]->mnemonic(), B.result->op()->mnemonic());
rossberg 2015/04/23 13:29:37 Stray debug output?
conradw 2015/04/23 14:51:55 Oops, done.
1043 CHECK_EQ(R.ops[j + 1]->opcode(), B.result->op()->opcode()); 1063 CHECK_EQ(R.ops[j + 1]->opcode(), B.result->op()->opcode());
1044 1064
1045 B.R.CheckPureBinop(B.result->opcode(), B.result); 1065 B.R.CheckPureBinop(B.result->opcode(), B.result);
1046 1066
1047 B.CheckNoOp(0); 1067 B.CheckNoOp(0);
1048 B.CheckNoOp(1); 1068 B.CheckNoOp(1);
1049 1069
1050 B.CheckEffectsRemoved(); 1070 B.CheckEffectsRemoved();
1051 } 1071 }
1052 1072
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 Node* ii1 = B.CheckConverted(IrOpcode::kJSToNumber, i1->InputAt(0), true); 1130 Node* ii1 = B.CheckConverted(IrOpcode::kJSToNumber, i1->InputAt(0), true);
1111 1131
1112 CHECK_EQ(B.p0, ii0->InputAt(0)); 1132 CHECK_EQ(B.p0, ii0->InputAt(0));
1113 CHECK_EQ(B.p1, ii1->InputAt(0)); 1133 CHECK_EQ(B.p1, ii1->InputAt(0));
1114 1134
1115 B.CheckEffectOrdering(ii0, ii1); 1135 B.CheckEffectOrdering(ii0, ii1);
1116 } 1136 }
1117 } 1137 }
1118 1138
1119 1139
1120 TEST(Int32AddNarrowing) { 1140 TEST_WITH_STRONG(Int32AddNarrowing) {
1121 { 1141 {
1122 JSBitwiseTypedLoweringTester R; 1142 JSBitwiseTypedLoweringTester R(language_mode);
1123 1143
1124 for (int o = 0; o < R.kNumberOps; o += 2) { 1144 for (int o = 0; o < R.kNumberOps; o += 2) {
1125 for (size_t i = 0; i < arraysize(kInt32Types); i++) { 1145 for (size_t i = 0; i < arraysize(kInt32Types); i++) {
1126 Node* n0 = R.Parameter(kInt32Types[i]); 1146 Node* n0 = R.Parameter(kInt32Types[i]);
1127 for (size_t j = 0; j < arraysize(kInt32Types); j++) { 1147 for (size_t j = 0; j < arraysize(kInt32Types); j++) {
1128 Node* n1 = R.Parameter(kInt32Types[j]); 1148 Node* n1 = R.Parameter(kInt32Types[j]);
1129 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); 1149 Node* one = R.graph.NewNode(R.common.NumberConstant(1));
1130 1150
1131 for (int l = 0; l < 2; l++) { 1151 for (int l = 0; l < 2; l++) {
1132 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); 1152 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1);
1133 Node* or_node = 1153 Node* or_node =
1134 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node); 1154 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node);
1135 Node* r = R.reduce(or_node); 1155 Node* r = R.reduce(or_node);
1136 1156
1137 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); 1157 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode());
1138 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); 1158 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode());
1139 } 1159 }
1140 } 1160 }
1141 } 1161 }
1142 } 1162 }
1143 } 1163 }
1144 { 1164 {
1145 JSBitwiseShiftTypedLoweringTester R; 1165 JSBitwiseShiftTypedLoweringTester R(language_mode);
1146 1166
1147 for (int o = 0; o < R.kNumberOps; o += 2) { 1167 for (int o = 0; o < R.kNumberOps; o += 2) {
1148 for (size_t i = 0; i < arraysize(kInt32Types); i++) { 1168 for (size_t i = 0; i < arraysize(kInt32Types); i++) {
1149 Node* n0 = R.Parameter(kInt32Types[i]); 1169 Node* n0 = R.Parameter(kInt32Types[i]);
1150 for (size_t j = 0; j < arraysize(kInt32Types); j++) { 1170 for (size_t j = 0; j < arraysize(kInt32Types); j++) {
1151 Node* n1 = R.Parameter(kInt32Types[j]); 1171 Node* n1 = R.Parameter(kInt32Types[j]);
1152 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); 1172 Node* one = R.graph.NewNode(R.common.NumberConstant(1));
1153 1173
1154 for (int l = 0; l < 2; l++) { 1174 for (int l = 0; l < 2; l++) {
1155 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); 1175 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1);
1156 Node* or_node = 1176 Node* or_node =
1157 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node); 1177 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node);
1158 Node* r = R.reduce(or_node); 1178 Node* r = R.reduce(or_node);
1159 1179
1160 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); 1180 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode());
1161 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); 1181 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode());
1162 } 1182 }
1163 } 1183 }
1164 } 1184 }
1165 } 1185 }
1166 } 1186 }
1167 { 1187 {
1168 JSBitwiseTypedLoweringTester R; 1188 JSBitwiseTypedLoweringTester R(language_mode);
1169 1189
1170 for (int o = 0; o < R.kNumberOps; o += 2) { 1190 for (int o = 0; o < R.kNumberOps; o += 2) {
1171 Node* n0 = R.Parameter(I32Type(R.signedness[o])); 1191 Node* n0 = R.Parameter(I32Type(R.signedness[o]));
1172 Node* n1 = R.Parameter(I32Type(R.signedness[o + 1])); 1192 Node* n1 = R.Parameter(I32Type(R.signedness[o + 1]));
1173 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); 1193 Node* one = R.graph.NewNode(R.common.NumberConstant(1));
1174 1194
1175 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); 1195 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1);
1176 Node* or_node = R.Binop(R.ops[o], add_node, one); 1196 Node* or_node = R.Binop(R.ops[o], add_node, one);
1177 Node* other_use = R.Binop(R.simplified.NumberAdd(), add_node, one); 1197 Node* other_use = R.Binop(R.simplified.NumberAdd(), add_node, one);
1178 Node* r = R.reduce(or_node); 1198 Node* r = R.reduce(or_node);
1179 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); 1199 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode());
1180 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); 1200 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode());
1181 // Conversion to int32 should be done. 1201 // Conversion to int32 should be done.
1182 CheckToI32(add_node, r->InputAt(0), R.signedness[o]); 1202 CheckToI32(add_node, r->InputAt(0), R.signedness[o]);
1183 CheckToI32(one, r->InputAt(1), R.signedness[o + 1]); 1203 CheckToI32(one, r->InputAt(1), R.signedness[o + 1]);
1184 // The other use should also not be touched. 1204 // The other use should also not be touched.
1185 CHECK_EQ(add_node, other_use->InputAt(0)); 1205 CHECK_EQ(add_node, other_use->InputAt(0));
1186 CHECK_EQ(one, other_use->InputAt(1)); 1206 CHECK_EQ(one, other_use->InputAt(1));
1187 } 1207 }
1188 } 1208 }
1189 } 1209 }
1190 1210
1191 1211
1192 TEST(Int32Comparisons) { 1212 TEST_WITH_STRONG(Int32Comparisons) {
1193 JSTypedLoweringTester R; 1213 JSTypedLoweringTester R;
1194 1214
1195 struct Entry { 1215 struct Entry {
1196 const Operator* js_op; 1216 const Operator* js_op;
1197 const Operator* uint_op; 1217 const Operator* uint_op;
1198 const Operator* int_op; 1218 const Operator* int_op;
1199 const Operator* num_op; 1219 const Operator* num_op;
1200 bool commute; 1220 bool commute;
1201 }; 1221 };
1202 1222
1203 Entry ops[] = { 1223 Entry ops[] = {
1204 {R.javascript.LessThan(), R.machine.Uint32LessThan(), 1224 {R.javascript.LessThan(language_mode), R.machine.Uint32LessThan(),
1205 R.machine.Int32LessThan(), R.simplified.NumberLessThan(), false}, 1225 R.machine.Int32LessThan(), R.simplified.NumberLessThan(), false},
1206 {R.javascript.LessThanOrEqual(), R.machine.Uint32LessThanOrEqual(), 1226 {R.javascript.LessThanOrEqual(language_mode),
1207 R.machine.Int32LessThanOrEqual(), R.simplified.NumberLessThanOrEqual(), 1227 R.machine.Uint32LessThanOrEqual(), R.machine.Int32LessThanOrEqual(),
1208 false}, 1228 R.simplified.NumberLessThanOrEqual(), false},
1209 {R.javascript.GreaterThan(), R.machine.Uint32LessThan(), 1229 {R.javascript.GreaterThan(language_mode), R.machine.Uint32LessThan(),
1210 R.machine.Int32LessThan(), R.simplified.NumberLessThan(), true}, 1230 R.machine.Int32LessThan(), R.simplified.NumberLessThan(), true},
1211 {R.javascript.GreaterThanOrEqual(), R.machine.Uint32LessThanOrEqual(), 1231 {R.javascript.GreaterThanOrEqual(language_mode),
1212 R.machine.Int32LessThanOrEqual(), R.simplified.NumberLessThanOrEqual(), 1232 R.machine.Uint32LessThanOrEqual(), R.machine.Int32LessThanOrEqual(),
1213 true}}; 1233 R.simplified.NumberLessThanOrEqual(), true}
1234 };
1214 1235
1215 for (size_t o = 0; o < arraysize(ops); o++) { 1236 for (size_t o = 0; o < arraysize(ops); o++) {
1216 for (size_t i = 0; i < arraysize(kNumberTypes); i++) { 1237 for (size_t i = 0; i < arraysize(kNumberTypes); i++) {
1217 Type* t0 = kNumberTypes[i]; 1238 Type* t0 = kNumberTypes[i];
1218 Node* p0 = R.Parameter(t0, 0); 1239 Node* p0 = R.Parameter(t0, 0);
1219 1240
1220 for (size_t j = 0; j < arraysize(kNumberTypes); j++) { 1241 for (size_t j = 0; j < arraysize(kNumberTypes); j++) {
1221 Type* t1 = kNumberTypes[j]; 1242 Type* t1 = kNumberTypes[j];
1222 Node* p1 = R.Parameter(t1, 1); 1243 Node* p1 = R.Parameter(t1, 1);
1223 1244
(...skipping 13 matching lines...) Expand all
1237 CHECK_EQ(p1, r->InputAt(0)); 1258 CHECK_EQ(p1, r->InputAt(0));
1238 CHECK_EQ(p0, r->InputAt(1)); 1259 CHECK_EQ(p0, r->InputAt(1));
1239 } else { 1260 } else {
1240 CHECK_EQ(p0, r->InputAt(0)); 1261 CHECK_EQ(p0, r->InputAt(0));
1241 CHECK_EQ(p1, r->InputAt(1)); 1262 CHECK_EQ(p1, r->InputAt(1));
1242 } 1263 }
1243 } 1264 }
1244 } 1265 }
1245 } 1266 }
1246 } 1267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698