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

Erik Eckstein eeckstein at apple.com
Mon Dec 1 03:06:32 PST 2014


commited in r222891. Note that I added a fix which checks that the guarding branch dominates the phi-block.

================
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:
> 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.
If I move the phi-loop to reuseTableCompare, I cannot easily return in case the optimization cannot be done for a specific phi-user.
I would need another helper function, which I don't like either.
Therefore I kept it as it is.

http://reviews.llvm.org/D6423






More information about the llvm-commits mailing list