Skip to content

Commit 9a0109d

Browse files
isheludkoCommit bot
authored andcommitted
[crankshaft] Range analysis should not rely on overflowed ranges.
BUG=chromium:645438 Review-Url: https://codereview.chromium.org/2412853002 Cr-Commit-Position: refs/heads/master@{#40202}
1 parent edfe391 commit 9a0109d

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/crankshaft/hydrogen-instructions.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ bool Range::AddAndCheckOverflow(const Representation& r, Range* other) {
259259
bool may_overflow = false;
260260
lower_ = AddWithoutOverflow(r, lower_, other->lower(), &may_overflow);
261261
upper_ = AddWithoutOverflow(r, upper_, other->upper(), &may_overflow);
262-
KeepOrder();
262+
if (may_overflow) {
263+
Clear();
264+
} else {
265+
KeepOrder();
266+
}
263267
#ifdef DEBUG
264268
Verify();
265269
#endif
@@ -271,13 +275,21 @@ bool Range::SubAndCheckOverflow(const Representation& r, Range* other) {
271275
bool may_overflow = false;
272276
lower_ = SubWithoutOverflow(r, lower_, other->upper(), &may_overflow);
273277
upper_ = SubWithoutOverflow(r, upper_, other->lower(), &may_overflow);
274-
KeepOrder();
278+
if (may_overflow) {
279+
Clear();
280+
} else {
281+
KeepOrder();
282+
}
275283
#ifdef DEBUG
276284
Verify();
277285
#endif
278286
return may_overflow;
279287
}
280288

289+
void Range::Clear() {
290+
lower_ = kMinInt;
291+
upper_ = kMaxInt;
292+
}
281293

282294
void Range::KeepOrder() {
283295
if (lower_ > upper_) {
@@ -301,8 +313,12 @@ bool Range::MulAndCheckOverflow(const Representation& r, Range* other) {
301313
int v2 = MulWithoutOverflow(r, lower_, other->upper(), &may_overflow);
302314
int v3 = MulWithoutOverflow(r, upper_, other->lower(), &may_overflow);
303315
int v4 = MulWithoutOverflow(r, upper_, other->upper(), &may_overflow);
304-
lower_ = Min(Min(v1, v2), Min(v3, v4));
305-
upper_ = Max(Max(v1, v2), Max(v3, v4));
316+
if (may_overflow) {
317+
Clear();
318+
} else {
319+
lower_ = Min(Min(v1, v2), Min(v3, v4));
320+
upper_ = Max(Max(v1, v2), Max(v3, v4));
321+
}
306322
#ifdef DEBUG
307323
Verify();
308324
#endif

src/crankshaft/hydrogen-instructions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class Range final : public ZoneObject {
235235
lower_ = Max(lower_, Smi::kMinValue);
236236
upper_ = Min(upper_, Smi::kMaxValue);
237237
}
238+
void Clear();
238239
void KeepOrder();
239240
#ifdef DEBUG
240241
void Verify() const;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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 n(x,y){
8+
y = (y-(0x80000000|0)|0);
9+
return (x/y)|0;
10+
};
11+
var x = -0x80000000;
12+
var y = 0x7fffffff;
13+
n(x,y);
14+
n(x,y);
15+
%OptimizeFunctionOnNextCall(n);
16+
assertEquals(x, n(x,y));

0 commit comments

Comments
 (0)