[PATCH] peephole optimization in switch table lookup: reuse the guarding table comparison if possible

Hans Wennborg hans at chromium.org
Wed Nov 26 17:03:50 PST 2014


Looks good to me.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:4006
@@ +4005,3 @@
+/// Jump threading will then eliminate the second if(cond).
+void reuseTableCompare(User *PhiUser, BasicBlock *PhiBlock,
+          BranchInst *RangeCheckBranch, Constant *DefaultValue,
----------------
This helper function should probably be static.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:4006
@@ +4005,3 @@
+/// Jump threading will then eliminate the second if(cond).
+void reuseTableCompare(User *PhiUser, BasicBlock *PhiBlock,
+          BranchInst *RangeCheckBranch, Constant *DefaultValue,
----------------
hans wrote:
> This helper function should probably be static.
Instead of passing both PhiUser and PhiBlock, can't we just pass in the PhiNode and iterate over the users ourselves? That way we get to extract some more code too, which I think would be good.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:4041
@@ +4040,3 @@
+    assert((CaseConst == TrueConst || CaseConst == FalseConst) &&
+           "expect true or false as compare result");
+  }
----------------
ultra nit: Upper case and period is nice even in asserts.

http://reviews.llvm.org/D6423






More information about the llvm-commits mailing list