SelectionDAGBuilder: When emitting small compare chains for switches order them by...
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 26 May 2012 20:01:32 +0000 (20:01 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 26 May 2012 20:01:32 +0000 (20:01 +0000)
commitf2beccf6b4e9eb59b5080ae866e8d59a38679f15
treef6d6e5139cda47ff6b8c8e770d744c5db577ee18
parent7b01b578a93062fa75cf79f4b8753d539d72f76f
SelectionDAGBuilder: When emitting small compare chains for switches order them by using edge weights.

SimplifyCFG tends to form a lot of 2-3 case switches when merging branches. Move
the most likely condition to the front so it is checked first and the others can
be skipped. This is currently not as effective as it could be because SimplifyCFG
destroys profiling metadata when merging branches and switches. Merging branch
weight metadata is tricky though.

This code touches at most 3 cases so I didn't use a proper sorting algorithm.

llvm-svn: 157521
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/test/CodeGen/X86/switch-order-weight.ll [new file with mode: 0644]