This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Improve handling of multi-exit loops with known symbolic counts
ClosedPublic

Authored by mkazantsev on Jan 10 2023, 1:22 AM.

Details

Summary

This patch does two things, both related to support of multi-exit loops with
many exits that have known symbolic max exit count. They can theoretically
go independently, but I don't know how to write a test showing separate
impact.

Part 1: SkipLastIter can be set to true not when a particular exit has exit
count same as the whole loop (and therefore it must exit on the last iteration),
but when the aggregate of first few exits has umin same as whole loop exit count.
It means that it's not known which of them will exit exactly, but one of them will.

Part 2: when SkipLastIter is set, and exit count is umin(a, b, c), instead of
umin(a, b, c) - 1 use umin(a - 1, b - 1, c - 1). We don't care about overflows
here, but the further logic knows how to deal with umin by element, but the
SCEVAddExpr node will confuse it.

Diff Detail

Event Timeline

mkazantsev created this revision.Jan 10 2023, 1:22 AM
mkazantsev requested review of this revision.Jan 10 2023, 1:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 1:22 AM
nikic accepted this revision.Jan 10 2023, 2:48 AM

LGTM

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
1409

will likely won't

This revision is now accepted and ready to land.Jan 10 2023, 2:48 AM