Skip to content

Commit 97ffcd9

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Disable incorrect widening of smis to int32
The optimization of widening smi operations to int32 does not account for uses which depend on the range of operation (e.g. BinarySmiOp which uses the result of widened operation becomes incorrect). Closes dart-lang/sdk#32619 Change-Id: Ia419c7bbec93679a5cdd1d16ffa3f51824fc08bb Reviewed-on: https://dart-review.googlesource.com/c/47661 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
1 parent 1a49337 commit 97ffcd9

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2018, 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+
// Regression test for dartbug.com/32619: incorrect widening of smis to int32.
6+
7+
// VMOptions=--optimization-counter-threshold=5 --no-background-compilation
8+
9+
import "package:expect/expect.dart";
10+
import 'dart:typed_data';
11+
12+
const int _digitBits = 32;
13+
const int _digitMask = (1 << _digitBits) - 1;
14+
15+
const int _halfDigitBits = _digitBits >> 1;
16+
const int _halfDigitMask = (1 << _halfDigitBits) - 1;
17+
18+
int _mulAdd(Uint32List multiplicandDigits, int i, Uint32List accumulatorDigits,
19+
int j, int n) {
20+
int carry = 0;
21+
while (--n >= 0) {
22+
int ml = multiplicandDigits[i] & _halfDigitMask;
23+
int mh = multiplicandDigits[i++] >> _halfDigitBits;
24+
int ph = mh * 4;
25+
int q1 = ((ph & _halfDigitMask) << _halfDigitBits);
26+
int pl = 4 * ml + q1 + accumulatorDigits[j];
27+
carry = (pl >> _digitBits) + (ph >> _halfDigitBits);
28+
accumulatorDigits[j++] = pl & _digitMask;
29+
}
30+
31+
return carry;
32+
}
33+
34+
main() {
35+
var multiplicandDigits = new Uint32List.fromList([0, 294967296, 0, 0]);
36+
var accumulatorDigits = new Uint32List.fromList([0, 4, 4, 0, 0, 0]);
37+
38+
var d1 = _mulAdd(multiplicandDigits, 0, accumulatorDigits, 0, 2);
39+
40+
Expect.equals(0, d1);
41+
}

runtime/vm/compiler/backend/flow_graph.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
namespace dart {
2222

2323
#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_IA32)
24+
// Smi->Int32 widening pass is disabled due to dartbug.com/32619.
25+
DEFINE_FLAG(bool, use_smi_widening, false, "Enable Smi->Int32 widening pass.");
2426
DEFINE_FLAG(bool, trace_smi_widening, false, "Trace Smi->Int32 widening pass.");
2527
#endif
2628
DEFINE_FLAG(bool, prune_dead_locals, true, "optimize dead locals away");
@@ -1863,6 +1865,10 @@ static bool BenefitsFromWidening(BinarySmiOpInstr* smi_op) {
18631865
}
18641866

18651867
void FlowGraph::WidenSmiToInt32() {
1868+
if (!FLAG_use_smi_widening) {
1869+
return;
1870+
}
1871+
18661872
GrowableArray<BinarySmiOpInstr*> candidates;
18671873

18681874
// Step 1. Collect all instructions that potentially benefit from widening of

0 commit comments

Comments
 (0)