[llvm-commits] PATCH: Add support for tracking pairs of pointers with a constant offset to inline cost estimation

Duncan Sands baldrick at free.fr
Fri Mar 9 00:43:58 PST 2012


Hi Chandler, on a meta note, in the long run is it really a good idea to add
ever more special case logic here?  I can't help feeling that there needs to
be an infrastructure that can uniformly catch everything here.  On IRC I did
mutter about instsimplify, however a large part of instsimplify (and constant
folding) is a list of patterns like this: x ^ x -> 0, (x+y)-x -> y, etc.  Maybe
we should factorize this kind of thing out in some way that in can be applied to
instructions (instsimplify), constants (constant folding), "instructions we
would get if we actually inlined this thing" (inline cost), SCEV (loops) etc.

Ciao, Duncan.

> This is an early patch, it still has some rough edges. In particular, I want to
> clean up the body of the loop which looks for operations to simplify in the
> function body, but I wanted to start showing people where I'm going here and get
> any feedback sooner rather than later.
>
> The motivation for these heroics (and I recognize that these are heroics) is to
> handle cases like:
>
> template <typename IteratorT>
> foo my_algorithm(IteratorT first, IteratorT last) {
>    if (std::distance(first, last) < 42) {
>      // Algorithm A
>    } else {
>      // Algorithm B
>    }
> }
>
> Without this patch, the inline cost will be assumed to be the total size of the
> function, even when we call it like so:
>
> void test(int *ptr) {
>    foo bar = my_algorithm(ptr, ptr + 13);
> }
>
> Here, the arguments are a known constant offset, and yet we won't see that, or
> see that only one half of the branch in my_algorithm is going to survive. This
> causes missed optimizations every time we use an STL algorithm on a fixed buffer
> (usually a stack object).
>
> The patch tries to track these correlated pointer values, and detect when
> they're used in a way that will simplify. Initial testing shows that it works,
> but I haven't yet reduced my big test cases into nice small feature tests for
> the test suite. Clearly, that has to happen before check-in.
>
>
> Let me know your thoughts! I'll post a new patch as I clean it up, and I'll also
> post numbers as I have them on the impact this gives.
>
>
> _______________________________________________
> 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