This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Make use of non-null pointers for range calculation
ClosedPublic

Authored by nikic on Jun 23 2023, 5:14 AM.

Details

Summary

We know that certain pointers (e.g. non-extern-weak globals or allocas in default address space) are not null, in which case the lowest address they can be allocated at is their alignment.

This allows us to calculate better exit counts for loops that have an additional null check in the guarding condition (see @alloca_icmp_null_exit_count).

Diff Detail

Event Timeline

nikic created this revision.Jun 23 2023, 5:14 AM
nikic requested review of this revision.Jun 23 2023, 5:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2023, 5:14 AM
arichardson added inline comments.Jun 23 2023, 7:41 PM
llvm/test/Analysis/ScalarEvolution/alloca.ll
27

Not related to this patch but I wonder if we could add a way to treat address spaces other than zero as also having non null allocas. For example for the CHERI targets AS200 has almost exactly the same semantics as as0 (other than pointers having additional metadata) and these AS0 only optimizations result in worse codegen. Maybe the allocas can be null should be opt-in rather than the default?

nikic added inline comments.Jun 24 2023, 12:12 AM
llvm/test/Analysis/ScalarEvolution/alloca.ll
27

Sure -- you would have to add a new per-AS DataLayout property for this.

aeubanks accepted this revision.Jun 28 2023, 9:44 AM
aeubanks added a subscriber: aeubanks.

lgtm

This revision is now accepted and ready to land.Jun 28 2023, 9:44 AM
This revision was landed with ongoing or failed builds.Jun 29 2023, 12:09 AM
This revision was automatically updated to reflect the committed changes.