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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import '../constant_system_dart.dart'; 5 import '../constant_system_dart.dart';
6 import '../constants/constant_system.dart'; 6 import '../constants/constant_system.dart';
7 import '../constants/values.dart'; 7 import '../constants/values.dart';
8 import '../js_backend/js_backend.dart'; 8 import '../js_backend/js_backend.dart';
9 import '../js_backend/backend_helpers.dart'; 9 import '../js_backend/backend_helpers.dart';
10 import '../world.dart' show ClosedWorld; 10 import '../world.dart' show ClosedWorld;
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 node.block.rewrite(node, graph.addConstantBool(true, closedWorld)); 807 node.block.rewrite(node, graph.addConstantBool(true, closedWorld));
808 node.block.remove(node); 808 node.block.remove(node);
809 } 809 }
810 } 810 }
811 811
812 Range handleInvokeModulo(HInvokeDynamicMethod invoke) { 812 Range handleInvokeModulo(HInvokeDynamicMethod invoke) {
813 HInstruction left = invoke.inputs[1]; 813 HInstruction left = invoke.inputs[1];
814 HInstruction right = invoke.inputs[2]; 814 HInstruction right = invoke.inputs[2];
815 Range divisor = ranges[right]; 815 Range divisor = ranges[right];
816 if (divisor != null) { 816 if (divisor != null) {
817 // For Integer values we can be precise in the upper bound, 817 // For Integer values we can be precise in the upper bound, so special
818 // so special case those. 818 // case those.
819 if (left.isInteger(closedWorld) && right.isInteger(closedWorld)) { 819 if (left.isInteger(closedWorld) && right.isInteger(closedWorld)) {
820 if (divisor.isPositive) { 820 if (divisor.isPositive) {
821 return info.newNormalizedRange( 821 return info.newNormalizedRange(
822 info.intZero, divisor.upper - info.intOne); 822 info.intZero, divisor.upper - info.intOne);
823 } else if (divisor.isNegative) { 823 } else if (divisor.isNegative) {
824 return info.newNormalizedRange( 824 return info.newNormalizedRange(
825 info.intZero, info.newNegateValue(divisor.lower) - info.intOne); 825 info.intZero, info.newNegateValue(divisor.lower) - info.intOne);
826 } 826 }
827 } else if (left.isNumber(closedWorld) && right.isNumber(closedWorld)) { 827 } else if (left.isNumber(closedWorld) && right.isNumber(closedWorld)) {
828 if (divisor.isPositive) { 828 if (divisor.isPositive) {
829 return info.newNormalizedRange(info.intZero, divisor.upper); 829 return info.newNormalizedRange(info.intZero, divisor.upper);
830 } else if (divisor.isNegative) { 830 } else if (divisor.isNegative) {
831 return info.newNormalizedRange( 831 return info.newNormalizedRange(
832 info.intZero, info.newNegateValue(divisor.lower)); 832 info.intZero, info.newNegateValue(divisor.lower));
833 } 833 }
834 } 834 }
835 } 835 }
836 return info.newUnboundRange(); 836 return info.newUnboundRange();
837 } 837 }
838 838
839 Range visitRemainder(HRemainder instruction) {
840 HInstruction left = instruction.inputs[0];
841 HInstruction right = instruction.inputs[1];
842 Range dividend = ranges[left];
843 // If both operands are >=0, the result is >= 0 and bounded by the divisor.
844 if ((dividend != null && dividend.isPositive) ||
845 left.isPositiveInteger(closedWorld)) {
846 Range divisor = ranges[right];
847 if (divisor != null) {
848 if (divisor.isPositive) {
849 // For Integer values we can be precise in the upper bound.
850 if (left.isInteger(closedWorld) && right.isInteger(closedWorld)) {
851 return info.newNormalizedRange(
852 info.intZero, divisor.upper - info.intOne);
853 }
854 if (left.isNumber(closedWorld) && right.isNumber(closedWorld)) {
855 return info.newNormalizedRange(info.intZero, divisor.upper);
856 }
857 }
858 }
859 }
860 return info.newUnboundRange();
861 }
862
839 Range visitInvokeDynamicMethod(HInvokeDynamicMethod invoke) { 863 Range visitInvokeDynamicMethod(HInvokeDynamicMethod invoke) {
840 if ((invoke.inputs.length == 3) && (invoke.selector.name == "%")) 864 if ((invoke.inputs.length == 3) && (invoke.selector.name == "%"))
841 return handleInvokeModulo(invoke); 865 return handleInvokeModulo(invoke);
842 return super.visitInvokeDynamicMethod(invoke); 866 return super.visitInvokeDynamicMethod(invoke);
843 } 867 }
844 868
845 Range handleBinaryOperation(HBinaryArithmetic instruction) { 869 Range handleBinaryOperation(HBinaryArithmetic instruction) {
846 if (!instruction.isInteger(closedWorld)) return info.newUnboundRange(); 870 if (!instruction.isInteger(closedWorld)) return info.newUnboundRange();
847 return instruction 871 return instruction
848 .operation(constantSystem) 872 .operation(constantSystem)
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 } 1106 }
1083 1107
1084 Range handleBinaryOperation(HBinaryArithmetic instruction) { 1108 Range handleBinaryOperation(HBinaryArithmetic instruction) {
1085 Range leftRange = visit(instruction.left); 1109 Range leftRange = visit(instruction.left);
1086 Range rightRange = visit(instruction.right); 1110 Range rightRange = visit(instruction.right);
1087 if (leftRange == null || rightRange == null) return null; 1111 if (leftRange == null || rightRange == null) return null;
1088 BinaryOperation operation = instruction.operation(info.constantSystem); 1112 BinaryOperation operation = instruction.operation(info.constantSystem);
1089 return operation.apply(leftRange, rightRange); 1113 return operation.apply(leftRange, rightRange);
1090 } 1114 }
1091 } 1115 }
OLDNEW
« 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