LICM ilist question.

I am using LLVM 2.6 and I have a question on the use of the BasicBlock::iterator to hoist loop invariant instructions to the loop preheader. When I process the instructions backward as shown in the following code, I got the following error right after the “hoist(I)” is done. Can anyone advise whether I am misusing BasicBlock::iterator?

/opt/llvms/src/llvm_26/ include/llvm/ADT/ilist.h:213: llvm::ilist_iterator& llvm::ilist_iterator::operator–() [with NodeTy = llvm::Instruction]: Assertion `NodePtr && “–'d off the beginning of an ilist!”’ failed.

LICM::HOistRegion(DomTreeNode *N)
{
assert(N != 0 && “Null dominator tree node?”);
BasicBlock *BB = N->getBlock();

for (BasicBlock::iterator II = BB->end(); II != BB->begin(); ) {

Instruction &I = *–II;

if (isLoopInvariantInst(I) && canSinkOrHoistInst(I) &&
isSafeToExecuteUnconditionally(I))
hoist(I);
}

}

– UGR