@@ -592,7 +592,7 @@ private module BoundsEstimate {
592592 not exists(def.getAPhiInput(v)) and
593593 // If there's different `access`es, then they refer to the same variable
594594 // with the same lower bounds. Hence adding these guards make no sense (the
595- // implementation will take the union but they'll be removed by
595+ // implementation will take the union, but they'll be removed by
596596 // deduplication). Hence we use `max` as an approximation.
597597 result =
598598 max(VariableAccess access | isGuardPhiWithBound(def, v, access) | nrOfBoundsExpr(access))
@@ -624,8 +624,13 @@ private module BoundsEstimate {
624624 * Gets the number of bounds for `def` when `def` is an NE phi node for the
625625 * variable `v`.
626626 */
627- private float nrOfBoundsNEPhi(RangeSsaDefinition def, StackVariable v) {
628- exists(VariableAccess access | isNEPhi(v, def, access, _) and result = nrOfBoundsExpr(access))
627+ language[monotonicAggregates]
628+ float nrOfBoundsNEPhi(RangeSsaDefinition def, StackVariable v) {
629+ // If there's different `access`es, then they refer to the same variable
630+ // with the same lower bounds. Hence adding these guards make no sense (the
631+ // implementation will take the union, but they'll be removed by
632+ // deduplication). Hence we use `max` as an approximation.
633+ result = max(VariableAccess access | isNEPhi(v, def, access, _) | nrOfBoundsExpr(access))
629634 or
630635 def.isPhiNode(v) and
631636 not isNEPhi(v, def, _, _) and
@@ -636,11 +641,14 @@ private module BoundsEstimate {
636641 * Gets the number of bounds for `def` when `def` is an unsupported guard phi
637642 * node for the variable `v`.
638643 */
644+ language[monotonicAggregates]
639645 private float nrOfBoundsUnsupportedGuardPhi(RangeSsaDefinition def, StackVariable v) {
640- exists(VariableAccess access |
641- isUnsupportedGuardPhi(v, def, access) and
642- result = nrOfBoundsExpr(access)
643- )
646+ // If there's different `access`es, then they refer to the same variable
647+ // with the same lower bounds. Hence adding these guards make no sense (the
648+ // implementation will take the union, but they'll be removed by
649+ // deduplication). Hence we use `max` as an approximation.
650+ result =
651+ max(VariableAccess access | isUnsupportedGuardPhi(v, def, access) | nrOfBoundsExpr(access))
644652 or
645653 def.isPhiNode(v) and
646654 not isUnsupportedGuardPhi(v, def, _) and
0 commit comments