aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Vectorize
diff options
context:
space:
mode:
authorArnold Schwaighofer <aschwaighofer@apple.com>2013-11-01 23:28:54 +0000
committerArnold Schwaighofer <aschwaighofer@apple.com>2013-11-01 23:28:54 +0000
commitbc28e88a2861ab1183e138f19e92e5d862eaa8a6 (patch)
tree6a588de3aa8692f3c02ba4eb9ecef6379a10bc20 /lib/Transforms/Vectorize
parent31ed50c225c8de764c899e31ab4e25f242ce0b78 (diff)
downloadexternal_llvm-bc28e88a2861ab1183e138f19e92e5d862eaa8a6.zip
external_llvm-bc28e88a2861ab1183e138f19e92e5d862eaa8a6.tar.gz
external_llvm-bc28e88a2861ab1183e138f19e92e5d862eaa8a6.tar.bz2
LoopVectorizer: Move cse code into its own function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193895 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Vectorize')
-rw-r--r--lib/Transforms/Vectorize/LoopVectorize.cpp69
1 files changed, 37 insertions, 32 deletions
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp
index 7f77784..fe73cd9 100644
--- a/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2055,6 +2055,41 @@ Value *createMinMaxOp(IRBuilder<> &Builder,
return Select;
}
+///\brief Perform cse of induction variable instructions.
+static void cse(BasicBlock *BB) {
+ // Perform simple cse.
+ SmallPtrSet<Instruction*, 16> Visited;
+ SmallVector<Instruction*, 16> ToRemove;
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
+ Instruction *In = I;
+
+ if (!isa<InsertElementInst>(In) && !isa<ExtractElementInst>(In) &&
+ !isa<ShuffleVectorInst>(In) && !isa<GetElementPtrInst>(In))
+ continue;
+
+ // Check if we can replace this instruction with any of the
+ // visited instructions.
+ for (SmallPtrSet<Instruction*, 16>::iterator v = Visited.begin(),
+ ve = Visited.end(); v != ve; ++v) {
+ if (In->isIdenticalTo(*v)) {
+ In->replaceAllUsesWith(*v);
+ ToRemove.push_back(In);
+ In = 0;
+ break;
+ }
+ }
+ if (In)
+ Visited.insert(In);
+
+ }
+ // Erase all of the instructions that we RAUWed.
+ for (SmallVectorImpl<Instruction *>::iterator v = ToRemove.begin(),
+ ve = ToRemove.end(); v != ve; ++v) {
+ assert((*v)->getNumUses() == 0 && "Can't remove instructions with uses");
+ (*v)->eraseFromParent();
+ }
+}
+
void
InnerLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) {
//===------------------------------------------------===//
@@ -2275,38 +2310,8 @@ InnerLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) {
fixLCSSAPHIs();
- // Perform simple cse.
- SmallPtrSet<Instruction*, 16> Visited;
- SmallVector<Instruction*, 16> ToRemove;
- for (BasicBlock::iterator I = LoopVectorBody->begin(),
- E = LoopVectorBody->end(); I != E; ++I) {
- Instruction *In = I;
-
- if (!isa<InsertElementInst>(In) && !isa<ExtractElementInst>(In) &&
- !isa<ShuffleVectorInst>(In) && !isa<GetElementPtrInst>(In))
- continue;
-
- // Check if we can replace this instruction with any of the
- // visited instructions.
- for (SmallPtrSet<Instruction*, 16>::iterator v = Visited.begin(),
- ve = Visited.end(); v != ve; ++v) {
- if (In->isIdenticalTo(*v)) {
- In->replaceAllUsesWith(*v);
- ToRemove.push_back(In);
- In = 0;
- break;
- }
- }
- if (In)
- Visited.insert(In);
-
- }
- // Erase all of the instructions that we RAUWed.
- for (SmallVectorImpl<Instruction *>::iterator v = ToRemove.begin(),
- ve = ToRemove.end(); v != ve; ++v) {
- assert((*v)->getNumUses() == 0 && "Can't remove instructions with uses");
- (*v)->eraseFromParent();
- }
+ // Remove redundant induction instructions.
+ cse(LoopVectorBody);
}
void InnerLoopVectorizer::fixLCSSAPHIs() {