This is an archive of the discontinued LLVM Phabricator instance.

ArgumentPromotion: Don't hack on functions containing musttail calls
AcceptedPublic

Authored by rnk on Jun 30 2014, 4:22 PM.

Details

Reviewers
nicholas
nlewycky
Summary

The prototypes need to match exactly in order to preserve ABI
guarantees. Hypothetically, if we can promote both the callee and the
caller all together, we can do argument promotion, but that is a
separable issue.

Diff Detail

Event Timeline

rnk updated this revision to Diff 10986.Jun 30 2014, 4:22 PM
rnk updated this revision to Diff 10987.
rnk retitled this revision from to ArgumentPromotion: Don't hack on functions containing musttail calls.
rnk updated this object.
rnk added a reviewer: nlewycky.
rnk added a subscriber: Unknown Object (MLST).
  • Add an assert near the tail call removal that I found

Isn't this overly conservative?

define internal void @aaa() {
  %X = ...
  %Y = ...
  call void @bbb(i8 %X, i8 %Y)
  ret void
}

define internal void @bbb(i8 %X, i8 %Y) {
  musttail call void @ccc(i8 %X, i8 %Y)
  ret void
}

define internal void @ccc(i8 %X, i8 %Y) {
  call @use(i8 %X)
  ret void
}

You can totally knock out %Y, right?

rnk added a comment.Jul 6 2014, 10:49 PM
In D4352#6, @nicholas wrote:

Isn't this overly conservative?

define internal void @aaa() {
  %X = ...
  %Y = ...
  call void @bbb(i8 %X, i8 %Y)
  ret void
}

define internal void @bbb(i8 %X, i8 %Y) {
  musttail call void @ccc(i8 %X, i8 %Y)
  ret void
}

define internal void @ccc(i8 %X, i8 %Y) {
  call @use(i8 %X)
  ret void
}

You can totally knock out %Y, right?

That would be deadargelim, not argument promotion, but that's besides the point.

Yes, if we could teach argument promotion to promote the entire call stack of musttail callers and callees at once, then we could do that transformation.

It might be worth it if we expect functional languages to use this construct widely. For C++, musttail is used with thunks that will either be a) virtual, and therefore not promotable, or b) devirtualized, and more profitable to inline at the call site.

nicholas accepted this revision.Jul 12 2014, 11:21 PM
nicholas added a reviewer: nicholas.
nicholas added inline comments.
test/Transforms/ArgumentPromotion/tail.ll
22

This comment was the reason for my question about it being overly conservative. Could you reword this to be more specific about what we can't do?

This revision is now accepted and ready to land.Jul 12 2014, 11:21 PM
rnk updated this revision to Diff 11767.Jul 22 2014, 11:11 AM
rnk edited edge metadata.
  • rebase
  • enhance comment

Looks like patch was not committed.