This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Improve pointer offset computation for cases of same base
ClosedPublic

Authored by xur on Sep 24 2019, 2:55 PM.

Details

Summary

This patch improves the handling of pointer offset in GEP expressions where one argument is the base pointer.
isPointerOffset() is being used by memcpyopt where current code synthesizes consecutive 32 bytes stores to one store and two memset intrinsic calls.
With this patch, we convert the stores to one memset intrinsic.

Diff Detail

Event Timeline

xur created this revision.Sep 24 2019, 2:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2019, 2:55 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
gchatelet added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
5760

iteratively

5764

it will or we'll?

xur updated this revision to Diff 221796.Sep 25 2019, 9:55 AM

Fixed comments suggested by Guillaume.

looks fine to me, but please wait for evghenii@'s comment.

xur edited reviewers, added: eugenis; removed: evghenii.Oct 1 2019, 10:39 AM
xur added a reviewer: fhahn.Oct 1 2019, 10:46 AM
eugenis accepted this revision.Oct 1 2019, 10:57 AM

I think this can be easily generalized even more to handle the case when both Ptr1 and Ptr2 are GEPs of some common base - replace getOffsetFromBase with getOffsetAndBase, check that the bases are the same, return the difference between offsets.

But this is fine at it is, LGTM.

This revision is now accepted and ready to land.Oct 1 2019, 10:57 AM
xur added a comment.Oct 10 2019, 11:27 AM

I totally agree with what eugenis said.
I added his comments to a TODO comment.
I will commit this version and may address the TODO later.

This revision was automatically updated to reflect the committed changes.