Reviewers: Kevin Millikin, fschneider,

Message:
In theory, this should improve some benchmarks, and have at least no negative
effects on others, but measurements show no real conclusive results. :-(

I just wanted to upload my changes to see if somebody sees a stupid mistake or
some misconception how things work...

Description:
Give uses within a loop a greater weight when doing representation inference.

Uses of a value are weighted by a factor of FLAG_loop_weight (default: 10) for every loop they are in. This makes uses in inner loops "more important", which
should improve the result of the representation inference.

Please review this at http://codereview.chromium.org/8277031/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/flag-definitions.h
  M     src/hydrogen-instructions.h
  M     src/hydrogen-instructions.cc
  M     src/hydrogen.cc


Index: src/flag-definitions.h
===================================================================
--- src/flag-definitions.h      (revision 9619)
+++ src/flag-definitions.h      (working copy)
@@ -152,6 +152,7 @@
 DEFINE_bool(trace_osr, false, "trace on-stack replacement")
 DEFINE_int(stress_runs, 0, "number of stress runs")
 DEFINE_bool(optimize_closures, true, "optimize closures")
+DEFINE_int(loop_weight, 10, "loop weight for representation inference")

 // assembler-ia32.cc / assembler-arm.cc / assembler-x64.cc
 DEFINE_bool(debug_code, false,
Index: src/hydrogen-instructions.cc
===================================================================
--- src/hydrogen-instructions.cc        (revision 9619)
+++ src/hydrogen-instructions.cc        (working copy)
@@ -67,6 +67,19 @@
 }


+template<class T> inline const T& min(const T& a, const T& b) {
+  return (a < b) ? a : b;
+}
+
+
+int HValue::LoopWeight() const {
+  const int w = FLAG_loop_weight;
+  static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w };
+  return weights[min(block()->LoopNestingDepth(),
+                     static_cast<int>(ARRAY_SIZE(weights)-1))];
+}
+
+
 void HValue::AssumeRepresentation(Representation r) {
   if (CheckFlag(kFlexibleRepresentation)) {
     ChangeRepresentation(r);
@@ -1117,7 +1130,7 @@
     HValue* value = it.value();
     if (!value->IsPhi()) {
       Representation rep = value->RequiredInputRepresentation(it.index());
-      ++non_phi_uses_[rep.kind()];
+      non_phi_uses_[rep.kind()] += value->LoopWeight();
     }
   }
 }
Index: src/hydrogen-instructions.h
===================================================================
--- src/hydrogen-instructions.h (revision 9619)
+++ src/hydrogen-instructions.h (working copy)
@@ -556,6 +556,7 @@

   HBasicBlock* block() const { return block_; }
   void SetBlock(HBasicBlock* block);
+  int LoopWeight() const;

   int id() const { return id_; }
   void set_id(int id) { id_ = id; }
Index: src/hydrogen.cc
===================================================================
--- src/hydrogen.cc     (revision 9619)
+++ src/hydrogen.cc     (working copy)
@@ -1652,7 +1652,7 @@
     Representation rep = use->RequiredInputRepresentation(it.index());
     if (rep.IsNone()) continue;
     if (use->IsPhi()) HPhi::cast(use)->AddIndirectUsesTo(&use_count[0]);
-    ++use_count[rep.kind()];
+    use_count[rep.kind()] += use->LoopWeight();
   }
   int tagged_count = use_count[Representation::kTagged];
   int double_count = use_count[Representation::kDouble];


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to