mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-22 03:39:03 +00:00
Make RewriteLoopExitValues far less nested by using continue in the loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a9569f10de
commit
c9838f25d5
@ -322,16 +322,26 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
||||
|
||||
std::set<Instruction*> InstructionsToDelete;
|
||||
|
||||
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
|
||||
if (LI->getLoopFor(L->getBlocks()[i]) == L) { // Not in a subloop...
|
||||
// Loop over all of the integer-valued instructions in this loop, but that are
|
||||
// not in a subloop.
|
||||
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i) {
|
||||
if (LI->getLoopFor(L->getBlocks()[i]) != L)
|
||||
continue; // The Block is in a subloop, skip it.
|
||||
BasicBlock *BB = L->getBlocks()[i];
|
||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
|
||||
if (I->getType()->isInteger()) { // Is an integer instruction
|
||||
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ) {
|
||||
Instruction *I = II++;
|
||||
|
||||
if (!I->getType()->isInteger())
|
||||
continue; // SCEV only supports integer expressions for now.
|
||||
|
||||
SCEVHandle SH = SE->getSCEV(I);
|
||||
if (SH->hasComputableLoopEvolution(L) || // Varies predictably
|
||||
HasConstantItCount) {
|
||||
if (!HasConstantItCount &&
|
||||
!SH->hasComputableLoopEvolution(L)) { // Varies predictably
|
||||
continue; // Cannot exit evolution for the loop value.
|
||||
}
|
||||
|
||||
// Find out if this predictably varying value is actually used
|
||||
// outside of the loop. "extra" as opposed to "intra".
|
||||
// outside of the loop. "Extra" is as opposed to "intra".
|
||||
std::vector<Instruction*> ExtraLoopUsers;
|
||||
for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
|
||||
UI != E; ++UI) {
|
||||
@ -352,17 +362,19 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!ExtraLoopUsers.empty()) {
|
||||
// If nothing outside the loop uses this value, don't rewrite it.
|
||||
if (ExtraLoopUsers.empty())
|
||||
continue;
|
||||
|
||||
// Okay, this instruction has a user outside of the current loop
|
||||
// and varies predictably in this loop. Evaluate the value it
|
||||
// contains when the loop exits, and insert code for it.
|
||||
// and varies predictably *inside* the loop. Evaluate the value it
|
||||
// contains when the loop exits if possible.
|
||||
SCEVHandle ExitValue = SE->getSCEVAtScope(I, L->getParentLoop());
|
||||
if (!isa<SCEVCouldNotCompute>(ExitValue)) {
|
||||
if (isa<SCEVCouldNotCompute>(ExitValue))
|
||||
continue;
|
||||
|
||||
Changed = true;
|
||||
++NumReplaced;
|
||||
// Remember the next instruction. The rewriter can move code
|
||||
// around in some cases.
|
||||
BasicBlock::iterator NextI = I; ++NextI;
|
||||
|
||||
Value *NewVal = Rewriter.expandCodeFor(ExitValue, InsertPt,
|
||||
I->getType());
|
||||
@ -382,7 +394,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
||||
Instruction* NewInstr = dyn_cast<Instruction>(NewVal);
|
||||
if (NewInstr && !isa<PHINode>(NewInstr) &&
|
||||
!L->contains(NewInstr->getParent()))
|
||||
for (unsigned j = 0; j < NewInstr->getNumOperands(); ++j){
|
||||
for (unsigned j = 0; j != NewInstr->getNumOperands(); ++j) {
|
||||
Instruction* PredI =
|
||||
dyn_cast<Instruction>(NewInstr->getOperand(j));
|
||||
if (PredI && L->contains(PredI->getParent())) {
|
||||
@ -406,15 +418,6 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
|
||||
// If this instruction is dead now, schedule it to be removed.
|
||||
if (I->use_empty())
|
||||
InstructionsToDelete.insert(I);
|
||||
I = NextI;
|
||||
continue; // Skip the ++I
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Next instruction. Continue instruction skips this.
|
||||
++I;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user