From 0ad2c7ace8abe46a86724a0ad939515d23d5c402 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 13 Aug 2010 21:24:58 +0000 Subject: [PATCH] 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 --- lib/Analysis/ScalarEvolution.cpp | 44 +++++++++++++++++++------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 2cf8fff32b0..a9679d91180 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -545,40 +545,45 @@ namespace { // not as complete as it could be. if (const SCEVUnknown *LU = dyn_cast(LHS)) { const SCEVUnknown *RU = cast(RHS); + const Value *LV = LU->getValue(), *RV = RU->getValue(); // Order pointer values after integer values. This helps SCEVExpander // form GEPs. - bool LIsPointer = LU->getType()->isPointerTy(), - RIsPointer = RU->getType()->isPointerTy(); + bool LIsPointer = LV->getType()->isPointerTy(), + RIsPointer = RV->getType()->isPointerTy(); if (LIsPointer != RIsPointer) return RIsPointer; // Compare getValueID values. - unsigned LID = LU->getValue()->getValueID(), - RID = RU->getValue()->getValueID(); + unsigned LID = LV->getValueID(), + RID = RV->getValueID(); if (LID != RID) return LID < RID; // Sort arguments by their position. - if (const Argument *LA = dyn_cast(LU->getValue())) { - const Argument *RA = cast(RU->getValue()); + if (const Argument *LA = dyn_cast(LV)) { + const Argument *RA = cast(RV); return LA->getArgNo() < RA->getArgNo(); } // For instructions, compare their loop depth, and their opcode. // This is pretty loose. - if (const Instruction *LV = dyn_cast(LU->getValue())) { - const Instruction *RV = cast(RU->getValue()); + if (const Instruction *LInst = dyn_cast(LV)) { + const Instruction *RInst = cast(RV); // Compare loop depths. - unsigned LDepth = LI->getLoopDepth(LV->getParent()), - RDepth = LI->getLoopDepth(RV->getParent()); - if (LDepth != RDepth) - return LDepth < RDepth; + const BasicBlock *LParent = LInst->getParent(), + *RParent = RInst->getParent(); + if (LParent != RParent) { + unsigned LDepth = LI->getLoopDepth(LParent), + RDepth = LI->getLoopDepth(RParent); + if (LDepth != RDepth) + return LDepth < RDepth; + } // Compare the number of operands. - unsigned LNumOps = LV->getNumOperands(), - RNumOps = RV->getNumOperands(); + unsigned LNumOps = LInst->getNumOperands(), + RNumOps = RInst->getNumOperands(); if (LNumOps != RNumOps) return LNumOps < RNumOps; } @@ -600,10 +605,13 @@ namespace { // Compare addrec loop depths. if (const SCEVAddRecExpr *LA = dyn_cast(LHS)) { const SCEVAddRecExpr *RA = cast(RHS); - unsigned LDepth = LA->getLoop()->getLoopDepth(), - RDepth = RA->getLoop()->getLoopDepth(); - if (LDepth != RDepth) - return LDepth < RDepth; + const Loop *LLoop = LA->getLoop(), *RLoop = RA->getLoop(); + if (LLoop != RLoop) { + unsigned LDepth = LLoop->getLoopDepth(), + RDepth = RLoop->getLoopDepth(); + if (LDepth != RDepth) + return LDepth < RDepth; + } } // Lexicographically compare n-ary expressions.