aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-12-20 02:20:53 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-12-20 02:20:53 +0000
commit82366edcc72e06c4c94e7c1c74e35a6c74afbba2 (patch)
treebc876ab76340e372d9b87f28c6c2d675c9112da4 /lib/Transforms/Scalar/LoopStrengthReduce.cpp
parentbf0c5f3e151e3aca581f687e1f2f00ac1dc9591e (diff)
downloadexternal_llvm-82366edcc72e06c4c94e7c1c74e35a6c74afbba2.zip
external_llvm-82366edcc72e06c4c94e7c1c74e35a6c74afbba2.tar.gz
external_llvm-82366edcc72e06c4c94e7c1c74e35a6c74afbba2.tar.bz2
Clean up previous patch: PHI uses should not prevent iv reuse if all other uses are addresses. This trades a constant multiply for one fewer iv.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45251 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp51
1 files changed, 16 insertions, 35 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 83c4ede..2dafbd7 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -997,8 +997,11 @@ bool LoopStrengthReduce::ValidStride(bool HasBaseReg,
AccessTy = SI->getOperand(0)->getType();
else if (LoadInst *LI = dyn_cast<LoadInst>(UsersToProcess[i].Inst))
AccessTy = LI->getType();
- else if (PHINode *PN = dyn_cast<PHINode>(UsersToProcess[i].Inst))
- AccessTy = PN->getType();
+ else if (isa<PHINode>(UsersToProcess[i].Inst)) {
+ if (AllowPHIIVReuse)
+ continue;
+ return false;
+ }
TargetLowering::AddrMode AM;
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(UsersToProcess[i].Imm))
@@ -1126,34 +1129,6 @@ static bool isAddressUse(Instruction *Inst, Value *OperandVal) {
return isAddress;
}
-/// isAddressUsePHI - Returns if all uses of the specified PHI node are using
-/// the PHI node value as an address.
-static void isAddressUsePHI(Instruction *Inst,
- SmallPtrSet<Instruction*,16> &Processed,
- bool &Result) {
- if (!Result || !Processed.insert(Inst))
- return;
-
- for (Value::use_iterator UI = Inst->use_begin(), E = Inst->use_end();
- UI != E; ++UI) {
- Instruction *User = cast<Instruction>(*UI);
- if (isa<PHINode>(User) && !Processed.count(User)) {
- bool ThisResult = true;
- isAddressUsePHI(User, Processed, ThisResult);
- if (!ThisResult) {
- Result = false;
- return;
- }
- continue;
- }
-
- if (!isAddressUse(User, cast<Value>(Inst))) {
- Result = false;
- return;
- }
- }
-}
-
// CollectIVUsers - Transform our list of users and offsets to a bit more
// complex table. In this new vector, each 'BasedUser' contains 'Base' the base
// of the strided accessas well as the old information from Uses. We
@@ -1191,6 +1166,7 @@ SCEVHandle LoopStrengthReduce::CollectIVUsers(const SCEVHandle &Stride,
// instructions. If we can represent anything there, move it to the imm
// fields of the BasedUsers. We do this so that it increases the commonality
// of the remaining uses.
+ unsigned NumPHI = 0;
for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) {
// If the user is not in the current loop, this means it is using the exit
// value of the IV. Do not put anything in the base, make sure it's all in
@@ -1204,17 +1180,16 @@ SCEVHandle LoopStrengthReduce::CollectIVUsers(const SCEVHandle &Stride,
// Addressing modes can be folded into loads and stores. Be careful that
// the store is through the expression, not of the expression though.
- bool isPtrPHI = false;
+ bool isPHI = false;
bool isAddress = isAddressUse(UsersToProcess[i].Inst,
UsersToProcess[i].OperandValToReplace);
if (isa<PHINode>(UsersToProcess[i].Inst)) {
- SmallPtrSet<Instruction*,16> Processed;
- isPtrPHI = true;
- isAddressUsePHI(UsersToProcess[i].Inst, Processed, isPtrPHI);
+ isPHI = true;
+ ++NumPHI;
}
// If this use isn't an address, then not all uses are addresses.
- if (!isAddress && !(AllowPHIIVReuse && isPtrPHI))
+ if (!isAddress && !(AllowPHIIVReuse && isPHI))
AllUsesAreAddresses = false;
MoveImmediateValues(TLI, UsersToProcess[i].Inst, UsersToProcess[i].Base,
@@ -1222,6 +1197,12 @@ SCEVHandle LoopStrengthReduce::CollectIVUsers(const SCEVHandle &Stride,
}
}
+ // If one of the use if a PHI node and all other uses are addresses, still
+ // allow iv reuse. Essentially we are trading one constant multiplication
+ // for one fewer iv.
+ if (NumPHI > 1)
+ AllUsesAreAddresses = false;
+
return CommonExprs;
}