This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Make range check more precise
ClosedPublic

Authored by nikic on Oct 25 2021, 1:32 PM.

Details

Summary

Make the range check more precise by calculating the range of potentially accessed bytes for both accesses and checking whether their intersection is empty. In that case there can be no overlap between the accesses and the result is NoAlias.

This is more powerful than the previous approach, because it can deal with sign-wrapped ranges. In the test case the original range is [-1, INT_MAX] but becomes [0, INT_MIN] after applying the offset. This is a wrapping range, so getSignedMin/getSignedMax will treat it as a full range. However, the range excludes the elements [INT_MIN+1, -1], which is enough to prove NoAlias with an access at offset -1.

Diff Detail

Event Timeline

nikic created this revision.Oct 25 2021, 1:32 PM
nikic requested review of this revision.Oct 25 2021, 1:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2021, 1:32 PM
reames accepted this revision.Oct 26 2021, 11:19 AM

LGTM w/minor change suggested.

It looks like this structure might subsume some of the nearby checks as well, but that can be explored in a follow up.

llvm/lib/Analysis/BasicAliasAnalysis.cpp
1323

Rather than mutating an existing variable (which might be used later), I'd just use a new variable name here. e.g. AccessRange

This revision is now accepted and ready to land.Oct 26 2021, 11:19 AM
This revision was landed with ongoing or failed builds.Oct 27 2021, 3:41 AM
This revision was automatically updated to reflect the committed changes.