This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Support unsigned predicates in isKnownPredicateViaNoOverflow
ClosedPublic

Authored by mkazantsev on Sep 21 2020, 4:09 AM.

Details

Summary

SCEV should be able to prove facts like x <u x+1<nuw>.

Diff Detail

Event Timeline

mkazantsev created this revision.Sep 21 2020, 4:09 AM

What about swapped cases, like (X + C)<nuw> u<= X?

lebedev.ri accepted this revision.Sep 21 2020, 6:41 AM

What about swapped cases, like (X + C)<nuw> u<= X?

Disregard. We return true if the predicate is known-true, and false in all other cases.
Looks reasonable to me.

llvm/lib/Analysis/ScalarEvolution.cpp
9302–9303

It is unclear how much it matters in practice, but
i don't think C needs to be a constant,
which means that we only need to check that RHS is an NUW SCEVAddExpr, and that
any_of(AE->operands(), [L](SCEV*Op){ return Op == L; }).

9311

Likely even less real-world, but likewise, i'd think we want to check
that RHS is a NUW SCEVAddExpr, any_of(AE->operands(), [L](SCEV*Op){ return Op == L; }),
and that (AE - L) != 0.

This revision is now accepted and ready to land.Sep 21 2020, 6:41 AM
mkazantsev added inline comments.Sep 22 2020, 2:37 AM
llvm/lib/Analysis/ScalarEvolution.cpp
9302–9303

I think such cases are handled in different aux functions of isKnownViaNonRecursiveReasoning. This one is specifically for constant offset.

Reloaded with dedicated unit test to make it independent on underlying patches (the only dependency was test).