This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Remove trivially empty va_start/va_end and va_copy/va_end ranges.
ClosedPublic

Authored by aadg on Apr 11 2016, 12:58 PM.

Details

Reviewers
majnemer
Summary

When a va_start or va_copy is immediately followed by a va_end (ignoring
debug information or other start/end in between), then it is safe to
remove the pair. As this code shares some commonalities with the lifetime
markers, this has been factored to helper functions. In the va_copy
case a specific handling in needed because it does not have the same
prototype as the va_end.

This InstCombine pattern kicks-in 3 times when running the LLVM test
suite.

Diff Detail

Event Timeline

aadg updated this revision to Diff 53310.Apr 11 2016, 12:58 PM
aadg retitled this revision from to [InstCombine] Remove trivially empty va_start/va_end and va_copy/va_end ranges..
aadg updated this object.
aadg added a reviewer: majnemer.
aadg added a subscriber: llvm-commits.
rengolin added inline comments.
lib/Transforms/InstCombine/InstCombineCalls.cpp
1049

this could be a return false short-cut, not necessarily an assert...

1081

Where is this used and what's the point of always returning the null pointer?

1088

This could be a boolean flag to check for argument equality.

aadg added a comment.Apr 13 2016, 2:42 AM

Thanks for looking into it Renato !

lib/Transforms/InstCombine/InstCombineCalls.cpp
1049

The original intent is to make this helper only usable in this specific case (same number of argument). Any other case would point to an error.

After giving it a second thought, I think it's OK to make this helper a bit more "generic" so that it can be used as well in the VisitVACopy. I will update the patch in that direction.

1081

The InstCombiner is an InstVisitor, so the dispatch to the visit* method is done by the base InstVisitor class.

This is the semantics of the InstCombiner when the instruction actually visited has just been removed (and replaced with something else).

1088

As stated above, I think the prototypes of removeTriviallyEmptyRange & haveSameOperands should be adapted so that this method is reusing those helpers.

aadg updated this revision to Diff 53631.Apr 13 2016, 3:29 PM

[InstCombine] Remove trivially empty va_start/va_end and va_copy/va_end ranges.

Following the review, rework the helper functions to simplify the patch further.

majnemer added inline comments.May 6 2016, 1:50 PM
lib/Transforms/InstCombine/InstCombineCalls.cpp
1048–1049

Should we assert that both I and E have at least NumOperands?

1057–1058

It seems to stop at the first end intrinsic which matches the start's operands, it doesn't necessarily skip _all_ end intrinsics.

If we have something like:

call @llvm.foo.start(i1 0)
call @llvm.foo.start(i1 0)
call @llvm.foo.end(i1 0) ; This will not be skipped, it will be removed
call @llvm.foo.end(i1 0)

That being said, this behavior is probably fine, I'd just like the comment to be a little more clear.

1065

auto *E

aadg marked 3 inline comments as done.May 9 2016, 1:35 PM

I will address your comment with an update to the patch.

lib/Transforms/InstCombine/InstCombineCalls.cpp
1048–1049

Yes, it does not hurt to wear a safety belt.

1057–1058

I think the behavior is fine because we only care about the trivial case. I will update the comment accordingly.

1065

Will fix.

aadg updated this revision to Diff 56620.May 9 2016, 1:36 PM
aadg marked 3 inline comments as done.

Address David's comment.

majnemer accepted this revision.May 9 2016, 1:38 PM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 9 2016, 1:38 PM
aadg closed this revision.May 10 2016, 2:31 AM

Committed @ r269033.

Thanks David !