Reviewers: danno,
Message:
PTAL.
Description:
Better handling of Phi nodes feeding booleans into truncating integer
operations
Please review this at https://codereview.chromium.org/14471034/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/hydrogen-instructions.h
M src/hydrogen-instructions.cc
M src/hydrogen.cc
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index
d6710a4fa1f43b9311f416c5e5604c46f4322832..fe3ea44238f0fe2f9982051eacf2af32a980e838
100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -2264,7 +2264,8 @@ Representation
HBinaryOperation::RepresentationFromInputs() {
void HBinaryOperation::AssumeRepresentation(Representation r) {
- set_observed_input_representation(r, r);
+ set_observed_input_representation(1, r);
+ set_observed_input_representation(2, r);
HValue::AssumeRepresentation(r);
}
@@ -3462,6 +3463,50 @@ void HBitwise::PrintDataTo(StringStream* stream) {
}
+bool HPhi::AllOperandsConvertibleToInteger() {
+ // Convert "true or false" into "1 or 0" when all uses are truncating.
+ // This must happen before representation inference takes place.
+ do {
+ if (OperandCount() != 2) break;
+ if (!CheckUsesForFlag(kTruncatingToInt32)) break;
+ int false_input = -1, true_input = -1;
+ HGraph* graph = block()->graph();
+ for (int i = 0; i <= 1; ++i) {
+ HValue* operand = OperandAt(i);
+ if (operand == graph->GetConstantFalse()) {
+ false_input = i;
+ } else if (operand == graph->GetConstantTrue()) {
+ true_input = i;
+ }
+ }
+ // Did we find both?
+ if (false_input + true_input != 1) break;
+ SetOperandAt(false_input, graph->GetConstant0());
+ SetOperandAt(true_input, graph->GetConstant1());
+ for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
+ HValue* use = it.value();
+ if (use->IsBinaryOperation()) {
+ HBinaryOperation::cast(use)->set_observed_input_representation(
+ it.index(), Representation::Integer32());
+ }
+ }
+ return true;
+ } while (false);
+
+ for (int i = 0; i < OperandCount(); ++i) {
+ if (!OperandAt(i)->IsConvertibleToInteger()) {
+ if (FLAG_trace_representation) {
+ HValue* input = OperandAt(i);
+ PrintF("#%d %s: Input #%d %s at %d is NCTI\n",
+ id(), Mnemonic(), input->id(), input->Mnemonic(), i);
+ }
+ return false;
+ }
+ }
+ return true;
+}
+
+
void HPhi::InferRepresentation(HInferRepresentation* h_infer) {
ASSERT(CheckFlag(kFlexibleRepresentation));
// If there are non-Phi uses, and all of them have observed the same
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index
b4d26694a253a8c1c4de95a3228d445f4ab7cf84..10c32fdfe7f883179caba1eb1080a57662f90635
100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -3129,19 +3129,7 @@ class HPhi: public HValue {
is_convertible_to_integer_ = b;
}
- bool AllOperandsConvertibleToInteger() {
- for (int i = 0; i < OperandCount(); ++i) {
- if (!OperandAt(i)->IsConvertibleToInteger()) {
- if (FLAG_trace_representation) {
- HValue* input = OperandAt(i);
- PrintF("#%d %s: Input #%d %s at %d is NCTI\n",
- id(), Mnemonic(), input->id(), input->Mnemonic(), i);
- }
- return false;
- }
- }
- return true;
- }
+ bool AllOperandsConvertibleToInteger();
protected:
virtual void DeleteFromGraph();
@@ -3444,10 +3432,9 @@ class HBinaryOperation: public
HTemplateInstruction<3> {
return right();
}
- void set_observed_input_representation(Representation left,
- Representation right) {
- observed_input_representation_[0] = left;
- observed_input_representation_[1] = right;
+ void set_observed_input_representation(int index, Representation rep) {
+ ASSERT(index >= 1 && index <= 2);
+ observed_input_representation_[index - 1] = rep;
}
virtual void initialize_output_representation(Representation observed) {
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index
9ca78ccc84454c2f20140f22614b5951b79911e9..33d5f19445089b571627580ac06dbc2d65b44035
100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -9454,7 +9454,8 @@ void HOptimizedGraphBuilder::VisitSub(UnaryOperation*
expr) {
info = TypeInfo::Unknown();
}
if (instr->IsBinaryOperation()) {
- HBinaryOperation::cast(instr)->set_observed_input_representation(rep,
rep);
+ HBinaryOperation::cast(instr)->set_observed_input_representation(1,
rep);
+ HBinaryOperation::cast(instr)->set_observed_input_representation(2,
rep);
}
return ast_context()->ReturnInstruction(instr, expr->id());
}
@@ -9895,7 +9896,8 @@ HInstruction*
HOptimizedGraphBuilder::BuildBinaryOperation(
if (instr->IsBinaryOperation()) {
HBinaryOperation* binop = HBinaryOperation::cast(instr);
- binop->set_observed_input_representation(left_rep, right_rep);
+ binop->set_observed_input_representation(1, left_rep);
+ binop->set_observed_input_representation(2, right_rep);
binop->initialize_output_representation(result_rep);
}
return instr;
@@ -10275,7 +10277,8 @@ void
HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
if (combined_rep.IsTagged() || combined_rep.IsNone()) {
HCompareGeneric* result =
new(zone()) HCompareGeneric(context, left, right, op);
- result->set_observed_input_representation(left_rep, right_rep);
+ result->set_observed_input_representation(1, left_rep);
+ result->set_observed_input_representation(2, right_rep);
result->set_position(expr->position());
return ast_context()->ReturnInstruction(result, expr->id());
} else {
--
--
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.