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

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

Issue 1095063002: Use type information to eliminate unnecessary bitwise-and operations. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « src/compiler/js-typed-lowering.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/access-builder.h" 5 #include "src/compiler/access-builder.h"
6 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/js-typed-lowering.h" 7 #include "src/compiler/js-typed-lowering.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 #include "src/compiler/operator-properties.h" 10 #include "src/compiler/operator-properties.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 JSBinopReduction r(this, node); 363 JSBinopReduction r(this, node);
364 Node* frame_state = FLAG_turbo_deoptimization 364 Node* frame_state = FLAG_turbo_deoptimization
365 ? NodeProperties::GetFrameStateInput(node, 1) 365 ? NodeProperties::GetFrameStateInput(node, 1)
366 : nullptr; 366 : nullptr;
367 r.ConvertInputsToNumber(frame_state); 367 r.ConvertInputsToNumber(frame_state);
368 r.ConvertInputsToUI32(kSigned, kSigned); 368 r.ConvertInputsToUI32(kSigned, kSigned);
369 return r.ChangeToPureOperator(intOp, Type::Integral32()); 369 return r.ChangeToPureOperator(intOp, Type::Integral32());
370 } 370 }
371 371
372 372
373 Reduction JSTypedLowering::ReduceBitwiseAnd(Node* node) {
titzer 2015/04/20 12:20:39 I think you want to move this optimization to mach
374 JSBinopReduction r(this, node);
375 Node* lhs = NodeProperties::GetValueInput(node, 0);
376 Node* rhs = NodeProperties::GetValueInput(node, 1);
377 Type* lhs_type = NodeProperties::GetBounds(lhs).upper;
378 Type* rhs_type = NodeProperties::GetBounds(rhs).upper;
379 // Check if the bitwise-and operation can be eliminated - if either input is a
380 // constant power of two minus one and the other input is no greater.
381 // HELP - can it be assumed that a constant argument is always on the rhs, and
382 // thus this first case is unnecessary?
383 if (lhs_type->Min() == lhs_type->Max() &&
384 lhs_type->Max() > 0 && lhs_type->Max() <= kMaxInt) {
385 uint32_t value = lhs_type->Max();
386 if ((value & (value + 1)) == 0) {
387 if (rhs_type->Min() >= 0 && rhs_type->Max() <= value) {
388 // HELP - would like to just return the rhs, but Replace(rhs) causes
389 // errors? Replace the input with -1 which can be optimized away later.
390 node->ReplaceInput(0, jsgraph()->Int32Constant(-1));
391 }
392 }
393 }
394 if (rhs_type->Min() == rhs_type->Max() &&
395 rhs_type->Max() > 0 && rhs_type->Max() <= kMaxInt) {
396 uint32_t value = rhs_type->Max();
397 if ((value & (value + 1)) == 0) {
398 if (lhs_type->Min() >= 0 && lhs_type->Max() <= value) {
titzer 2015/04/20 12:20:40 Yep, the problem is that JS operators have value a
399 // HELP - would like to just return the rhs, but Replace(rhs) causes
400 // errors? Replace the input with -1 which can be optimized away later.
401 node->ReplaceInput(1, jsgraph()->Int32Constant(-1));
402 }
403 }
404 }
405
406 Node* frame_state = FLAG_turbo_deoptimization
407 ? NodeProperties::GetFrameStateInput(node, 1)
408 : nullptr;
409 r.ConvertInputsToNumber(frame_state);
410 r.ConvertInputsToUI32(kSigned, kSigned);
411 return r.ChangeToPureOperator(machine()->Word32And(), Type::Integral32());
412 }
413
414
373 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, 415 Reduction JSTypedLowering::ReduceUI32Shift(Node* node,
374 Signedness left_signedness, 416 Signedness left_signedness,
375 const Operator* shift_op) { 417 const Operator* shift_op) {
376 JSBinopReduction r(this, node); 418 JSBinopReduction r(this, node);
377 if (r.BothInputsAre(Type::Primitive())) { 419 if (r.BothInputsAre(Type::Primitive())) {
378 r.ConvertInputsForShift(left_signedness); 420 r.ConvertInputsForShift(left_signedness);
379 return r.ChangeToPureOperator(shift_op, Type::Integral32()); 421 return r.ChangeToPureOperator(shift_op, Type::Integral32());
380 } 422 }
381 return NoChange(); 423 return NoChange();
382 } 424 }
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 case IrOpcode::kJSLessThan: // fall through 1023 case IrOpcode::kJSLessThan: // fall through
982 case IrOpcode::kJSGreaterThan: // fall through 1024 case IrOpcode::kJSGreaterThan: // fall through
983 case IrOpcode::kJSLessThanOrEqual: // fall through 1025 case IrOpcode::kJSLessThanOrEqual: // fall through
984 case IrOpcode::kJSGreaterThanOrEqual: 1026 case IrOpcode::kJSGreaterThanOrEqual:
985 return ReduceJSComparison(node); 1027 return ReduceJSComparison(node);
986 case IrOpcode::kJSBitwiseOr: 1028 case IrOpcode::kJSBitwiseOr:
987 return ReduceInt32Binop(node, machine()->Word32Or()); 1029 return ReduceInt32Binop(node, machine()->Word32Or());
988 case IrOpcode::kJSBitwiseXor: 1030 case IrOpcode::kJSBitwiseXor:
989 return ReduceInt32Binop(node, machine()->Word32Xor()); 1031 return ReduceInt32Binop(node, machine()->Word32Xor());
990 case IrOpcode::kJSBitwiseAnd: 1032 case IrOpcode::kJSBitwiseAnd:
991 return ReduceInt32Binop(node, machine()->Word32And()); 1033 return ReduceBitwiseAnd(node);
992 case IrOpcode::kJSShiftLeft: 1034 case IrOpcode::kJSShiftLeft:
993 return ReduceUI32Shift(node, kSigned, machine()->Word32Shl()); 1035 return ReduceUI32Shift(node, kSigned, machine()->Word32Shl());
994 case IrOpcode::kJSShiftRight: 1036 case IrOpcode::kJSShiftRight:
995 return ReduceUI32Shift(node, kSigned, machine()->Word32Sar()); 1037 return ReduceUI32Shift(node, kSigned, machine()->Word32Sar());
996 case IrOpcode::kJSShiftRightLogical: 1038 case IrOpcode::kJSShiftRightLogical:
997 return ReduceUI32Shift(node, kUnsigned, machine()->Word32Shr()); 1039 return ReduceUI32Shift(node, kUnsigned, machine()->Word32Shr());
998 case IrOpcode::kJSAdd: 1040 case IrOpcode::kJSAdd:
999 return ReduceJSAdd(node); 1041 return ReduceJSAdd(node);
1000 case IrOpcode::kJSSubtract: 1042 case IrOpcode::kJSSubtract:
1001 return ReduceNumberBinop(node, simplified()->NumberSubtract()); 1043 return ReduceNumberBinop(node, simplified()->NumberSubtract());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 } 1138 }
1097 1139
1098 1140
1099 MachineOperatorBuilder* JSTypedLowering::machine() const { 1141 MachineOperatorBuilder* JSTypedLowering::machine() const {
1100 return jsgraph()->machine(); 1142 return jsgraph()->machine();
1101 } 1143 }
1102 1144
1103 } // namespace compiler 1145 } // namespace compiler
1104 } // namespace internal 1146 } // namespace internal
1105 } // namespace v8 1147 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-typed-lowering.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698