Skip to content

Commit 42ded33

Browse files
GeorgNeisCommit bot
authored andcommitted
[compiler] Speculate a little more in SpeculativeShiftRightLogical.
If the RHS is 0 and we have Smi feedback, speculate that the result (the LHS) will continue to be in the Unsigned31 range. This helps us avoid converting the result to double when merging with Signed32. [email protected] BUG= Review-Url: https://codereview.chromium.org/2709423002 Cr-Commit-Position: refs/heads/master@{#43415}
1 parent 2ab2bda commit 42ded33

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/compiler/simplified-lowering.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,26 @@ class RepresentationSelector {
19861986
if (BothInputsAre(node, Type::PlainPrimitive())) {
19871987
if (truncation.IsUnused()) return VisitUnused(node);
19881988
}
1989+
NumberOperationHint hint = NumberOperationHintOf(node->op());
1990+
Type* rhs_type = GetUpperBound(node->InputAt(1));
1991+
if (rhs_type->Is(type_cache_.kZeroish) &&
1992+
(hint == NumberOperationHint::kSignedSmall ||
1993+
hint == NumberOperationHint::kSigned32) &&
1994+
!truncation.IsUsedAsWord32()) {
1995+
// The SignedSmall or Signed32 feedback means that the results that we
1996+
// have seen so far were of type Unsigned31. We speculate that this
1997+
// will continue to hold. Moreover, since the RHS is 0, the result
1998+
// will just be the (converted) LHS.
1999+
VisitBinop(node, CheckedUseInfoAsWord32FromHint(hint),
2000+
MachineRepresentation::kWord32, Type::Unsigned31());
2001+
if (lower()) {
2002+
node->RemoveInput(1);
2003+
NodeProperties::ChangeOp(node,
2004+
simplified()->CheckedUint32ToInt32());
2005+
}
2006+
return;
2007+
}
19892008
if (BothInputsAre(node, Type::NumberOrOddball())) {
1990-
Type* rhs_type = GetUpperBound(node->InputAt(1));
19912009
VisitBinop(node, UseInfo::TruncatingWord32(),
19922010
UseInfo::TruncatingWord32(),
19932011
MachineRepresentation::kWord32);
@@ -1996,8 +2014,6 @@ class RepresentationSelector {
19962014
}
19972015
return;
19982016
}
1999-
NumberOperationHint hint = NumberOperationHintOf(node->op());
2000-
Type* rhs_type = GetUpperBound(node->InputAt(1));
20012017
VisitBinop(node, CheckedUseInfoAsWord32FromHint(hint),
20022018
MachineRepresentation::kWord32, Type::Unsigned32());
20032019
if (lower()) {

test/mjsunit/compiler/shift-shr.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,32 @@ assertEquals(0, test_shr(1));
2424
for (var i = 5; i >= -5; i--) {
2525
assertEquals(0, test_shr(i));
2626
}
27+
28+
29+
(function () {
30+
function foo(x, b, array) {
31+
var y;
32+
x = x >>> 0;
33+
b ? (y = x | 0) : (y = x);
34+
return array[y];
35+
}
36+
37+
foo(111, true, new Array(42));
38+
foo(111, true, new Array(42));
39+
%OptimizeFunctionOnNextCall(foo);
40+
foo(-111, true, new Array(42));
41+
})();
42+
43+
(function () {
44+
function foo(x, b, array) {
45+
var y;
46+
x = x >>> 0;
47+
b ? (y = x | 0) : (y = x);
48+
return array[y];
49+
}
50+
51+
foo(111, true, new Array(42));
52+
foo(111, true, new Array(42));
53+
%OptimizeFunctionOnNextCall(foo);
54+
foo(111, true, new Array(42));
55+
})();

0 commit comments

Comments
 (0)