This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Replace checks with invariants if we cannot remove them
ClosedPublic

Authored by mkazantsev on Sep 29 2020, 9:55 PM.

Details

Summary

If we cannot prove that the check is trivially true, but can prove that it either
fails on the 1st iteration or never fails, we can replace it with first iteration check.

Diff Detail

Event Timeline

mkazantsev created this revision.Sep 29 2020, 9:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2020, 9:55 PM
mkazantsev planned changes to this revision.Sep 29 2020, 10:00 PM

Rebased, ready for review.

anna added a subscriber: anna.Nov 11 2020, 7:18 PM

Just a stylistic comment. You can have the InvariantCond as a struct with the fields: InvariantPred, InvariantLHS, InvariantRHS. I think this will make code more readable (for example, use the struct in ReplaceInvariantCond(ExitingBB, InvariantCond).

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

I maybe missing something. Where are we checking the "never fails in any iteration other than the first" ?

2437

Nit: ReplaceWithInvariantCond.

skatkov added inline comments.
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
2359

SE->isLoopInvariantExitCondDuringFirstIterations ?

mkazantsev added inline comments.Nov 11 2020, 9:22 PM
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
2359

Yes, inside of isLoopInvariantExitCondDuringFirstIterations we effectively check that comparison against IV may be replaced with comparison against start.

skatkov accepted this revision.Nov 11 2020, 9:28 PM

lgtm with Anna's nit + please do a rebase.

This revision is now accepted and ready to land.Nov 11 2020, 9:28 PM

(InvariantPred, InvariantLHS, InvariantRHS) API is used in SCEV. I will follow-up with refactoring changing it whevever it is used.