On Tue, Jul 17, 2012 at 1:21 PM, Tom de Vries <tom_devr...@mentor.com> wrote: > Richard, > > attached patch implements an if-to-switch conversion tree pass > pass_if_to_switch.
Nice. I've been working on something similar, using the paper "Efficient and Effective Branch Reordering Using Profile Data" (Mingui Yang et. al., see www.cs.fsu.edu/~whalley/papers/acmtoplas02.ps and also mentioned in tree-switch-conversion.c). The if-to-switch conversion falls out naturally from the algorithm proposed in that paper. It also proposes basic block duplication to form longer chains of if-chains to convert. I think you should compare your method to the one described in the paper, and at least reference the paper if it's somehow similar -- once upon a time it was a stated goal of tree-ssa to use algorithms close to "literature algorithms". Your approach looks very similar: smarter in some respects (the bit ranges stuff) and less sophisticated in others (no block duplication). This transformation should *not* be enabled by default at -O2. Users may have sorted the branches deliberately in a certain order, and if switch expansion results in a different order, your transformation is not an optimization. If the transformation is enabled with -fprofile-use, profile information gets lost with this transformation, because you don't have unique edges per condition anymore. This always hurts for the default case, and may also hurt "normal" cases. The Yang paper describes a value profiling method to record per-condition profile data, and I was planning to implement that as well (and also the PGO switch lowering that Freescale proposed at the GCC Summit 2006, see http://gcc.gnu.org/ml/gcc-patches/2008-04/msg02120.html). Perhaps you can have a look and see if there are some handles in the above that you can work with :-) Ciao! Steven