Remove the temporary flag -disable-unroll-scev and dead code.

SCEV should now be used for trip count analysis, not LoopInfo.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145262 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Trick 2011-11-28 19:22:09 +00:00
parent f9b1cd0c7f
commit ed38f1ca2e
3 changed files with 7 additions and 144 deletions

View File

@ -23,7 +23,6 @@
// * whether or not a particular block branches out of the loop
// * the successor blocks of the loop
// * the loop depth
// * the trip count
// * etc...
//
//===----------------------------------------------------------------------===//
@ -587,37 +586,6 @@ public:
///
PHINode *getCanonicalInductionVariable() const;
/// getTripCount - Return a loop-invariant LLVM value indicating the number of
/// times the loop will be executed. Note that this means that the backedge
/// of the loop executes N-1 times. If the trip-count cannot be determined,
/// this returns null.
///
/// The IndVarSimplify pass transforms loops to have a form that this
/// function easily understands.
///
Value *getTripCount() const;
/// getSmallConstantTripCount - Returns the trip count of this loop as a
/// normal unsigned value, if possible. Returns 0 if the trip count is unknown
/// of not constant. Will also return 0 if the trip count is very large
/// (>= 2^32)
///
/// The IndVarSimplify pass transforms loops to have a form that this
/// function easily understands.
///
unsigned getSmallConstantTripCount() const;
/// getSmallConstantTripMultiple - Returns the largest constant divisor of the
/// trip count of this loop as a normal unsigned value, if possible. This
/// means that the actual trip count is always a multiple of the returned
/// value (don't forget the trip count could very well be zero as well!).
///
/// Returns 1 if the trip count is unknown or not guaranteed to be the
/// multiple of a constant (which is also the case if the trip count is simply
/// constant, use getSmallConstantTripCount for that case), Will also return 1
/// if the trip count is very large (>= 2^32).
unsigned getSmallConstantTripMultiple() const;
/// isLCSSAForm - Return true if the Loop is in LCSSA form
bool isLCSSAForm(DominatorTree &DT) const;

View File

@ -165,99 +165,6 @@ PHINode *Loop::getCanonicalInductionVariable() const {
return 0;
}
/// getTripCount - Return a loop-invariant LLVM value indicating the number of
/// times the loop will be executed. Note that this means that the backedge
/// of the loop executes N-1 times. If the trip-count cannot be determined,
/// this returns null.
///
/// The IndVarSimplify pass transforms loops to have a form that this
/// function easily understands.
///
Value *Loop::getTripCount() const {
// Canonical loops will end with a 'cmp ne I, V', where I is the incremented
// canonical induction variable and V is the trip count of the loop.
PHINode *IV = getCanonicalInductionVariable();
if (IV == 0 || IV->getNumIncomingValues() != 2) return 0;
bool P0InLoop = contains(IV->getIncomingBlock(0));
Value *Inc = IV->getIncomingValue(!P0InLoop);
BasicBlock *BackedgeBlock = IV->getIncomingBlock(!P0InLoop);
if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
if (BI->isConditional()) {
if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
if (ICI->getOperand(0) == Inc) {
if (BI->getSuccessor(0) == getHeader()) {
if (ICI->getPredicate() == ICmpInst::ICMP_NE)
return ICI->getOperand(1);
} else if (ICI->getPredicate() == ICmpInst::ICMP_EQ) {
return ICI->getOperand(1);
}
}
}
}
return 0;
}
/// getSmallConstantTripCount - Returns the trip count of this loop as a
/// normal unsigned value, if possible. Returns 0 if the trip count is unknown
/// or not constant. Will also return 0 if the trip count is very large
/// (>= 2^32)
unsigned Loop::getSmallConstantTripCount() const {
Value* TripCount = this->getTripCount();
if (TripCount) {
if (ConstantInt *TripCountC = dyn_cast<ConstantInt>(TripCount)) {
// Guard against huge trip counts.
if (TripCountC->getValue().getActiveBits() <= 32) {
return (unsigned)TripCountC->getZExtValue();
}
}
}
return 0;
}
/// getSmallConstantTripMultiple - Returns the largest constant divisor of the
/// trip count of this loop as a normal unsigned value, if possible. This
/// means that the actual trip count is always a multiple of the returned
/// value (don't forget the trip count could very well be zero as well!).
///
/// Returns 1 if the trip count is unknown or not guaranteed to be the
/// multiple of a constant (which is also the case if the trip count is simply
/// constant, use getSmallConstantTripCount for that case), Will also return 1
/// if the trip count is very large (>= 2^32).
unsigned Loop::getSmallConstantTripMultiple() const {
Value* TripCount = this->getTripCount();
// This will hold the ConstantInt result, if any
ConstantInt *Result = NULL;
if (TripCount) {
// See if the trip count is constant itself
Result = dyn_cast<ConstantInt>(TripCount);
// if not, see if it is a multiplication
if (!Result)
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TripCount)) {
switch (BO->getOpcode()) {
case BinaryOperator::Mul:
Result = dyn_cast<ConstantInt>(BO->getOperand(1));
break;
case BinaryOperator::Shl:
if (ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1)))
if (CI->getValue().getActiveBits() <= 5)
return 1u << CI->getZExtValue();
break;
default:
break;
}
}
}
// Guard against huge trip counts.
if (Result && Result->getValue().getActiveBits() <= 32) {
return (unsigned)Result->getZExtValue();
} else {
return 1;
}
}
/// isLCSSAForm - Return true if the Loop is in LCSSA form
bool Loop::isLCSSAForm(DominatorTree &DT) const {
// Sort the blocks vector so that we can use binary search to do quick

View File

@ -40,11 +40,6 @@ UnrollAllowPartial("unroll-allow-partial", cl::init(false), cl::Hidden,
cl::desc("Allows loops to be partially unrolled until "
"-unroll-threshold loop size is reached."));
// Temporary flag to be removed in 3.0
static cl::opt<bool>
NoSCEVUnroll("disable-unroll-scev", cl::init(false), cl::Hidden,
cl::desc("Use ScalarEvolution to analyze loop trip counts for unrolling"));
namespace {
class LoopUnroll : public LoopPass {
public:
@ -148,20 +143,13 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
// Find trip count and trip multiple if count is not available
unsigned TripCount = 0;
unsigned TripMultiple = 1;
if (!NoSCEVUnroll) {
// Find "latch trip count". UnrollLoop assumes that control cannot exit
// via the loop latch on any iteration prior to TripCount. The loop may exit
// early via an earlier branch.
BasicBlock *LatchBlock = L->getLoopLatch();
if (LatchBlock) {
TripCount = SE->getSmallConstantTripCount(L, LatchBlock);
TripMultiple = SE->getSmallConstantTripMultiple(L, LatchBlock);
}
}
else {
TripCount = L->getSmallConstantTripCount();
if (TripCount == 0)
TripMultiple = L->getSmallConstantTripMultiple();
// Find "latch trip count". UnrollLoop assumes that control cannot exit
// via the loop latch on any iteration prior to TripCount. The loop may exit
// early via an earlier branch.
BasicBlock *LatchBlock = L->getLoopLatch();
if (LatchBlock) {
TripCount = SE->getSmallConstantTripCount(L, LatchBlock);
TripMultiple = SE->getSmallConstantTripMultiple(L, LatchBlock);
}
// Automatically select an unroll count.
unsigned Count = CurrentCount;