summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InductionVariable.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-12-22 05:26:29 +0000
committerChris Lattner <sabre@nondot.org>2003-12-22 05:26:29 +0000
commita86c4a3a010cce8d2224f136453c04b559124bbc (patch)
treefaec267f80b6ae5d8a73da3781485993522fc8f6 /llvm/lib/Analysis/InductionVariable.cpp
parentf1277450abe79091812d084e6dcc6c9847cff348 (diff)
downloadbcm5719-llvm-a86c4a3a010cce8d2224f136453c04b559124bbc.tar.gz
bcm5719-llvm-a86c4a3a010cce8d2224f136453c04b559124bbc.zip
finegrainify namespacification
Implement indvar analysis of getelementptr and sub expressions llvm-svn: 10582
Diffstat (limited to 'llvm/lib/Analysis/InductionVariable.cpp')
-rw-r--r--llvm/lib/Analysis/InductionVariable.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/InductionVariable.cpp b/llvm/lib/Analysis/InductionVariable.cpp
index 6e9a209b7e1..8b805f8818e 100644
--- a/llvm/lib/Analysis/InductionVariable.cpp
+++ b/llvm/lib/Analysis/InductionVariable.cpp
@@ -27,16 +27,13 @@
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/Expressions.h"
#include "llvm/BasicBlock.h"
-#include "llvm/iPHINode.h"
-#include "llvm/iOperators.h"
-#include "llvm/iTerminators.h"
+#include "llvm/Instructions.h"
#include "llvm/Type.h"
#include "llvm/Constants.h"
#include "llvm/Support/CFG.h"
#include "llvm/Assembly/Writer.h"
#include "Support/Debug.h"
-
-namespace llvm {
+using namespace llvm;
static bool isLoopInvariant(const Value *V, const Loop *L) {
if (const Instruction *I = dyn_cast<Instruction>(V))
@@ -125,13 +122,33 @@ InductionVariable::InductionVariable(PHINode *P, LoopInfo *LoopInfo): End(0) {
if (V2 == Phi) { // referencing the PHI directly? Must have zero step
Step = Constant::getNullValue(Phi->getType());
} else if (BinaryOperator *I = dyn_cast<BinaryOperator>(V2)) {
- // TODO: This could be much better...
if (I->getOpcode() == Instruction::Add) {
if (I->getOperand(0) == Phi)
Step = I->getOperand(1);
else if (I->getOperand(1) == Phi)
Step = I->getOperand(0);
+ } else if (I->getOpcode() == Instruction::Sub &&
+ I->getOperand(0) == Phi) {
+ // If the incoming value is a constant, just form a constant negative
+ // step. Otherwise, negate the step outside of the loop and use it.
+ Value *V = I->getOperand(1);
+ Constant *Zero = Constant::getNullValue(V->getType());
+ if (Constant *CV = dyn_cast<Constant>(V))
+ Step = ConstantExpr::get(Instruction::Sub, Zero, CV);
+ else if (Instruction *I = dyn_cast<Instruction>(V)) {
+ Step = BinaryOperator::create(Instruction::Sub, Zero, V,
+ V->getName()+".neg", I->getNext());
+
+ } else {
+ Step = BinaryOperator::create(Instruction::Sub, Zero, V,
+ V->getName()+".neg",
+ Phi->getParent()->getParent()->begin()->begin());
+ }
}
+ } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V2)) {
+ if (GEP->getNumOperands() == 2 &&
+ GEP->getOperand(0) == Phi)
+ Step = GEP->getOperand(1);
}
if (Step == 0) { // Unrecognized step value...
@@ -301,5 +318,3 @@ void InductionVariable::print(std::ostream &o) const {
}
o << "\n";
}
-
-} // End llvm namespace
OpenPOWER on IntegriCloud