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

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/invoke_dynamic_specializers.dart

Issue 94303002: Add another type JSPositiveInt to show a range analysis in the inferrer would be very beneficial :-… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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
Index: sdk/lib/_internal/compiler/implementation/ssa/invoke_dynamic_specializers.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/ssa/invoke_dynamic_specializers.dart (revision 30754)
+++ sdk/lib/_internal/compiler/implementation/ssa/invoke_dynamic_specializers.dart (working copy)
@@ -220,12 +220,29 @@
instruction.setUseGvn();
}
+ bool inputsArePositiveIntegers(HInstruction instruction, Compiler compiler) {
+ HInstruction left = instruction.inputs[1];
+ HInstruction right = instruction.inputs[2];
+ JavaScriptBackend backend = compiler.backend;
+ return left.isPositiveIntegerOrNull(compiler)
+ && right.isPositiveIntegerOrNull(compiler);
+ }
+
HInstruction newBuiltinVariant(HInvokeDynamic instruction, Compiler compiler);
}
class AddSpecializer extends BinaryArithmeticSpecializer {
const AddSpecializer();
+ TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
+ Compiler compiler) {
+ if (inputsArePositiveIntegers(instruction, compiler)) {
+ JavaScriptBackend backend = compiler.backend;
+ return backend.positiveIntType;
+ }
+ return super.computeTypeFromInputTypes(instruction, compiler);
+ }
+
BinaryOperation operation(ConstantSystem constantSystem) {
return constantSystem.add;
}
@@ -267,6 +284,15 @@
class ModuloSpecializer extends BinaryArithmeticSpecializer {
const ModuloSpecializer();
+ TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
+ Compiler compiler) {
+ if (inputsArePositiveIntegers(instruction, compiler)) {
+ JavaScriptBackend backend = compiler.backend;
+ return backend.positiveIntType;
+ }
+ return super.computeTypeFromInputTypes(instruction, compiler);
+ }
+
BinaryOperation operation(ConstantSystem constantSystem) {
return constantSystem.modulo;
}
@@ -285,6 +311,15 @@
return constantSystem.multiply;
}
+ TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
+ Compiler compiler) {
+ if (inputsArePositiveIntegers(instruction, compiler)) {
+ JavaScriptBackend backend = compiler.backend;
+ return backend.positiveIntType;
+ }
+ return super.computeTypeFromInputTypes(instruction, compiler);
+ }
+
HInstruction newBuiltinVariant(HInvokeDynamic instruction,
Compiler compiler) {
return new HMultiply(
@@ -315,6 +350,15 @@
return constantSystem.truncatingDivide;
}
+ TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
+ Compiler compiler) {
+ if (inputsArePositiveIntegers(instruction, compiler)) {
+ JavaScriptBackend backend = compiler.backend;
+ return backend.positiveIntType;
+ }
+ return super.computeTypeFromInputTypes(instruction, compiler);
+ }
+
HInstruction newBuiltinVariant(HInvokeDynamic instruction,
Compiler compiler) {
// Truncating divide does not have a JS equivalent.
@@ -348,7 +392,7 @@
bool isPositive(HInstruction instruction, Compiler compiler) {
// TODO: We should use the value range analysis. Currently, ranges
// are discarded just after the analysis.
- return instruction.isUInt32(compiler);
+ return instruction.isPositiveInteger(compiler);
}
}

Powered by Google App Engine
This is Rietveld 408576698