Various optimizations. Don't compare two loops' depths

when they are the same loop. Don't compare two instructions'
loop depths when they are in the same block.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111045 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2010-08-13 21:24:58 +00:00
parent fc412d85c4
commit 0ad2c7ace8

View File

@ -545,40 +545,45 @@ namespace {
// not as complete as it could be. // not as complete as it could be.
if (const SCEVUnknown *LU = dyn_cast<SCEVUnknown>(LHS)) { if (const SCEVUnknown *LU = dyn_cast<SCEVUnknown>(LHS)) {
const SCEVUnknown *RU = cast<SCEVUnknown>(RHS); const SCEVUnknown *RU = cast<SCEVUnknown>(RHS);
const Value *LV = LU->getValue(), *RV = RU->getValue();
// Order pointer values after integer values. This helps SCEVExpander // Order pointer values after integer values. This helps SCEVExpander
// form GEPs. // form GEPs.
bool LIsPointer = LU->getType()->isPointerTy(), bool LIsPointer = LV->getType()->isPointerTy(),
RIsPointer = RU->getType()->isPointerTy(); RIsPointer = RV->getType()->isPointerTy();
if (LIsPointer != RIsPointer) if (LIsPointer != RIsPointer)
return RIsPointer; return RIsPointer;
// Compare getValueID values. // Compare getValueID values.
unsigned LID = LU->getValue()->getValueID(), unsigned LID = LV->getValueID(),
RID = RU->getValue()->getValueID(); RID = RV->getValueID();
if (LID != RID) if (LID != RID)
return LID < RID; return LID < RID;
// Sort arguments by their position. // Sort arguments by their position.
if (const Argument *LA = dyn_cast<Argument>(LU->getValue())) { if (const Argument *LA = dyn_cast<Argument>(LV)) {
const Argument *RA = cast<Argument>(RU->getValue()); const Argument *RA = cast<Argument>(RV);
return LA->getArgNo() < RA->getArgNo(); return LA->getArgNo() < RA->getArgNo();
} }
// For instructions, compare their loop depth, and their opcode. // For instructions, compare their loop depth, and their opcode.
// This is pretty loose. // This is pretty loose.
if (const Instruction *LV = dyn_cast<Instruction>(LU->getValue())) { if (const Instruction *LInst = dyn_cast<Instruction>(LV)) {
const Instruction *RV = cast<Instruction>(RU->getValue()); const Instruction *RInst = cast<Instruction>(RV);
// Compare loop depths. // Compare loop depths.
unsigned LDepth = LI->getLoopDepth(LV->getParent()), const BasicBlock *LParent = LInst->getParent(),
RDepth = LI->getLoopDepth(RV->getParent()); *RParent = RInst->getParent();
if (LDepth != RDepth) if (LParent != RParent) {
return LDepth < RDepth; unsigned LDepth = LI->getLoopDepth(LParent),
RDepth = LI->getLoopDepth(RParent);
if (LDepth != RDepth)
return LDepth < RDepth;
}
// Compare the number of operands. // Compare the number of operands.
unsigned LNumOps = LV->getNumOperands(), unsigned LNumOps = LInst->getNumOperands(),
RNumOps = RV->getNumOperands(); RNumOps = RInst->getNumOperands();
if (LNumOps != RNumOps) if (LNumOps != RNumOps)
return LNumOps < RNumOps; return LNumOps < RNumOps;
} }
@ -600,10 +605,13 @@ namespace {
// Compare addrec loop depths. // Compare addrec loop depths.
if (const SCEVAddRecExpr *LA = dyn_cast<SCEVAddRecExpr>(LHS)) { if (const SCEVAddRecExpr *LA = dyn_cast<SCEVAddRecExpr>(LHS)) {
const SCEVAddRecExpr *RA = cast<SCEVAddRecExpr>(RHS); const SCEVAddRecExpr *RA = cast<SCEVAddRecExpr>(RHS);
unsigned LDepth = LA->getLoop()->getLoopDepth(), const Loop *LLoop = LA->getLoop(), *RLoop = RA->getLoop();
RDepth = RA->getLoop()->getLoopDepth(); if (LLoop != RLoop) {
if (LDepth != RDepth) unsigned LDepth = LLoop->getLoopDepth(),
return LDepth < RDepth; RDepth = RLoop->getLoopDepth();
if (LDepth != RDepth)
return LDepth < RDepth;
}
} }
// Lexicographically compare n-ary expressions. // Lexicographically compare n-ary expressions.