Skip to content

Commit bbc59d1

Browse files
GeorgNeisCommit Bot
authored andcommitted
M86-LTS: [compiler] Fix bug in RepresentationChanger::GetWord32RepresentationFor
We have to respect the TypeCheckKind. (cherry picked from commit fd29e24) No-Try: true No-Presubmit: true No-Tree-Checks: true Bug: chromium:1195777 Change-Id: If1eed719fef79b7c61d99c29ba869ddd7985c413 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2817791 Commit-Queue: Georg Neis <[email protected]> Reviewed-by: Nico Hartmann <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#73909} Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2838235 Owners-Override: Achuith Bhandarkar <[email protected]> Reviewed-by: Artem Sumaneev <[email protected]> Commit-Queue: Achuith Bhandarkar <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#79} Cr-Branched-From: a64aed2-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc0-refs/heads/master@{#69472}
1 parent 936c0d5 commit bbc59d1

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

src/compiler/representation-change.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,10 @@ Node* RepresentationChanger::GetWord32RepresentationFor(
949949
return node;
950950
} else if (output_rep == MachineRepresentation::kWord64) {
951951
if (output_type.Is(Type::Signed32()) ||
952-
output_type.Is(Type::Unsigned32())) {
953-
op = machine()->TruncateInt64ToInt32();
954-
} else if (output_type.Is(cache_->kSafeInteger) &&
955-
use_info.truncation().IsUsedAsWord32()) {
952+
(output_type.Is(Type::Unsigned32()) &&
953+
use_info.type_check() == TypeCheckKind::kNone) ||
954+
(output_type.Is(cache_->kSafeInteger) &&
955+
use_info.truncation().IsUsedAsWord32())) {
956956
op = machine()->TruncateInt64ToInt32();
957957
} else if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
958958
use_info.type_check() == TypeCheckKind::kSigned32 ||
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2021 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+
8+
(function() {
9+
function foo(b) {
10+
let y = (new Date(42)).getMilliseconds();
11+
let x = -1;
12+
if (b) x = 0xFFFF_FFFF;
13+
return y < Math.max(1 << y, x, 1 + y);
14+
}
15+
assertTrue(foo(true));
16+
%PrepareFunctionForOptimization(foo);
17+
assertTrue(foo(false));
18+
%OptimizeFunctionOnNextCall(foo);
19+
assertTrue(foo(true));
20+
})();
21+
22+
23+
(function() {
24+
function foo(b) {
25+
let x = 0;
26+
if (b) x = -1;
27+
return x == Math.max(-1, x >>> Infinity);
28+
}
29+
assertFalse(foo(true));
30+
%PrepareFunctionForOptimization(foo);
31+
assertTrue(foo(false));
32+
%OptimizeFunctionOnNextCall(foo);
33+
assertFalse(foo(true));
34+
})();
35+
36+
37+
(function() {
38+
function foo(b) {
39+
let x = -1;
40+
if (b) x = 0xFFFF_FFFF;
41+
return -1 < Math.max(0, x, -1);
42+
}
43+
assertTrue(foo(true));
44+
%PrepareFunctionForOptimization(foo);
45+
assertTrue(foo(false));
46+
%OptimizeFunctionOnNextCall(foo);
47+
assertTrue(foo(true));
48+
})();
49+
50+
51+
(function() {
52+
function foo(b) {
53+
let x = 0x7FFF_FFFF;
54+
if (b) x = 0;
55+
return 0 < (Math.max(-5 >>> x, -5) % -5);
56+
}
57+
assertTrue(foo(true));
58+
%PrepareFunctionForOptimization(foo);
59+
assertTrue(foo(false));
60+
%OptimizeFunctionOnNextCall(foo);
61+
assertTrue(foo(true));
62+
})();

0 commit comments

Comments
 (0)