This is an archive of the discontinued LLVM Phabricator instance.

Create as few pieces of an argument as possible when promoting an argument.
Needs ReviewPublic

Authored by trentxintong on Dec 29 2016, 1:49 PM.

Details

Reviewers
majnemer
rnk
Summary

Create as few pieces of an argument as possible when promoting an argument.
When LLVM finds a by-ref argument is only read by the callee and its the safe to dereference.
It could choose to promote this argument to one or more value arguments. Currently it goes through
all the loads and create them at every callsites.

This patch minimize the # of arguments passed in. i.e. If we have an argument thats completely
part of another argument (due to gep in the callee), we do not need to pass in this argument,
instead we do extractvalue from the other argument.

Event Timeline

trentxintong retitled this revision from to Create as few pieces of an argument as possible when promoting an argument..
trentxintong updated this object.
trentxintong added reviewers: rnk, majnemer.
trentxintong added a subscriber: llvm-commits.

Rework how ArgIndices is iterated a bit.

rnk edited edge metadata.Dec 29 2016, 3:46 PM

Doesn't SROA remove FCA loads? If so, it seems unlikely that arg promotion will ever see an FCA load.

SROA is ran after argument promotion, there is some unpacking in Instcombine as well, but its ran after argument promotion as well.

we do advise frontends against generating aggregate loads, but they may do so regardless.

rnk added a comment.Dec 29 2016, 3:53 PM

I'm sure there's some obscure reason for this phase ordering. Do we run instcombine before argument promotion? We should turn these FCA loads into GEPs, loads, and insertelements. FCA loads are currently non-canonical, although it is reasonable for a frontend to generate them.

Actually we do run one iteration of instcombine before argument promotion. Given that, I feel this is still useful as there are limits on what sort of aggregates we break up, e.g. if the struct has padding, we do not break it up. argprom however may still promote the argument.