Skip to content

Commit a59e3ac

Browse files
GeorgNeisCommit Bot
authored andcommitted
Merged: [compiler] Fix bug in SimplifiedLowering's overflow computation
Revision: e371325 BUG=chromium:1126249 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true [email protected] Change-Id: I411d9233f77992e73da12784cef59c885999b556 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2415988 Reviewed-by: Tobias Tebbi <[email protected]> Commit-Queue: Georg Neis <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#8} Cr-Branched-From: a64aed2-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc0-refs/heads/master@{#69472}
1 parent ba3f29f commit a59e3ac

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/compiler/simplified-lowering.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,16 @@ void ReplaceEffectControlUses(Node* node, Node* effect, Node* control) {
183183
}
184184

185185
bool CanOverflowSigned32(const Operator* op, Type left, Type right,
186-
Zone* type_zone) {
187-
// We assume the inputs are checked Signed32 (or known statically
188-
// to be Signed32). Technically, the inputs could also be minus zero, but
189-
// that cannot cause overflow.
186+
TypeCache const* type_cache, Zone* type_zone) {
187+
// We assume the inputs are checked Signed32 (or known statically to be
188+
// Signed32). Technically, the inputs could also be minus zero, which we treat
189+
// as 0 for the purpose of this function.
190+
if (left.Maybe(Type::MinusZero())) {
191+
left = Type::Union(left, type_cache->kSingletonZero, type_zone);
192+
}
193+
if (right.Maybe(Type::MinusZero())) {
194+
right = Type::Union(right, type_cache->kSingletonZero, type_zone);
195+
}
190196
left = Type::Intersect(left, Type::Signed32(), type_zone);
191197
right = Type::Intersect(right, Type::Signed32(), type_zone);
192198
if (left.IsNone() || right.IsNone()) return false;
@@ -1484,7 +1490,8 @@ class RepresentationSelector {
14841490
if (lower<T>()) {
14851491
if (truncation.IsUsedAsWord32() ||
14861492
!CanOverflowSigned32(node->op(), left_feedback_type,
1487-
right_feedback_type, graph_zone())) {
1493+
right_feedback_type, type_cache_,
1494+
graph_zone())) {
14881495
ChangeToPureOp(node, Int32Op(node));
14891496

14901497
} else {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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(b) {
8+
var x = -0;
9+
var y = -0x80000000;
10+
11+
if (b) {
12+
x = -1;
13+
y = 1;
14+
}
15+
16+
return (x - y) == -0x80000000;
17+
}
18+
19+
%PrepareFunctionForOptimization(foo);
20+
assertFalse(foo(true));
21+
%OptimizeFunctionOnNextCall(foo);
22+
assertFalse(foo(false));

0 commit comments

Comments
 (0)