This is an archive of the discontinued LLVM Phabricator instance.

[SCEV][NFC] Remove TBB, FBB parameters from exit limit computations
ClosedPublic

Authored by mkazantsev on Mar 13 2018, 4:52 AM.

Details

Summary

Methods computeExitLimitFromCondCached and computeExitLimitFromCondImpl take
true and false branches as parameters and only use them for asserts and for identifying
whether true/false branch belongs to the loop (which can be done once earlier). This fact
complicates generalization of exit limit computation logic on guards because the guards
don't have blocks to which they go in case of failure explicitly.

The motivation of this patch is that currently this part of SCEV knows nothing about guards
and only works with explicit branches. As result, it fails to prove that a loop

for (i = 0; i < 100; i++)
  guard(i < 10);

exits after 10th iteration, while in the equivalent example

for (i = 0; i < 100; i++)
  if (i >= 10) break;

SCEV easily proves this fact. We are going to change it in near future, and this is why
we need to make these methods operate on more abstract level.

This patch refactors this code to get rid of these parameters as meaningless and prepare
ground for teaching these methods to work with guards as well as they work with explicit
branching instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Mar 13 2018, 4:52 AM
fhahn accepted this revision.Mar 14 2018, 10:16 AM

LGTM, it seems like TBB and FBB were only used to determine whether the br instruction using ExitCond leaves the loop and determining this up front should be fine. But I am not extremely familiar with this code, so it might be good to wait a bit with committing to leave the other reviewers some time to raise additional concerns.

include/llvm/Analysis/ScalarEvolution.h
1436 ↗(On Diff #138151)

Maybe it is worth stating that ExitByCond will be true, if the conditional branch exits the loop?

lib/Analysis/ScalarEvolution.cpp
6946 ↗(On Diff #138151)

I think in some cases, it could be triggered with this change whereas no assertion was triggered before, e.g. ExitByCond being something not understood by computeExitLimitFromCondImpl. But I think it makes sense to only use it for branches with one successor in the loop and one outside.

This revision is now accepted and ready to land.Mar 14 2018, 10:16 AM
sanjoy added inline comments.Mar 14 2018, 11:18 AM
include/llvm/Analysis/ScalarEvolution.h
1436 ↗(On Diff #138151)

Not sure what this comment means anymore. Let's rename ExitByCond to ExitOnTrue.

lib/Analysis/ScalarEvolution.cpp
7019 ↗(On Diff #138151)

Let's keep this as bool EitherMayExit = !ExitOnTrue -- it is useful documentation.

mkazantsev added inline comments.Mar 14 2018, 9:17 PM
lib/Analysis/ScalarEvolution.cpp
6946 ↗(On Diff #138151)

This is what an exiting block is by definition.

mkazantsev marked an inline comment as done.Mar 15 2018, 2:38 AM
This revision was automatically updated to reflect the committed changes.