[vm, compiler] Use correct size of Smi when truncating during constant folding.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/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>
diff --git a/runtime/vm/compiler/backend/evaluator.cc b/runtime/vm/compiler/backend/evaluator.cc
index 11b007a..fd8c0e8 100644
--- a/runtime/vm/compiler/backend/evaluator.cc
+++ b/runtime/vm/compiler/backend/evaluator.cc
@@ -71,9 +71,8 @@
 int64_t Evaluator::TruncateTo(int64_t v, Representation r) {
   switch (r) {
     case kTagged: {
-      // Smi occupies word minus kSmiTagShift bits.
       const intptr_t kTruncateBits =
-          (kBitsPerInt64 - kBitsPerWord) + kSmiTagShift;
+          kBitsPerInt64 - (compiler::target::kSmiBits + 1 /*sign bit*/);
       return Utils::ShiftLeftWithTruncation(v, kTruncateBits) >> kTruncateBits;
     }
     case kUnboxedInt32:
diff --git a/tests/language/vm/regress_45525_test.dart b/tests/language/vm/regress_45525_test.dart
new file mode 100644
index 0000000..2becc03
--- /dev/null
+++ b/tests/language/vm/regress_45525_test.dart
@@ -0,0 +1,26 @@
+// Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// VMOptions=--optimization-counter-threshold=10  --no-background-compilation
+
+import "package:expect/expect.dart";
+
+dynamic a() {
+  return 23;
+}
+
+dynamic b() {
+  return 26;
+}
+
+@pragma("vm:never-inline")
+dynamic foo() {
+  // BinarySmiOp(<<) marked truncating
+  return (a() << b()) & 0xFFFFFFF;
+}
+
+main() {
+  for (var i = 0; i < 20; i++) {
+    Expect.equals(201326592, foo());
+  }
+}
diff --git a/tests/language_2/vm/regress_45525_test.dart b/tests/language_2/vm/regress_45525_test.dart
new file mode 100644
index 0000000..2becc03
--- /dev/null
+++ b/tests/language_2/vm/regress_45525_test.dart
@@ -0,0 +1,26 @@
+// Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// VMOptions=--optimization-counter-threshold=10  --no-background-compilation
+
+import "package:expect/expect.dart";
+
+dynamic a() {
+  return 23;
+}
+
+dynamic b() {
+  return 26;
+}
+
+@pragma("vm:never-inline")
+dynamic foo() {
+  // BinarySmiOp(<<) marked truncating
+  return (a() << b()) & 0xFFFFFFF;
+}
+
+main() {
+  for (var i = 0; i < 20; i++) {
+    Expect.equals(201326592, foo());
+  }
+}