This is an archive of the discontinued LLVM Phabricator instance.

[ScalarEvolution] Refine computeMaxBECountForLT to be accurate in more cases.
ClosedPublic

Authored by efriedma on Jul 16 2021, 4:26 PM.

Details

Summary

Allow arbitrary strides, and make sure we return the correct result when the backedge-taken count is zero.

Inspired by D104140.

Diff Detail

Event Timeline

efriedma created this revision.Jul 16 2021, 4:26 PM
efriedma requested review of this revision.Jul 16 2021, 4:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2021, 4:26 PM
reames accepted this revision.Jul 19 2021, 2:54 PM

LGTM w/minor comments.

llvm/lib/Analysis/ScalarEvolution.cpp
11549

This is harmless, but I believe we've already established this by the time this method is invoked.

llvm/test/Analysis/ScalarEvolution/max-trip-count.ll
459

Can you add a test case for the i1 case? I had to write it out to convince myself of your comment and I think having the test in the change would help clarify for later readers.

This revision is now accepted and ready to land.Jul 19 2021, 2:54 PM
efriedma added inline comments.Jul 19 2021, 3:13 PM
llvm/lib/Analysis/ScalarEvolution.cpp
11549

At the moment, yes, but we're probably going to drop that check?

llvm/test/Analysis/ScalarEvolution/max-trip-count.ll
459

I can add the test, but it will just return CouldNotCompute without further changes; isKnownNonPositive(Stride) is true if Stride is an i1.

reames added inline comments.Jul 19 2021, 3:36 PM
llvm/lib/Analysis/ScalarEvolution.cpp
11549

I'd meant in the bit of code which forces stride to umin(1,stride) if we can't prove it non-zero in the caller.

llvm/test/Analysis/ScalarEvolution/max-trip-count.ll
459

Please add it anyways. :)

This revision was landed with ongoing or failed builds.Jul 19 2021, 3:43 PM
This revision was automatically updated to reflect the committed changes.