[inliner] Completely change (and fix) how the inline cost analysis
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Dec 2013 07:59:56 +0000 (07:59 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Dec 2013 07:59:56 +0000 (07:59 +0000)
commit0bdc7cd5de8b11564ce7ab3af584b11a48b7ab51
treeb50303b77431b0ab2b531eeb1374a613599b5ea3
parent2d39ad82bc64c5fd4536fe02bb6ab3f153a7dfac
[inliner] Completely change (and fix) how the inline cost analysis
handles terminator instructions.

The inline cost analysis inheritted some pretty rough handling of
terminator insts from the original cost analysis, and then made it much,
much worse by factoring all of the important analyses into a separate
instruction visitor. That instruction visitor never visited the
terminator.

This works fine for things like conditional branches, but for many other
things we simply computed The Wrong Value. First example are
unconditional branches, which should be free but were counted as full
cost. This is most significant for conditional branches where the
condition simplifies and folds during inlining. We paid a 1 instruction
tax on every branch in a straight line specialized path. =[

Oh, we also claimed that the unreachable instruction had cost.

But it gets worse. Let's consider invoke. We never applied the call
penalty. We never accounted for the cost of the arguments. Nope. Worse
still, we didn't handle the *correctness* constraints of not inlining
recursive invokes, or exception throwing returns_twice functions. Oops.
See PR18206. Sadly, PR18206 requires yet another fix, but this
refactoring is at least a huge step in that direction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197215 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/IPA/InlineCost.cpp
test/Transforms/Inline/invoke-cost.ll [new file with mode: 0644]