[PATCH] D52002: Switch optimization for known maximum switch values

Ayonam Ray via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 12 13:21:29 PDT 2018


ayonam created this revision.
ayonam added reviewers: bogner, lattner, spatel.
Herald added a subscriber: llvm-commits.

This patch optimizes a switch statement where the possible range of values of the switch variable can be computed at compile time and the default case represents a small subset of those values (heuristically set to 30%) all of which are contiguous.  In such cases, a conditional branch at the top of the switch body to represent the default values causes a considerable penalty due to branch mispredicts.  Replacing this conditional branch with additional entries in the jump table for the values that would have otherwise directed the switch to the default case, improves performance by 2 - 3%.

The changes mainly involve recording the maximum possible value of the switch in the analysis pass and then using that value to determine generation of the conditional branch as well as the additional entries in the jump table.


Repository:
  rL LLVM

https://reviews.llvm.org/D52002

Files:
  include/llvm/IR/Instructions.h
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
  lib/IR/Instructions.cpp
  lib/Transforms/Utils/SimplifyCFG.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52002.165133.patch
Type: text/x-patch
Size: 11688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180912/b622acf1/attachment.bin>


More information about the llvm-commits mailing list