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

Chandler Carruth chandlerc at gmail.com
Thu Mar 8 19:13:52 PST 2012


Hello folks!

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120308/9df8a719/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline-cost-ptr-pair.diff
Type: application/octet-stream
Size: 9876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120308/9df8a719/attachment.obj>


More information about the llvm-commits mailing list