How to write optimizer loop

I've written an optimization loop, with the following form:

     PassManager lpm;

     lpm.add(createLoopDeletionPass());
     lpm.add(createSCCPPass());
     lpm.add(createAggressiveDCEPass());
     lpm.add(createGlobalOptimizerPass());
     lpm.add(createGlobalDCEPass());
     lpm.add(createDeadStoreEliminationPass());
     lpm.add(createLoopDeletionPass());
     lpm.add(createInstructionCombiningPass());
     lpm.add(createCFGSimplificationPass());

     const int maxit = 100;
     int it = 0;
     bool changed = true;
     while (changed && it < maxit)
     {
         changed = lpm.run(*myModule);
         it++;
     }

Aside from the possibility that the optimizations don't converge (handled by the "maxit" variable), this code is erroneous since the Loop Deletion pass incurs LCSSA and loop-simplify, which will likely always modify code that has been simplified via CFGSimplification.

Is there a recommended method to write an optimization loop that correctly detects when an iteration has made changes to the module? I'm now thinking that it will be necessary to compare the new and previous module, possibly with a hash function.

Also, how could I embed this loop into another PassManager so that it doesn't need to recompute stuff such as DominatorTree?

Andrew