Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Unified Diff: pkg/compiler/lib/src/ssa/value_range_analyzer.dart

Issue 2561533002: dart2js: Constant folding and specialization for remainder (Closed)
Patch Set: improve range analysis of remainder Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/ssa/types_propagation.dart ('k') | tests/compiler/dart2js/modulo_remainder_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/value_range_analyzer.dart
diff --git a/pkg/compiler/lib/src/ssa/value_range_analyzer.dart b/pkg/compiler/lib/src/ssa/value_range_analyzer.dart
index 3f041a062f07a78d68f9fa31ad680fdf7fb753c9..7e53d06bac62445d1de327e18783a02ace8c910c 100644
--- a/pkg/compiler/lib/src/ssa/value_range_analyzer.dart
+++ b/pkg/compiler/lib/src/ssa/value_range_analyzer.dart
@@ -814,8 +814,8 @@ class SsaValueRangeAnalyzer extends HBaseVisitor implements OptimizationPhase {
HInstruction right = invoke.inputs[2];
Range divisor = ranges[right];
if (divisor != null) {
- // For Integer values we can be precise in the upper bound,
- // so special case those.
+ // For Integer values we can be precise in the upper bound, so special
+ // case those.
if (left.isInteger(closedWorld) && right.isInteger(closedWorld)) {
if (divisor.isPositive) {
return info.newNormalizedRange(
@@ -836,6 +836,30 @@ class SsaValueRangeAnalyzer extends HBaseVisitor implements OptimizationPhase {
return info.newUnboundRange();
}
+ Range visitRemainder(HRemainder instruction) {
+ HInstruction left = instruction.inputs[0];
+ HInstruction right = instruction.inputs[1];
+ Range dividend = ranges[left];
+ // If both operands are >=0, the result is >= 0 and bounded by the divisor.
+ if ((dividend != null && dividend.isPositive) ||
+ left.isPositiveInteger(closedWorld)) {
+ Range divisor = ranges[right];
+ if (divisor != null) {
+ if (divisor.isPositive) {
+ // For Integer values we can be precise in the upper bound.
+ if (left.isInteger(closedWorld) && right.isInteger(closedWorld)) {
+ return info.newNormalizedRange(
+ info.intZero, divisor.upper - info.intOne);
+ }
+ if (left.isNumber(closedWorld) && right.isNumber(closedWorld)) {
+ return info.newNormalizedRange(info.intZero, divisor.upper);
+ }
+ }
+ }
+ }
+ return info.newUnboundRange();
+ }
+
Range visitInvokeDynamicMethod(HInvokeDynamicMethod invoke) {
if ((invoke.inputs.length == 3) && (invoke.selector.name == "%"))
return handleInvokeModulo(invoke);
« no previous file with comments | « pkg/compiler/lib/src/ssa/types_propagation.dart ('k') | tests/compiler/dart2js/modulo_remainder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698