Skip to content

Commit 966d0eb

Browse files
GeorgNeisCommit Bot
authored andcommitted
Merged: [compiler] Fix a bug in SimplifiedLowering
Revision: ba1b2cc BUG=chromium:1150649 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true Change-Id: Ic903e61ee00b7c240bed96633d1eab582c295308 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2557985 Reviewed-by: Tobias Tebbi <[email protected]> Commit-Queue: Georg Neis <[email protected]> Cr-Commit-Position: refs/branch-heads/8.8@{#10} Cr-Branched-From: 2dbcdc1-refs/heads/8.8.278@{#1} Cr-Branched-From: 366d30c-refs/heads/master@{#71094}
1 parent e7737a2 commit 966d0eb

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/compiler/simplified-lowering.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,6 @@ class RepresentationSelector {
14091409
IsSomePositiveOrderedNumber(input1_type)
14101410
? CheckForMinusZeroMode::kDontCheckForMinusZero
14111411
: CheckForMinusZeroMode::kCheckForMinusZero;
1412-
14131412
NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(mz_mode));
14141413
}
14151414

@@ -1453,6 +1452,13 @@ class RepresentationSelector {
14531452

14541453
Type left_feedback_type = TypeOf(node->InputAt(0));
14551454
Type right_feedback_type = TypeOf(node->InputAt(1));
1455+
1456+
// Using Signed32 as restriction type amounts to promising there won't be
1457+
// signed overflow. This is incompatible with relying on a Word32
1458+
// truncation in order to skip the overflow check.
1459+
Type const restriction =
1460+
truncation.IsUsedAsWord32() ? Type::Any() : Type::Signed32();
1461+
14561462
// Handle the case when no int32 checks on inputs are necessary (but
14571463
// an overflow check is needed on the output). Note that we do not
14581464
// have to do any check if at most one side can be minus zero. For
@@ -1466,7 +1472,7 @@ class RepresentationSelector {
14661472
right_upper.Is(Type::Signed32OrMinusZero()) &&
14671473
(left_upper.Is(Type::Signed32()) || right_upper.Is(Type::Signed32()))) {
14681474
VisitBinop<T>(node, UseInfo::TruncatingWord32(),
1469-
MachineRepresentation::kWord32, Type::Signed32());
1475+
MachineRepresentation::kWord32, restriction);
14701476
} else {
14711477
// If the output's truncation is identify-zeros, we can pass it
14721478
// along. Moreover, if the operation is addition and we know the
@@ -1486,8 +1492,9 @@ class RepresentationSelector {
14861492
UseInfo right_use = CheckedUseInfoAsWord32FromHint(hint, FeedbackSource(),
14871493
kIdentifyZeros);
14881494
VisitBinop<T>(node, left_use, right_use, MachineRepresentation::kWord32,
1489-
Type::Signed32());
1495+
restriction);
14901496
}
1497+
14911498
if (lower<T>()) {
14921499
if (truncation.IsUsedAsWord32() ||
14931500
!CanOverflowSigned32(node->op(), left_feedback_type,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax
6+
7+
function foo(a) {
8+
var y = 0x7fffffff; // 2^31 - 1
9+
10+
// Widen the static type of y (this condition never holds).
11+
if (a == NaN) y = NaN;
12+
13+
// The next condition holds only in the warmup run. It leads to Smi
14+
// (SignedSmall) feedback being collected for the addition below.
15+
if (a) y = -1;
16+
17+
const z = (y + 1)|0;
18+
return z < 0;
19+
}
20+
21+
%PrepareFunctionForOptimization(foo);
22+
assertFalse(foo(true));
23+
%OptimizeFunctionOnNextCall(foo);
24+
assertTrue(foo(false));

0 commit comments

Comments
 (0)