Skip to content

Commit 25ba40a

Browse files
committed
fix an issue duncan pointed out, which could cause loop rotate
to violate LCSSA form llvm-svn: 123066
1 parent b4ab257 commit 25ba40a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

llvm/lib/Transforms/Scalar/LoopRotation.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace {
7070
void preserveCanonicalLoopForm(LPPassManager &LPM);
7171

7272
private:
73+
LoopInfo *LI;
7374
Loop *L;
7475
BasicBlock *OrigHeader;
7576
BasicBlock *OrigPreHeader;
@@ -89,21 +90,31 @@ INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
8990

9091
Pass *llvm::createLoopRotatePass() { return new LoopRotate(); }
9192

93+
/// Initialize local data
94+
void LoopRotate::initialize() {
95+
L = NULL;
96+
OrigHeader = NULL;
97+
OrigPreHeader = NULL;
98+
NewHeader = NULL;
99+
Exit = NULL;
100+
}
101+
92102
/// Rotate Loop L as many times as possible. Return true if
93103
/// the loop is rotated at least once.
94104
bool LoopRotate::runOnLoop(Loop *Lp, LPPassManager &LPM) {
105+
LI = &getAnalysis<LoopInfo>();
95106

96-
bool RotatedOneLoop = false;
97107
initialize();
98108
LPM_Ptr = &LPM;
99109

100110
// One loop can be rotated multiple times.
111+
bool MadeChange = false;
101112
while (rotateLoop(Lp,LPM)) {
102-
RotatedOneLoop = true;
113+
MadeChange = true;
103114
initialize();
104115
}
105116

106-
return RotatedOneLoop;
117+
return MadeChange;
107118
}
108119

109120
/// Rotate loop LP. Return true if the loop is rotated.
@@ -213,7 +224,8 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
213224
// With the operands remapped, see if the instruction constant folds or is
214225
// otherwise simplifyable. This commonly occurs because the entry from PHI
215226
// nodes allows icmps and other instructions to fold.
216-
if (Value *V = SimplifyInstruction(C)) {
227+
Value *V = SimplifyInstruction(C);
228+
if (V && LI->replacementPreservesLCSSAForm(C, V)) {
217229
// If so, then delete the temporary instruction and stick the folded value
218230
// in the map.
219231
delete C;
@@ -322,14 +334,6 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
322334
return true;
323335
}
324336

325-
/// Initialize local data
326-
void LoopRotate::initialize() {
327-
L = NULL;
328-
OrigHeader = NULL;
329-
OrigPreHeader = NULL;
330-
NewHeader = NULL;
331-
Exit = NULL;
332-
}
333337

334338
/// After loop rotation, loop pre-header has multiple sucessors.
335339
/// Insert one forwarding basic block to ensure that loop pre-header

0 commit comments

Comments
 (0)