[llvm-commits] [LLVM, SwitchInst, case ranges] Auxiliary patch #1

Chris Lattner clattner at apple.com
Thu Jan 5 09:43:56 PST 2012


On Oct 31, 2011, at 11:56 PM, Duncan Sands wrote:

> Hi Anton,
> 
>>> be the opposite: they might make switches harder to work with and reason about
>>> for no advantage.  Which is it?  Do you have an example where case ranges would
>>> result in better code, or make it easier to produce better code?
>> I think the typical example is some code which produces large
>> switches. In the frontend we
>> won't emit such large switches and end with explicit comparisons instead.
>> 
>> Do you have some example of this from Ada world? I believe I saw
>> something like this in Polyhedron, but I'm not sure.
> 
> this happens all the time with Ada, for example with ranges like "all negative
> numbers".  Currently the front-end emits explicit compares and branches for the
> big ranges (more than 64 cases), and a switch for the rest.  If LLVM switches
> had ranges, would LLVM produce better code for this kind of thing?

I haven't had a chance to look at Stepan's patch, but FWIW I'm generally supportive of the idea.  One problem that this solves is that our current modeling of switches causes us to have critical edges from the switch for trivial cases.  For example:

switch (x) {
case 4:
case 5:
  stuff

will have two CFG edges from the switch, both going to the same block (so it has multiple predecessors).  Various code that splits this critical edge end up producing really really bad code.

If we modeled that as one edge in the CFG, many similar problems would disappear.

-Chris




More information about the llvm-commits mailing list