@@ -70,6 +70,7 @@ namespace {
70
70
void preserveCanonicalLoopForm (LPPassManager &LPM);
71
71
72
72
private:
73
+ LoopInfo *LI;
73
74
Loop *L;
74
75
BasicBlock *OrigHeader;
75
76
BasicBlock *OrigPreHeader;
@@ -89,21 +90,31 @@ INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
89
90
90
91
Pass *llvm::createLoopRotatePass() { return new LoopRotate (); }
91
92
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
+
92
102
// / Rotate Loop L as many times as possible. Return true if
93
103
// / the loop is rotated at least once.
94
104
bool LoopRotate::runOnLoop (Loop *Lp, LPPassManager &LPM) {
105
+ LI = &getAnalysis<LoopInfo>();
95
106
96
- bool RotatedOneLoop = false ;
97
107
initialize ();
98
108
LPM_Ptr = &LPM;
99
109
100
110
// One loop can be rotated multiple times.
111
+ bool MadeChange = false ;
101
112
while (rotateLoop (Lp,LPM)) {
102
- RotatedOneLoop = true ;
113
+ MadeChange = true ;
103
114
initialize ();
104
115
}
105
116
106
- return RotatedOneLoop ;
117
+ return MadeChange ;
107
118
}
108
119
109
120
// / Rotate loop LP. Return true if the loop is rotated.
@@ -213,7 +224,8 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
213
224
// With the operands remapped, see if the instruction constant folds or is
214
225
// otherwise simplifyable. This commonly occurs because the entry from PHI
215
226
// 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)) {
217
229
// If so, then delete the temporary instruction and stick the folded value
218
230
// in the map.
219
231
delete C;
@@ -322,14 +334,6 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
322
334
return true ;
323
335
}
324
336
325
- // / Initialize local data
326
- void LoopRotate::initialize () {
327
- L = NULL ;
328
- OrigHeader = NULL ;
329
- OrigPreHeader = NULL ;
330
- NewHeader = NULL ;
331
- Exit = NULL ;
332
- }
333
337
334
338
// / After loop rotation, loop pre-header has multiple sucessors.
335
339
// / Insert one forwarding basic block to ensure that loop pre-header
0 commit comments