[vm,compiler] Fix loop computation in case of try blocks
If catch block is included into the loop, we should also include the whole try body as there are implicit control flow edges between each block in a try body and corresponding catch block. If try body is not included, analysis of loop invariant loads could miss conflicting stores and may conclude that certain loads are loop invariant although they are not. TEST=runtime/tests/vm/dart/regress_63336_test.dart Fixes https://github.com/dart-lang/sdk/issues/63336 Change-Id: I9d6b73e24554ee3bfbcc722fa59634ea90b00abb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501560 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
1707f11db4
commit
da1f06f239
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2026, 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.
|
||||
|
||||
// Verify that a load from a catch block is not considered loop invariant
|
||||
// and not hoisted out of the loop if there is a store in the try body.
|
||||
// Regression test for https://github.com/dart-lang/sdk/issues/63336.
|
||||
|
||||
// VMOptions=--optimization-counter-threshold=100 --no-background-compilation
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
int var63 = 28;
|
||||
int var68 = 44;
|
||||
|
||||
void test() {
|
||||
int n = 43;
|
||||
while (--n > 0) {
|
||||
try {
|
||||
var63++;
|
||||
// Terminate block without reaching a loop backedge,
|
||||
// so try body won't be included into the loop body
|
||||
// through explicit predecessors of the backedge.
|
||||
throw 'bye';
|
||||
// Make sure load is not immediately in a CatchBlockEntry.
|
||||
} on StackOverflowError {
|
||||
rethrow;
|
||||
} catch (_) {
|
||||
// Load from 'var63' is considered loop invariant if
|
||||
// loop body doesn't include try block body.
|
||||
var68 = var63;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
var63 = 28;
|
||||
var68 = 44;
|
||||
test();
|
||||
Expect.equals(70, var68);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user