[PATCH] D52707: Switch optimization in IR for known maximum switch values

Ayonam Ray via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 30 23:26:42 PDT 2018


ayonam created this revision.
ayonam added reviewers: bogner, lattner, hans, bkramer.
ayonam added a project: CodeChecker into llvm/clang.
Herald added a subscriber: llvm-commits.

This patch is for optimizing a switch statement where the switch expression can be analyzed to determine the maximum value it can take.  In such cases, the default statement generates a conditional branch comparing the switch value with the highest value of case statement given.  This branch can be avoided by adding the missing case statements between the highest value of case statement given and the maximum value the switch expression can take and then redirecting all these new case statements to the default block.  Thereafter, the default block can be marked as unreachable, which would remove the conditional branch while lowering the switch statement.  This part is dealt with in the Revision https://reviews.llvm.org/D52002 that is also up for review.


Repository:
  rL LLVM

https://reviews.llvm.org/D52707

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52707.167671.patch
Type: text/x-patch
Size: 4936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181001/647f470d/attachment.bin>


More information about the llvm-commits mailing list