[lkml]   [2007]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: sparse -Wptr-subtraction-blows: still needed?
    Alan Cox <> writes:
    > Good compilers even in the 1990's would defer the divide and try and
    > propogate it out as a multiply the other side for constants, and they'll
    > also use shifts when possible.

    gcc has an algorithm that tends to generate a near perfect shift/add etc.
    code sequence and also knows the obvious x / y ==> x*1/y

    However it doesn't do that with -Os, prefering smaller code on x86
    (idiv is fairly small compared to the expanded sequences for non power
    of two dividends) and kernels are usually compiled with -Os these

    We've had a few cases in the past where this showed up as regression
    against older kernels that still used -O2.

    > Thus they'll turn
    > (ptr.element - base.element) < NELEM
    > into
    > (ptr.char - base.char) < (constant) [NELEM *sizeof(element) ]
    > at least for constant operations. Dunno if gcc is that clever

    It is. However a few more complex transformations I would have liked
    in the past are missing -- in particular

    x / (cond ? const1 : const2) ==> cond ? (x / const1) : (x / const2)

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2007-05-02 14:23    [W:0.022 / U:0.032 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site