Skip to content

Commit 3066b7b

Browse files
GeorgNeisCommit Bot
authored andcommitted
[LTS-M86][compiler][x64] Fix bug in InstructionSelector::ChangeInt32ToInt64
(cherry picked from commit 02f84c7) No-Try: true No-Presubmit: true No-Tree-Checks: true Bug: chromium:1196683 Change-Id: Ib4ea738b47b64edc81450583be4c80a41698c3d1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2820971 Commit-Queue: Georg Neis <[email protected]> Reviewed-by: Nico Hartmann <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#73903} Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2821959 Commit-Queue: Jana Grill <[email protected]> Reviewed-by: Georg Neis <[email protected]> Reviewed-by: Victor-Gabriel Savu <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#75} Cr-Branched-From: a64aed2-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc0-refs/heads/master@{#69472}
1 parent 720176a commit 3066b7b

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/compiler/backend/x64/instruction-selector-x64.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,9 @@ void InstructionSelector::VisitChangeInt32ToInt64(Node* node) {
12791279
opcode = load_rep.IsSigned() ? kX64Movsxwq : kX64Movzxwq;
12801280
break;
12811281
case MachineRepresentation::kWord32:
1282-
opcode = load_rep.IsSigned() ? kX64Movsxlq : kX64Movl;
1282+
// ChangeInt32ToInt64 must interpret its input as a _signed_ 32-bit
1283+
// integer, so here we must sign-extend the loaded value in any case.
1284+
opcode = kX64Movsxlq;
12831285
break;
12841286
default:
12851287
UNREACHABLE();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
const arr = new Uint32Array([2**31]);
10+
function foo() {
11+
return (arr[0] ^ 0) + 1;
12+
}
13+
%PrepareFunctionForOptimization(foo);
14+
assertEquals(-(2**31) + 1, foo());
15+
%OptimizeFunctionOnNextCall(foo);
16+
assertEquals(-(2**31) + 1, foo());
17+
});
18+
19+
20+
// The remaining tests already passed without the bugfix.
21+
22+
23+
(function() {
24+
const arr = new Uint16Array([2**15]);
25+
function foo() {
26+
return (arr[0] ^ 0) + 1;
27+
}
28+
%PrepareFunctionForOptimization(foo);
29+
assertEquals(2**15 + 1, foo());
30+
%OptimizeFunctionOnNextCall(foo);
31+
assertEquals(2**15 + 1, foo());
32+
})();
33+
34+
35+
(function() {
36+
const arr = new Uint8Array([2**7]);
37+
function foo() {
38+
return (arr[0] ^ 0) + 1;
39+
}
40+
%PrepareFunctionForOptimization(foo);
41+
assertEquals(2**7 + 1, foo());
42+
%OptimizeFunctionOnNextCall(foo);
43+
assertEquals(2**7 + 1, foo());
44+
})();
45+
46+
47+
(function() {
48+
const arr = new Int32Array([-(2**31)]);
49+
function foo() {
50+
return (arr[0] >>> 0) + 1;
51+
}
52+
%PrepareFunctionForOptimization(foo);
53+
assertEquals(2**31 + 1, foo());
54+
%OptimizeFunctionOnNextCall(foo);
55+
assertEquals(2**31 + 1, foo());
56+
})();

0 commit comments

Comments
 (0)