This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Infer addrec nowrap flags while calculating ranges (WIP)
Needs ReviewPublic

Authored by nikic on Oct 28 2020, 1:29 PM.

Details

Summary

We can already calculate nowrap flags based on range information in proveNoWrapViaConstantRanges(). However, because this happens separately from the range calculation, we lose some information and produce less precise results. Moving the nowrap flag calculation into getRangeRef() allows us to retain full precision.

This is semantically ugly in that quality of nowrap flags depends on whether the range was calculated or not. Of course, this is nothing new, e.g. the code this replaces was adding nowrap flags only when an addrec was zexted/sexted.

Diff Detail

Event Timeline

nikic created this revision.Oct 28 2020, 1:29 PM
Herald added a project: Restricted Project. · View Herald Transcript
nikic requested review of this revision.Oct 28 2020, 1:29 PM
nikic updated this revision to Diff 301456.Oct 28 2020, 3:44 PM
nikic edited the summary of this revision. (Show Details)

Rebase. It looks like this patch had some functional overlap with https://github.com/llvm/llvm-project/commit/160a453138429f5e389de877fd02db2bb7dc6765, in that it was able to prove 4 out of 5 conditions without the additional logic added there.

@mkazantsev Before I deal with the remaining tests, any thoughts on the general idea here?

bollu removed a reviewer: bollu.Jan 15 2021, 8:43 PM
bollu removed a reviewer: bollu.Jan 15 2021, 8:45 PM
mkazantsev added inline comments.Jan 18 2021, 2:16 AM
llvm/lib/Analysis/ScalarEvolution.cpp
5701

I understand why the union will retain nsw in this case, but what about nuw? See example in my comment below.

5893

If first range is [-5; -1]<nuw><nsw> and second range is [1; 5]<nuw><nsw>, we'll end up with smth like [-5; 5]<nuw><nsw>. This doesn't feel right.

Reping, rebase?

nikic updated this revision to Diff 332180.Mar 21 2021, 2:39 PM

Rebase. Still need to address review and some test failures though.

mkazantsev resigned from this revision.Jul 8 2021, 11:40 PM

This has been a WIP patch w/o author updates for a good while. Please add me back when it'll move somewhere.