[llvm] r265762 - Don't IPO over functions that can be de-refined

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 11:12:21 PDT 2016


Benjamin Kramer wrote:
 > $ cat foo.cc
 > inline void foo(const char *, ...) {}
 >
 > int main() {
 >    foo("bar");
 > }
 >
 > $ clang-old -S -o - log.cc -O2|grep -c bar
 > 0
 > $ clang-new -S -o - log.cc -O2|grep -c bar
 > 1
 >
 > Is this something we want to fix or is that how it's supposed to work
 > now. GCC happily discards foo() here.

This is a correct optimization that the old LLVM did for the wrong
reasons.  What most likely happened in the old LLVM was we'd infer
readnone on foo() and then elide the readnone call to foo in main.
Now the first step isn't happening anymore, because it is unsound.

If this specific case is important to you, there probably are things
we can do get the above optimization (e.g. inlining through simple
varargs functions).  If this can wait, then whatever we do to win back
non-inlining IPO for normal C++ inline function should kick in here
as well.

-- Sanjoy


More information about the llvm-commits mailing list