[PATCH] D12166: Assign weights to edges to jump table when lowering switch statement.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 16:47:02 PDT 2015


hans added a comment.

This looks fine to me, but it would be really nice to get tests here.


================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1900
@@ -1899,3 +1899,3 @@
 
-  addSuccessorWithWeight(SwitchBB, B.Default);
-  addSuccessorWithWeight(SwitchBB, MBB);
+  uint32_t DefaultWeight = getEdgeWeight(SwitchBB, B.Default);
+  addSuccessorWithWeight(SwitchBB, B.Default, DefaultWeight);
----------------
Does it get the DefaultWeight right here? (Not a criticism, just wondering if this ever worked.)

================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:8019
@@ +8018,3 @@
+        for (auto Succ : JumpMBB->successors())
+          JumpWeight += getEdgeWeight(JumpMBB, Succ);
+        uint64_t FallthruWeight = getEdgeWeight(CurMBB, Fallthrough);
----------------
I think the sum of all the branch weights on a branch (in this case a SwitchInst) will not overflow an uint32_t. Since we're adding up weights from the same switch it should be safe to use uint32_t for JumpWeight and skip the ScaleWeights below.


http://reviews.llvm.org/D12166





More information about the llvm-commits mailing list