@@ -125,81 +125,6 @@ static bool hasLoopInvariantOperands(SILInstruction *I, SILLoop *L) {
125
125
});
126
126
}
127
127
128
- // / Check if an address does not depend on other values in a basic block.
129
- static SILInstruction *addressIndependent (SILValue Addr) {
130
- Addr = stripCasts (Addr);
131
- if (auto *SGAI = dyn_cast<GlobalAddrInst>(Addr))
132
- return SGAI;
133
- if (auto *SEAI = dyn_cast<StructElementAddrInst>(Addr))
134
- return addressIndependent (SEAI->getOperand ());
135
- return nullptr ;
136
- }
137
-
138
- // / Check if two addresses can potentially access the same memory.
139
- // / For now, return true when both can be traced to the same global variable.
140
- static bool addressCanPairUp (SILValue Addr1, SILValue Addr2) {
141
- SILInstruction *Origin1 = addressIndependent (Addr1);
142
- return Origin1 && Origin1 == addressIndependent (Addr2);
143
- }
144
-
145
- // / Move cond_fail down if it can potentially help register promotion later.
146
- static bool sinkCondFail (SILLoop *Loop) {
147
- // Only handle innermost loops for now.
148
- if (!Loop->getSubLoops ().empty ())
149
- return false ;
150
-
151
- bool Changed = false ;
152
- for (auto *BB : Loop->getBlocks ()) {
153
- // A list of CondFails that can be moved down.
154
- SmallVector<CondFailInst*, 4 > CFs;
155
- // A pair of load and store that are independent of the CondFails and
156
- // can potentially access the same memory.
157
- LoadInst *LIOfPair = nullptr ;
158
- bool foundPair = false ;
159
-
160
- for (auto &Inst : *BB) {
161
- if (foundPair) {
162
- // Move CFs to right before Inst.
163
- for (unsigned I = 0 , E = CFs.size (); I < E; I++) {
164
- DEBUG (llvm::dbgs () << " sinking cond_fail down " );
165
- DEBUG (CFs[I]->dump ());
166
- DEBUG (llvm::dbgs () << " before " );
167
- DEBUG (Inst.dump ());
168
- CFs[I]->moveBefore (&Inst);
169
- }
170
- Changed = true ;
171
-
172
- foundPair = false ;
173
- LIOfPair = nullptr ;
174
- }
175
-
176
- if (auto CF = dyn_cast<CondFailInst>(&Inst)) {
177
- CFs.push_back (CF);
178
- } else if (auto LI = dyn_cast<LoadInst>(&Inst)) {
179
- if (addressIndependent (LI->getOperand ())) {
180
- LIOfPair = LI;
181
- } else {
182
- CFs.clear ();
183
- LIOfPair = nullptr ;
184
- }
185
- } else if (auto SI = dyn_cast<StoreInst>(&Inst)) {
186
- if (addressIndependent (SI->getDest ())) {
187
- if (LIOfPair &&
188
- addressCanPairUp (SI->getDest (), LIOfPair->getOperand ()))
189
- foundPair = true ;
190
- } else {
191
- CFs.clear ();
192
- LIOfPair = nullptr ;
193
- }
194
- } else if (Inst.mayHaveSideEffects ()) {
195
- CFs.clear ();
196
- LIOfPair = nullptr ;
197
- }
198
- }
199
- }
200
- return Changed;
201
- }
202
-
203
128
// / Checks if \p Inst has no side effects which prevent hoisting.
204
129
// / The \a SafeReads set contain instructions which we already proved to have
205
130
// / no such side effects.
@@ -517,7 +442,6 @@ void LoopTreeOptimization::analyzeCurrentLoop(
517
442
518
443
void LoopTreeOptimization::optimizeLoop (SILLoop *CurrentLoop,
519
444
ReadSet &SafeReads) {
520
- Changed |= sinkCondFail (CurrentLoop);
521
445
Changed |= hoistInstructions (CurrentLoop, DomTree, SafeReads,
522
446
RunsOnHighLevelSil);
523
447
Changed |= sinkFixLifetime (CurrentLoop, DomTree, LoopInfo);
0 commit comments