Reviewers: Sven Panne,
Message:
PTAL
Description:
Fix smi-based math floor.
BUG=chromium:270268
Please review this at https://chromiumcodereview.appspot.com/22623007/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/hydrogen-instructions.h
M src/hydrogen.cc
A + test/mjsunit/regress/regress-smi-math-floor.js
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index
f977a750d946a6b24d657b08229fc4a238c368b2..a03faca5c85ff989f6c35449e24b41e82b2b5ce3
100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -2430,6 +2430,21 @@ class HUnaryMathOperation: public
HTemplateInstruction<2> {
}
}
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentationPhase* h_infer,
+ const char* reason) {
+ if (flexible_int() && !new_rep.IsSmi()) {
+ new_rep = Representation::Integer32();
+ }
+ HValue::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
+ virtual void RepresentationChanged(Representation new_rep) {
+ if (flexible_int() && new_rep.IsInteger32()) {
+ ClearFlag(kFlexibleRepresentation);
+ }
+ }
+
virtual Range* InferRange(Zone* zone);
virtual HValue* Canonicalize();
@@ -2447,6 +2462,10 @@ class HUnaryMathOperation: public
HTemplateInstruction<2> {
}
private:
+ bool flexible_int() {
+ return op_ == kMathFloor || op_ == kMathRound;
+ }
+
HUnaryMathOperation(HValue* context, HValue* value, BuiltinFunctionId op)
: HTemplateInstruction<2>(HType::TaggedNumber()), op_(op) {
SetOperandAt(0, context);
@@ -2454,8 +2473,8 @@ class HUnaryMathOperation: public
HTemplateInstruction<2> {
switch (op) {
case kMathFloor:
case kMathRound:
- // TODO(verwaest): Set representation to flexible int starting as
smi.
- set_representation(Representation::Integer32());
+ set_representation(Representation::Smi());
+ SetFlag(kFlexibleRepresentation);
break;
case kMathAbs:
// Not setting representation here: it is None intentionally.
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index
f7ef91a088d9ea639a80089fc62ef85d39ed79be..81f0ef8fd79c1ba4880714dbf9f6ac07566cdd72
100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -8041,10 +8041,6 @@ void
HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
result->set_position(expr->position());
return ast_context()->ReturnInstruction(result, expr->id());
} else {
- // TODO(verwaest): Remove once Representation::FromType properly
- // returns Smi when the IC measures Smi.
- if (left_type->Is(Type::Smi())) left_rep = Representation::Smi();
- if (right_type->Is(Type::Smi())) right_rep = Representation::Smi();
HCompareNumericAndBranch* result =
new(zone()) HCompareNumericAndBranch(left, right, op);
result->set_observed_input_representation(left_rep, right_rep);
Index: test/mjsunit/regress/regress-smi-math-floor.js
diff --git a/test/mjsunit/regress/regress-crbug-173974.js
b/test/mjsunit/regress/regress-smi-math-floor.js
similarity index 92%
copy from test/mjsunit/regress/regress-crbug-173974.js
copy to test/mjsunit/regress/regress-smi-math-floor.js
index
905bd6058a0ad0fe2ebe10e4c7dafbe9945cbe3b..d54f22785bb82eda46c55ede762e19fc1598676d
100644
--- a/test/mjsunit/regress/regress-crbug-173974.js
+++ b/test/mjsunit/regress/regress-smi-math-floor.js
@@ -27,10 +27,12 @@
// Flags: --allow-natives-syntax
-function f() {
- var count = "";
- count[0] --;
+
+function f(o) {
+ return Math.floor(o.x) + 1;
}
-f();
+
+assertEquals(2, f({x:1}));
+assertEquals(2, f({x:1}));
%OptimizeFunctionOnNextCall(f);
-f();
+assertEquals(2, f({x:1}));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.