Skip to content

Commit c449afa

Browse files
GeorgNeisCommit Bot
authored andcommitted
Merged: [compiler] Fix a bug in SimplifiedLowering
Revision: ba1b2cc BUG=chromium:1150649 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true (cherry picked from commit 966d0eb) 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-Original-Commit-Position: refs/branch-heads/8.8@{#10} Cr-Original-Branched-From: 2dbcdc1-refs/heads/8.8.278@{#1} Cr-Original-Branched-From: 366d30c-refs/heads/master@{#71094} Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2624749 Reviewed-by: Jana Grill <[email protected]> Reviewed-by: Achuith Bhandarkar <[email protected]> Commit-Queue: Victor-Gabriel Savu <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#52} Cr-Branched-From: a64aed2-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc0-refs/heads/master@{#69472}
1 parent fa094d9 commit c449afa

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
@@ -1408,7 +1408,6 @@ class RepresentationSelector {
14081408
IsSomePositiveOrderedNumber(input1_type)
14091409
? CheckForMinusZeroMode::kDontCheckForMinusZero
14101410
: CheckForMinusZeroMode::kCheckForMinusZero;
1411-
14121411
NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(mz_mode));
14131412
}
14141413

@@ -1452,6 +1451,13 @@ class RepresentationSelector {
14521451

14531452
Type left_feedback_type = TypeOf(node->InputAt(0));
14541453
Type right_feedback_type = TypeOf(node->InputAt(1));
1454+
1455+
// Using Signed32 as restriction type amounts to promising there won't be
1456+
// signed overflow. This is incompatible with relying on a Word32
1457+
// truncation in order to skip the overflow check.
1458+
Type const restriction =
1459+
truncation.IsUsedAsWord32() ? Type::Any() : Type::Signed32();
1460+
14551461
// Handle the case when no int32 checks on inputs are necessary (but
14561462
// an overflow check is needed on the output). Note that we do not
14571463
// have to do any check if at most one side can be minus zero. For
@@ -1465,7 +1471,7 @@ class RepresentationSelector {
14651471
right_upper.Is(Type::Signed32OrMinusZero()) &&
14661472
(left_upper.Is(Type::Signed32()) || right_upper.Is(Type::Signed32()))) {
14671473
VisitBinop<T>(node, UseInfo::TruncatingWord32(),
1468-
MachineRepresentation::kWord32, Type::Signed32());
1474+
MachineRepresentation::kWord32, restriction);
14691475
} else {
14701476
// If the output's truncation is identify-zeros, we can pass it
14711477
// along. Moreover, if the operation is addition and we know the
@@ -1485,8 +1491,9 @@ class RepresentationSelector {
14851491
UseInfo right_use = CheckedUseInfoAsWord32FromHint(hint, FeedbackSource(),
14861492
kIdentifyZeros);
14871493
VisitBinop<T>(node, left_use, right_use, MachineRepresentation::kWord32,
1488-
Type::Signed32());
1494+
restriction);
14891495
}
1496+
14901497
if (lower<T>()) {
14911498
if (truncation.IsUsedAsWord32() ||
14921499
!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)