[PATCH] D52716: [Inliner] Penalise inlining of calls with loops at Oz

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 1 14:22:07 PDT 2018


efriedma added a comment.

We could probably improve our handling of GEPs; for example, a GEP used by a loop PHI node is probably not free.

> In the second test case the two branches for the loop arn't free because they aren't fallthroughs, but that sounds tough to model.

Probably not that hard to model: if a block has more than one unconditional branch predecessor, count each branch beyond the first.  Or something like that; maybe we could also do something more fancy for conditional branches, to guess whether they lower to one or two branch instructions at the machine level.

We could also try to improve our modeling of constants: we aren't assigning any cost to materializing `@digits`, or any cost to materializing "32" in `@call2`.

> Perhaps we could say that phis in loops have one "setup" cost? We would have to detect that the phi comes from a loop in that case.

The issue isn't really whether the PHI is in a loop; it has to do with the uses of the operand.  A PHI will eventually be lowered to a copy in each predecessor. The copy can be eliminated by the register allocator in many cases, but not all cases; the distinguishing factor is whether the PHI's operand is live after the PHI.

-----

Granted, just refusing to inline loops at -Oz probably does the right thing in most cases, but I'd like to see how far we can get by improving the cost model rather than artificially skewing it.


https://reviews.llvm.org/D52716





More information about the llvm-commits mailing list