Skip to content

Commit 76e41bc

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm, compiler] Use correct size of Smi when truncating during constant folding.
TEST=ci Bug: #45525 Change-Id: I048a90eade678f610f0fd4451b099711a1faa957 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193750 Reviewed-by: Liam Appelbe <liama@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
1 parent 66635c3 commit 76e41bc

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

runtime/vm/compiler/backend/evaluator.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ static IntegerPtr UnaryIntegerEvaluateRaw(const Integer& value,
7171
int64_t Evaluator::TruncateTo(int64_t v, Representation r) {
7272
switch (r) {
7373
case kTagged: {
74-
// Smi occupies word minus kSmiTagShift bits.
7574
const intptr_t kTruncateBits =
76-
(kBitsPerInt64 - kBitsPerWord) + kSmiTagShift;
75+
kBitsPerInt64 - (compiler::target::kSmiBits + 1 /*sign bit*/);
7776
return Utils::ShiftLeftWithTruncation(v, kTruncateBits) >> kTruncateBits;
7877
}
7978
case kUnboxedInt32:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021, 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+
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
5+
6+
import "package:expect/expect.dart";
7+
8+
dynamic a() {
9+
return 23;
10+
}
11+
12+
dynamic b() {
13+
return 26;
14+
}
15+
16+
@pragma("vm:never-inline")
17+
dynamic foo() {
18+
// BinarySmiOp(<<) marked truncating
19+
return (a() << b()) & 0xFFFFFFF;
20+
}
21+
22+
main() {
23+
for (var i = 0; i < 20; i++) {
24+
Expect.equals(201326592, foo());
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021, 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+
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
5+
6+
import "package:expect/expect.dart";
7+
8+
dynamic a() {
9+
return 23;
10+
}
11+
12+
dynamic b() {
13+
return 26;
14+
}
15+
16+
@pragma("vm:never-inline")
17+
dynamic foo() {
18+
// BinarySmiOp(<<) marked truncating
19+
return (a() << b()) & 0xFFFFFFF;
20+
}
21+
22+
main() {
23+
for (var i = 0; i < 20; i++) {
24+
Expect.equals(201326592, foo());
25+
}
26+
}

0 commit comments

Comments
 (0)