[PATCH] Expand SimplifyCFG to convert certain simple switches to selects

Marcello Maggioni hayarms at gmail.com
Mon Jun 23 06:37:04 PDT 2014


New revision.

In this revision I addressed most of the comments from Philip that I could, in particular:

-  I restructured ResultFound to be closer to it's use.
- Updated the comment about the two cases case.
- Added examples on the various cases helper functions
- Handled directly the case "single range + default" i.e. 
  switch (a) {
  case 4,5,6: return 20;
  default: return 10;
  }
  before this case was handled by TurnSwitchRangeIntoICmp + SimplifyCondBranch. Now it is handled directly. The patterns of some tests for this , because the name of the generated virtual registers was different, but the generated code is the same.
- Switched to an early return approach in the function
- Moved the Switch removal + PHI fixup into an helper function

In addition to that I:
- Changed the order of execution of TurnSwitchRangeIntoICmp to run after SwitchToSelect , so that this function can handled directly some cases handled by TurnSwitchRangeIntoICmp + SimplifyCondBranch. Changing this order shouldn't have any other side effect.
- Modified the function to make optimization that have only "one value + default value" (like the "single range + default" above) possible to implement, so in the future if someone has an idea to add here that matches this pattern it is possible to add.

http://reviews.llvm.org/D4219

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/2014-06-19-SwitchToSelectBitPattern.ll
  test/Transforms/SimplifyCFG/2014-06-19-SwitchToSelectRange.ll
  test/Transforms/SimplifyCFG/2014-06-19-SwitchToSelectTwoCase.ll
  test/Transforms/SimplifyCFG/UnreachableEliminate.ll
  test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
  test/Transforms/SimplifyCFG/switch-to-icmp.ll
  test/Transforms/SimplifyCFG/switch_create.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4219.10751.patch
Type: text/x-patch
Size: 27792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140623/9d4a0aee/attachment.bin>


More information about the llvm-commits mailing list