summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopRotation.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-08 17:38:45 +0000
committerChris Lattner <sabre@nondot.org>2011-01-08 17:38:45 +0000
commit012ca949afc1e78c06dd49b8bc5f3b6f6c45458d (patch)
tree0ae438b939f33bb10052b67dc4251a26cd3b4cb4 /lib/Transforms/Scalar/LoopRotation.cpp
parentb434acb7beeccc34b07f30bae24664e420b1227a (diff)
downloadllvm-012ca949afc1e78c06dd49b8bc5f3b6f6c45458d.tar.gz
llvm-012ca949afc1e78c06dd49b8bc5f3b6f6c45458d.tar.bz2
llvm-012ca949afc1e78c06dd49b8bc5f3b6f6c45458d.tar.xz
fix an issue duncan pointed out, which could cause loop rotate
to violate LCSSA form git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123066 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopRotation.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopRotation.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp
index 2b00caeb4e..428e0f2a1f 100644
--- a/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/lib/Transforms/Scalar/LoopRotation.cpp
@@ -70,6 +70,7 @@ namespace {
void preserveCanonicalLoopForm(LPPassManager &LPM);
private:
+ LoopInfo *LI;
Loop *L;
BasicBlock *OrigHeader;
BasicBlock *OrigPreHeader;
@@ -89,21 +90,31 @@ INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
Pass *llvm::createLoopRotatePass() { return new LoopRotate(); }
+/// Initialize local data
+void LoopRotate::initialize() {
+ L = NULL;
+ OrigHeader = NULL;
+ OrigPreHeader = NULL;
+ NewHeader = NULL;
+ Exit = NULL;
+}
+
/// Rotate Loop L as many times as possible. Return true if
/// the loop is rotated at least once.
bool LoopRotate::runOnLoop(Loop *Lp, LPPassManager &LPM) {
+ LI = &getAnalysis<LoopInfo>();
- bool RotatedOneLoop = false;
initialize();
LPM_Ptr = &LPM;
// One loop can be rotated multiple times.
+ bool MadeChange = false;
while (rotateLoop(Lp,LPM)) {
- RotatedOneLoop = true;
+ MadeChange = true;
initialize();
}
- return RotatedOneLoop;
+ return MadeChange;
}
/// Rotate loop LP. Return true if the loop is rotated.
@@ -213,7 +224,8 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
// With the operands remapped, see if the instruction constant folds or is
// otherwise simplifyable. This commonly occurs because the entry from PHI
// nodes allows icmps and other instructions to fold.
- if (Value *V = SimplifyInstruction(C)) {
+ Value *V = SimplifyInstruction(C);
+ if (V && LI->replacementPreservesLCSSAForm(C, V)) {
// If so, then delete the temporary instruction and stick the folded value
// in the map.
delete C;
@@ -322,14 +334,6 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
return true;
}
-/// Initialize local data
-void LoopRotate::initialize() {
- L = NULL;
- OrigHeader = NULL;
- OrigPreHeader = NULL;
- NewHeader = NULL;
- Exit = NULL;
-}
/// After loop rotation, loop pre-header has multiple sucessors.
/// Insert one forwarding basic block to ensure that loop pre-header