This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Use object size for globals to sharpen ranges.
ClosedPublic

Authored by fhahn on Apr 28 2023, 1:56 PM.

Details

Summary

The highest address the object can start is ObjSize bytes before the
end (unsigned max value). If this value is not a multiple of the
alignment, the last possible start value is the next lowest multiple
of the alignment. Note: The computations cannot overflow,
because if they would there's no possible start address for the
object.

At the moment, this is limited to GlobalVariables, because I could not
find a API similar to getObjectSize to also get the alignment of the
object. With such an API, this can be generalized to general addresses.

Diff Detail

Event Timeline

fhahn created this revision.Apr 28 2023, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2023, 1:56 PM
fhahn requested review of this revision.Apr 28 2023, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2023, 1:56 PM
fhahn updated this revision to Diff 518047.Apr 28 2023, 2:00 PM

Remove unnecessary changes in llvm/test/Analysis/ScalarEvolution/scev-expander-reuse-gep.ll.

nikic added inline comments.Apr 28 2023, 2:23 PM
llvm/lib/Analysis/ScalarEvolution.cpp
6793

Use the BitWidth variable?

6797

-=

6799

, RangeType

llvm/test/Analysis/ScalarEvolution/ptrtoint-global.ll
9

Is there a particular reason we need to test the range of add of ptrtoint rather than the ptrtoint itself?

fhahn updated this revision to Diff 518057.Apr 28 2023, 2:29 PM

Simplify code as suggested, thanks!

fhahn marked 4 inline comments as done.Apr 28 2023, 2:32 PM
fhahn added inline comments.
llvm/lib/Analysis/ScalarEvolution.cpp
6793

Simplified, thanks!

6797

updated, thanks!

6799

Added, thanks!

llvm/test/Analysis/ScalarEvolution/ptrtoint-global.ll
9

No particular reason, other than that was convenient to check with Alive2 and to make sure this leads to the expected results downstream of the range computations. But I can also update the tests to directly return the ptrtoint result.

nikic accepted this revision.Apr 29 2023, 1:00 PM

LGTM

llvm/lib/Analysis/ScalarEvolution.cpp
78

Why do we need the Loads header?

This revision is now accepted and ready to land.Apr 29 2023, 1:00 PM
This revision was landed with ongoing or failed builds.Apr 29 2023, 1:33 PM
This revision was automatically updated to reflect the committed changes.
fhahn marked 4 inline comments as done.