[PATCH] Switch lowering: use profile info to build weight-balanced binary search trees

Daniel Jasper djasper at google.com
Wed Apr 29 09:34:28 PDT 2015


================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7814
@@ +7813,3 @@
+           "Weights must be non-zero for pivot selection to work.");
+    if (LeftWeight < RightWeight) {
+      LeftWeight += (++Left)->Weight;
----------------
No braces.

================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7819
@@ +7818,3 @@
+  }
+  CaseClusterIt PivotCluster = Right;
+  assert(PivotCluster > W.FirstCluster && PivotCluster <= W.LastCluster);
----------------
At this point Left and Right are identical and the element they are pointing it belongs to the larger/heavier weight, right?

================
Comment at: test/CodeGen/Generic/MachineBranchProb.ll:61
@@ +60,3 @@
+; CHECK-NOT: Successors
+; CHECK: Successors according to CFG: BB#8(13) BB#9(20)
+}
----------------
Maybe add a comment that this division is because the left half is 1+10+1+1 = 13, the right half is 10+10=20 and we are directly checking against the pivot element so that that one weight doesn't contribute to either side. (If I am correct).

================
Comment at: test/CodeGen/X86/switch.ll:471
@@ +470,3 @@
+
+!3 = !{!"branch_weights", i32 1, i32 10, i32 0, i32 0, i32 0, i32 0, i32 10}
+
----------------
Could you describe somewhere (patch description, comment) what weight=0 means and how it affects the balancing? From this test, I would assume that we just do balanced trees in this case. However, the test below suggests otherwise.

http://reviews.llvm.org/D9318

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list