diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart index 46dc376b5a6..56ece5ec56d 100644 --- a/pkg/compiler/lib/src/ssa/builder.dart +++ b/pkg/compiler/lib/src/ssa/builder.dart @@ -6775,7 +6775,9 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault _currentImplicitInstantiations, ); } - instruction.sideEffects = _inferredData.getSideEffectsOfElement(target); + instruction.sideEffects.setTo( + _inferredData.getSideEffectsOfElement(target), + ); instruction.allowCSE = closedWorld.annotationsData.allowCSE(target); instruction.allowDCE = closedWorld.annotationsData.allowDCE(target); push(instruction); @@ -7391,9 +7393,8 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault isSetter: selector.isSetter || selector.isIndexSet, ); // TODO(natebiggs): Pass typeMask below and make non-nullable. - instruction.sideEffects = _inferredData.getSideEffectsOfSelector( - selector, - null, + instruction.sideEffects.setTo( + _inferredData.getSideEffectsOfSelector(selector, null), ); push(instruction); return instruction; diff --git a/pkg/compiler/lib/src/ssa/nodes.dart b/pkg/compiler/lib/src/ssa/nodes.dart index 9e6cbd22415..73faa7654cc 100644 --- a/pkg/compiler/lib/src/ssa/nodes.dart +++ b/pkg/compiler/lib/src/ssa/nodes.dart @@ -1172,7 +1172,7 @@ abstract class HInstruction implements SpannableWithEntity { /// Type of the instruction. late AbstractValue instructionType; - SideEffects sideEffects = SideEffects.empty(); + final SideEffects sideEffects = SideEffects.empty(); bool _useGvn = false; // TODO(sra): Consider whether to reduce instruction size by collecting all @@ -3516,7 +3516,8 @@ class HThrowExpression extends HInstruction { class HAwait extends HInstruction { HAwait(super.value, super.type) : super._oneInput() { - sideEffects = SideEffects(); + sideEffects.setAllSideEffects(); + sideEffects.setDependsOnSomething(); } @override String toString() => 'await'; @@ -3535,7 +3536,8 @@ class HYield extends HInstruction { SourceInformation? sourceInformation, ) : super._oneInput() { this.sourceInformation = sourceInformation; - sideEffects = SideEffects(); + sideEffects.setAllSideEffects(); + sideEffects.setDependsOnSomething(); } bool hasStar; @override diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart index 11ddba2e117..56d0941c203 100644 --- a/pkg/compiler/lib/src/ssa/optimize.dart +++ b/pkg/compiler/lib/src/ssa/optimize.dart @@ -1071,6 +1071,9 @@ class SsaInstructionSimplifier extends HBaseVisitor node.element = method; } + node.sideEffects.restrictTo( + _globalInferenceResults.inferredData.getSideEffectsOfElement(element), + ); if (_closedWorld.annotationsData.allowCSE(element)) { node.allowCSE = true; } @@ -2035,6 +2038,9 @@ class SsaInstructionSimplifier extends HBaseVisitor if (_nativeData.isNativeMember(member)) { return tryInlineNativeGetter(node, member) ?? node; } + node.sideEffects.restrictTo( + _globalInferenceResults.inferredData.getSideEffectsOfElement(member), + ); if (_closedWorld.annotationsData.allowCSE(member)) { node.allowCSE = true; } diff --git a/pkg/compiler/lib/src/universe/side_effects.dart b/pkg/compiler/lib/src/universe/side_effects.dart index f3a3649b92c..9822b7e090c 100644 --- a/pkg/compiler/lib/src/universe/side_effects.dart +++ b/pkg/compiler/lib/src/universe/side_effects.dart @@ -184,6 +184,10 @@ class SideEffects { _flags = other._flags; } + void restrictTo(SideEffects other) { + _flags = _flags.intersection(other._flags); + } + @override String toString() { StringBuffer buffer = StringBuffer();