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

Side by Side Diff: src/compiler/typer.cc

Issue 1121573004: Precise shift right result type derivation for all int32 input ranges. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | test/unittests/compiler/typer-unittest.cc » ('j') | 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/base/flags.h" 5 #include "src/base/flags.h"
6 #include "src/bootstrapper.h" 6 #include "src/bootstrapper.h"
7 #include "src/compiler/graph-reducer.h" 7 #include "src/compiler/graph-reducer.h"
8 #include "src/compiler/js-operator.h" 8 #include "src/compiler/js-operator.h"
9 #include "src/compiler/node.h" 9 #include "src/compiler/node.h"
10 #include "src/compiler/node-properties.h" 10 #include "src/compiler/node-properties.h"
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 980 }
981 981
982 982
983 Type* Typer::Visitor::JSShiftLeftTyper(Type* lhs, Type* rhs, Typer* t) { 983 Type* Typer::Visitor::JSShiftLeftTyper(Type* lhs, Type* rhs, Typer* t) {
984 return Type::Signed32(); 984 return Type::Signed32();
985 } 985 }
986 986
987 987
988 Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) { 988 Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) {
989 lhs = NumberToInt32(ToNumber(lhs, t), t); 989 lhs = NumberToInt32(ToNumber(lhs, t), t);
990 rhs = NumberToUint32(ToNumber(rhs, t), t); 990 rhs = NumberToInt32(ToNumber(rhs, t), t);
991 double min = kMinInt; 991
992 double max = kMaxInt; 992 // Canonicalize the shift range to 0 to 31.
993 if (lhs->Min() >= 0) { 993 int32_t shift_min = rhs->Min();
titzer 2015/05/06 11:53:12 Would it be possible to pull the integer range log
994 // Right-shifting a non-negative value cannot make it negative, nor larger. 994 int32_t shift_max = rhs->Max();
995 min = std::max(min, 0.0); 995 if ((int64_t(shift_max) - int64_t(shift_min)) >= 31) {
996 max = std::min(max, lhs->Max()); 996 shift_min = 0;
997 if (rhs->Min() > 0 && rhs->Max() <= 31) { 997 shift_max = 31;
998 max = static_cast<int>(max) >> static_cast<int>(rhs->Min()); 998 } else {
999 shift_min &= 0x1f;
1000 shift_max &= 0x1f;
1001 if (shift_min > shift_max) {
1002 shift_min = 0;
1003 shift_max = 31;
999 } 1004 }
1000 } 1005 }
1001 if (lhs->Max() < 0) { 1006 DCHECK(shift_min >= 0 && shift_max <= 31);
1002 // Right-shifting a negative value cannot make it non-negative, nor smaller. 1007
1003 min = std::max(min, lhs->Min()); 1008 int32_t lmin = lhs->Min();
1004 max = std::min(max, -1.0); 1009 int32_t min = std::min(std::max(lmin, 0) >> shift_max, lmin >> shift_min);
1005 if (rhs->Min() > 0 && rhs->Max() <= 31) { 1010 int32_t lmax = lhs->Max();
1006 min = static_cast<int>(min) >> static_cast<int>(rhs->Min()); 1011 int32_t max = std::max(lmax >> shift_min, std::min(lmax, -1) >> shift_max);
1007 } 1012
1008 }
1009 if (rhs->Min() > 0 && rhs->Max() <= 31) {
1010 // Right-shifting by a positive value yields a small integer value.
1011 double shift_min = kMinInt >> static_cast<int>(rhs->Min());
1012 double shift_max = kMaxInt >> static_cast<int>(rhs->Min());
1013 min = std::max(min, shift_min);
1014 max = std::min(max, shift_max);
1015 }
1016 // TODO(jarin) Ideally, the following micro-optimization should be performed 1013 // TODO(jarin) Ideally, the following micro-optimization should be performed
1017 // by the type constructor. 1014 // by the type constructor.
1018 if (max != Type::Signed32()->Max() || min != Type::Signed32()->Min()) { 1015 if (max != Type::Signed32()->Max() || min != Type::Signed32()->Min()) {
1019 return Type::Range(min, max, t->zone()); 1016 return Type::Range(min, max, t->zone());
1020 } 1017 }
1021 return Type::Signed32(); 1018 return Type::Signed32();
1022 } 1019 }
1023 1020
1024 1021
1025 Type* Typer::Visitor::JSShiftRightLogicalTyper(Type* lhs, Type* rhs, Typer* t) { 1022 Type* Typer::Visitor::JSShiftRightLogicalTyper(Type* lhs, Type* rhs, Typer* t) {
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 TYPED_ARRAYS(TYPED_ARRAY_CASE) 2358 TYPED_ARRAYS(TYPED_ARRAY_CASE)
2362 #undef TYPED_ARRAY_CASE 2359 #undef TYPED_ARRAY_CASE
2363 } 2360 }
2364 } 2361 }
2365 return Type::Constant(value, zone()); 2362 return Type::Constant(value, zone());
2366 } 2363 }
2367 2364
2368 } // namespace compiler 2365 } // namespace compiler
2369 } // namespace internal 2366 } // namespace internal
2370 } // namespace v8 2367 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/unittests/compiler/typer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698