On Mar 12, 2007, at 1:48 PM, Duncan Sands wrote:

> In gcc, a switch case is a range of values that branch
> to a label, for example 1 .. 17 -> label.  These are
> emitted as individual LLVM switch cases: 1 -> label,
> 2 -> label, ..., 17 -> label.  This works well except,
> for example, when the range is INT_MIN .. 0 -> label,
> in which case you can say goodbye to all your memory!
> This patch causes ranges with more than 64 elements
> (128 on 64 bit machines) to be emitted as explicit "if"
> statements.  For example, the following gcc switch
> (from the Ada testcase)

The patch looks good with two changes:

+    ConstantInt *Range = cast<ConstantInt>(ConstantExpr::getSub(HiC,  
ValC));

Please use APInt's to do the subtraction, instead of constant  
folding.  Reid should be able to help you with this.

+    if (Range->getZExtValue() < 2*HOST_BITS_PER_WIDE_INT) {

This is bad because it means llvm-gcc will produce different code  
based on thevalue of HOST_BITS...  Please just say " < 64" or something.

-Chris
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to