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

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 17:08:01 PDT 2015


congh added inline comments.

================
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);
----------------
hans wrote:
> Does it get the DefaultWeight right here? (Not a criticism, just wondering if this ever worked.)
Yes. getEdgeWeight() will retrieve edge weight through BPI from BB instead of MBB.

================
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);
----------------
hans wrote:
> 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.
You are right. I will replace uint64_t with uint32_t and remove ScaleWeights() here. Thanks for pointing it out!


http://reviews.llvm.org/D12166





More information about the llvm-commits mailing list