Nevermind. I misread the documentation. On Sat, Apr 30, 2011 at 8:12 PM, Thomas Jablin <tjablin at gmail.com> wrote:> Hi, > > Is it valid to query ScalarEvolution::getSCEVAtScope with a Value > which is an Instruction inside the provided Loop? If so, I believe > there is a bug in computeSCEVAtScope. Specifically: > > 04716 // If the scope is outside the addrec's loop, evaluate it by using the > 04717 // loop exit value of the addrec. > 04718 if (!AddRec->getLoop()->contains(L)) { > 04719 // To evaluate this recurrence, we need to know how many > times the AddRec > 04720 // loop iterates. Compute this now. > 04721 const SCEV *BackedgeTakenCount > getBackedgeTakenCount(AddRec->getLoop()); > 04722 if (BackedgeTakenCount == getCouldNotCompute()) return AddRec; > 04723 > 04724 // Then, evaluate the AddRec. > 04725 return AddRec->evaluateAtIteration(BackedgeTakenCount, *this); > 04726 } > > The guard checks that !AddRec->getLoop()->contains(L), but not > !L->contains(AddRec->getLoop()). > > Consequently, if getSCEVAtScope is called with GetElementPtrInst and a > Loop that contains it indirectly, the SCEV will be evaluated with > respect to the end of the inner Loop. For example: > > L1 for(i to N) > L2 for(j to N) > arrayidx = gep A, 0, j, i > > getSCEVAtScope(arrayIdx, L1) will evaluate j as N. > > If it is valid to call getSCEVAtScope with an outer loop, I believe > the guard should be: > 04718 if (!AddRec->getLoop()->contains(L) && > !L->contains(AddRec->getLoop())) { > > If it is not valid, an assertion might be helpful. > > Tom >