@@ -98,29 +98,22 @@ bool LoopRotate::runOnLoop(Loop *L, LPPassManager &LPM) {
98
98
99
99
// / Rotate loop LP. Return true if the loop is rotated.
100
100
bool LoopRotate::rotateLoop (Loop *L) {
101
- BasicBlock *OrigPreHeader = L->getLoopPreheader ();
102
- if (!OrigPreHeader) return false ;
103
-
104
- BasicBlock *OrigLatch = L->getLoopLatch ();
105
- if (!OrigLatch) return false ;
106
-
107
- BasicBlock *OrigHeader = L->getHeader ();
108
-
109
101
// If the loop has only one block then there is not much to rotate.
110
102
if (L->getBlocks ().size () == 1 )
111
103
return false ;
112
-
104
+
105
+ BasicBlock *OrigHeader = L->getHeader ();
106
+
107
+ BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator ());
108
+ if (BI == 0 || BI->isUnconditional ())
109
+ return false ;
110
+
113
111
// If the loop header is not one of the loop exiting blocks then
114
112
// either this loop is already rotated or it is not
115
113
// suitable for loop rotation transformations.
116
114
if (!L->isLoopExiting (OrigHeader))
117
115
return false ;
118
116
119
- BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator ());
120
- if (!BI)
121
- return false ;
122
- assert (BI->isConditional () && " Branch Instruction is not conditional" );
123
-
124
117
// Updating PHInodes in loops with multiple exits adds complexity.
125
118
// Keep it simple, and restrict loop rotation to loops with one exit only.
126
119
// In future, lift this restriction and support for multiple exits if
@@ -139,6 +132,9 @@ bool LoopRotate::rotateLoop(Loop *L) {
139
132
}
140
133
141
134
// Now, this loop is suitable for rotation.
135
+ BasicBlock *OrigPreHeader = L->getLoopPreheader ();
136
+ BasicBlock *OrigLatch = L->getLoopLatch ();
137
+ assert (OrigPreHeader && OrigLatch && " Loop not in canonical form?" );
142
138
143
139
// Anything ScalarEvolution may know about this loop or the PHI nodes
144
140
// in its header will soon be invalidated.
@@ -300,7 +296,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
300
296
// Also, since this original header only has one predecessor, zap its
301
297
// PHI nodes, which are now trivial.
302
298
FoldSingleEntryPHINodes (OrigHeader);
303
-
299
+
304
300
// TODO: We could just go ahead and merge OrigHeader into its predecessor
305
301
// at this point, if we don't mind updating dominator info.
306
302
0 commit comments