[PATCH] LowerSwitch: replace unreachable default with popular case destination

Hans Wennborg hans at chromium.org
Sat Jan 10 14:25:58 PST 2015


> The main problem is that the presence of a default block confuses the UpperBound and LowerBound computations , that cannot rely on skipping gaps between ranges of switch values anymore, which is a good optimization if the default block is absent.

> 

> Your test case is an example of code that gets worse in this case with the patch that without.


I think the problem was just that my patch prevented us from setting LowerBound and UpperBound. We should still set them even if the unreachable default gets replaced with a reachable destination. With that, I think there is no trade-off here - replacing the unreachable default is always profitable or neutral.

Thanks for catching that my test case was an example of where things got worse; that's embarrassing :) I've added a new test that benefits both from replacing the default and having UpperBound and LowerBound set.

> Usually LowerSwitch runs pretty late in the pipeline, in preparation for CodeGen.


Looking forward to getting this transformation out of SimplifyCFG so LowerSwitch can benefit, then :)


http://reviews.llvm.org/D6697

Files:
  lib/Transforms/Utils/LowerSwitch.cpp
  test/Transforms/LowerSwitch/2014-06-11-SwitchDefaultUnreachableOpt.ll
  test/Transforms/LowerSwitch/fold-popular-case-to-unreachable-default.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6697.17977.patch
Type: text/x-patch
Size: 5095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150110/7f3336ad/attachment.bin>


More information about the llvm-commits mailing list