Re: sparse -Wptr-subtraction-blows: still needed?

From: Andi Kleen
Date: Wed May 02 2007 - 08:21:53 EST


Alan Cox <alan@xxxxxxxxxxxxxxxxxxx> 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
days.

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)

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/