Files
sdk/pkg/compiler/test/codegen/data/partial_phi_redundancy.dart
T
Stephen Adams b3502f17cb [dart2js] Reduce redundant phis with refinements
Redundant phi elimination removes phis that join the same value.
However, this does not work when one or more of the inputs has a refinement (HTypeKnown). This change adds redundant phi elimination when the phi inputs have refinements.

The need for this optimization shows up when static js_interop needs a dispatch on type for conversion:

```
final JSAny? jsValue;
if (value is String) {
  jsValue = value.toJS;
} else if (value is bool) {
  jsValue = value.toJS;
...
```

(The `.toJS` calls become no-ops since, for dart2js, we are already in JavaScript, and so leave an otherwise pointless if-then-else chain).

Change-Id: If1a94856592163a81ac36c686cee04232c16d197
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403950
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-01-16 11:16:31 -08:00

34 lines
855 B
Dart

// Copyright (c) 2025, 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.
@pragma('dart2js:never-inline')
/*member: foo1:function(x) {
if (Date.now() > 0) {
if (typeof x != "string")
return "bad1";
} else if (typeof x != "string")
return "bad2";
return x;
}*/
String foo1(Object x) {
final Object y;
if (DateTime.now().millisecondsSinceEpoch > 0) {
if (x is! String) return 'bad1';
y = x;
} else {
if (x is! String) return 'bad2';
y = x;
}
// The phi for y has refinements to String on both branches, so the return
// should not need stringification.
return '$y';
}
/*member: main:ignore*/
main() {
print(foo1('a'));
print(foo1('b'));
print(foo1(123));
}