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

Duncan Sands baldrick at free.fr
Fri Oct 28 12:50:53 PDT 2011


Hi Stepan,

> Well, on instruction selection level switch cases are already grouped to switch ranges. I don't think that case ranges increases complexity of existing optimizers.

I guess Anton can comment on codegen, but the fact that it doesn't make codegen
harder has nothing to do with increasing the complexity of the optimizers, since
they work at the IR level.  It may be that case ranges allow the optimizers to
do a better job.  It may be that they simplify the optimizers.  But it also may
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 that its useful when we work with front-ends like Fortran, since we 
doesn't need to split fortran's case-ranges and combine them again during switch 
lowering procedure.

Does doing this combining have a significant impact on anything (like compile
time)?  If not, then it doesn't matter much.  It's even a good thing if the
simple form switch statements currently have make the optimizers easier to write 
and improve.

By the way, Ada also produces ranges, but unlike in C (I don't remember how
this is in Fortran) switch conditions can be signed or unsigned, resulting in
signed or unsigned ranges.  Will your ranges be circular (along the lines of
LLVM's ConstantRange class), so that both are handled uniformly?

Ciao, Duncan.

>
> -Stepan
>
> 28.10.2011, 16:19, "Duncan Sands"<baldrick at free.fr>:
>> Hi Stepan, I have to ask: what are switch case ranges good for?  Will they
>> actually result in better code, or just more complexity in the optimizers
>> and code generators?  Sorry to ask at this late date.  I know I'm the one
>> that first suggested adding case ranges, but I've since come to wonder
>> whether they are really useful.
>>
>> Ciao, Duncan.
>>
>>>   Hi all. The main discussion branch of this feature is here:
>>>   http://llvm.org/bugs/show_bug.cgi?id=1255
>>>
>>>   We need change SwitchInst internals: replace case value type from "ConstantInt"
>>>   to "APInt", then move case values out from operands collection. To do that we
>>>   need add APInt::isInitialized feature. We also need extend SmallSet class adding
>>>   Compare parameter to this template:
>>>   template<typename T, unsigned N, typename C = std::less<T>  >
>>>
>>>   Please find attached patches for review.
>>>
>>>   Regards,
>>>   Stepan.
>>>
>>>   _______________________________________________
>>>   llvm-commits mailing list
>>>   llvm-commits at cs.uiuc.edu
>>>   http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list