Skip to content

Commit c67598f

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, compiler] Don't use MayBeSameAsFirstInput for smi srl.
TEST=ci Bug: #59611 Change-Id: I6a41e690e048163eaa71a02924a6c942e9fdc93b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397641 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 3f6928c commit c67598f

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// The Dart Project Fuzz Tester (1.101).
6+
// Program generated as:
7+
// dart dartfuzz.dart --seed 1868073336 --no-fp --no-ffi --flat
8+
// @dart=2.14
9+
10+
// VMOptions=--optimization_counter_threshold=1 --use-slow-path --deterministic
11+
12+
import "dart:typed_data";
13+
14+
Uint8ClampedList var9 = Uint8ClampedList(40);
15+
bool var109 = true;
16+
int var112 = 5;
17+
18+
main() {
19+
for (int loc0 = 0; loc0 < 41; loc0++) {
20+
var112 = var9[27] >>> (var109 ? 38 : 255);
21+
}
22+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// VMOptions=--optimization-counter-threshold=50 --no-background-compilation
6+
7+
import "package:expect/expect.dart";
8+
9+
@pragma("vm:never-inline")
10+
dynamic smi_add(dynamic x, dynamic y) => x + y;
11+
12+
@pragma("vm:never-inline")
13+
dynamic smi_sub(dynamic x, dynamic y) => x - y;
14+
15+
@pragma("vm:never-inline")
16+
dynamic smi_mul(dynamic x, dynamic y) => x * y;
17+
18+
@pragma("vm:never-inline")
19+
dynamic smi_and(dynamic x, dynamic y) => x & y;
20+
21+
@pragma("vm:never-inline")
22+
dynamic smi_or(dynamic x, dynamic y) => x | y;
23+
24+
@pragma("vm:never-inline")
25+
dynamic smi_xor(dynamic x, dynamic y) => x ^ y;
26+
27+
@pragma("vm:never-inline")
28+
dynamic smi_div(dynamic x, dynamic y) => x ~/ y;
29+
30+
@pragma("vm:never-inline")
31+
dynamic smi_mod(dynamic x, dynamic y) => x % y;
32+
33+
@pragma("vm:never-inline")
34+
dynamic smi_sll(dynamic x, dynamic y) => x << y;
35+
36+
@pragma("vm:never-inline")
37+
dynamic smi_sra(dynamic x, dynamic y) => x >> y;
38+
39+
@pragma("vm:never-inline")
40+
dynamic smi_srl(dynamic x, dynamic y) => x >>> y;
41+
42+
testSmi() {
43+
Expect.equals(7, smi_add(3, 4));
44+
Expect.equals(-1, smi_sub(3, 4));
45+
Expect.equals(12, smi_mul(3, 4));
46+
Expect.equals(0, smi_and(3, 4));
47+
Expect.equals(7, smi_or(3, 4));
48+
Expect.equals(7, smi_xor(3, 4));
49+
Expect.equals(0, smi_div(3, 4));
50+
Expect.equals(3, smi_mod(3, 4));
51+
Expect.equals(48, smi_sll(3, 4));
52+
Expect.equals(0, smi_sra(3, 4));
53+
Expect.equals(0, smi_srl(3, 4));
54+
}
55+
56+
const maxSmi32 = 0x3FFFFFFF;
57+
const maxSmi64 = 0x3FFFFFFFFFFFFFFF;
58+
const minSmi32 = -0x80000000;
59+
const minSmi64 = -0x8000000000000000;
60+
61+
testSmiDeopt() {
62+
Expect.equals(0x40000000, smi_add(maxSmi32, 1));
63+
Expect.equals(0x4000000000000000, smi_add(maxSmi64, 1));
64+
65+
Expect.equals(0x40000000, smi_sub(maxSmi32, -1));
66+
Expect.equals(0x4000000000000000, smi_sub(maxSmi64, -1));
67+
68+
Expect.equals(0x7FFFFFFE, smi_mul(maxSmi32, 2));
69+
Expect.equals(0x7FFFFFFFFFFFFFFE, smi_mul(maxSmi64, 2));
70+
71+
Expect.equals(0x80000000, smi_div(minSmi32, -1));
72+
Expect.equals(0x8000000000000000, smi_div(minSmi64, -1));
73+
74+
Expect.throws(() => smi_mod(minSmi32, 0));
75+
Expect.throws(() => smi_mod(minSmi64, 0));
76+
77+
Expect.equals(0x7FFFFFFE, smi_sll(maxSmi32, 1));
78+
Expect.equals(0x7FFFFFFFFFFFFFFE, smi_sll(maxSmi64, 1));
79+
80+
Expect.equals(0, smi_sra(maxSmi32, 65));
81+
Expect.equals(0, smi_sra(maxSmi64, 65));
82+
83+
Expect.equals(0, smi_srl(minSmi32, 65));
84+
Expect.equals(0, smi_srl(minSmi64, 65));
85+
}
86+
87+
main() {
88+
for (int i = 0; i < 200; i++) {
89+
testSmi();
90+
}
91+
92+
print("=================================");
93+
94+
for (int i = 0; i < 200; i++) {
95+
testSmiDeopt();
96+
}
97+
}

runtime/vm/compiler/backend/il_riscv.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,8 +3233,11 @@ LocationSummary* BinarySmiOpInstr::MakeLocationSummary(Zone* zone,
32333233
if (kNumTemps == 1) {
32343234
summary->set_temp(0, Location::RequiresRegister());
32353235
}
3236-
summary->set_out(0, CanDeoptimize() ? Location::RequiresRegister()
3237-
: Location::MayBeSameAsFirstInput());
3236+
if (CanDeoptimize() || (op_kind() == Token::kUSHR)) {
3237+
summary->set_out(0, Location::RequiresRegister());
3238+
} else {
3239+
summary->set_out(0, Location::MayBeSameAsFirstInput());
3240+
}
32383241
return summary;
32393242
}
32403243

@@ -3491,6 +3494,7 @@ void BinarySmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
34913494
compiler::Label done, adjust;
34923495
__ bgez(result, &done, compiler::Assembler::kNearJump);
34933496
// Result is negative, adjust it.
3497+
ASSERT(result != right);
34943498
__ bgez(right, &adjust, compiler::Assembler::kNearJump);
34953499
__ sub(result, result, TMP2);
34963500
__ j(&done, compiler::Assembler::kNearJump);

0 commit comments

Comments
 (0)