Infinite loop when adding a new analysis pass

I am trying to add an analysis pass as a FunctionPass, and let LICM
(LoopPass) depends upon it. So in LICM.cpp, I have the following:

    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<MyAnalysis>(); // Add this

char LICM::ID = 0;
INITIALIZE_PASS_BEGIN(LICM, "licm", "Loop Invariant Code Motion", false, false)
             // add this dependency
INITIALIZE_PASS_END(LICM, "licm", "Loop Invariant Code Motion", false, false)

Howerver, I got an infinite loop when trying

opt -O3 t.bc -o out.bc

Where t.bc is created using clang from
  int main() { return 0; }

What am I missing ?

All files are attacahed (include/Analysis/MyAnalysis.h,
lib/Analysis/MyAnanlysis.cpp, and diffs to the existing files).


MyAnalysis.cpp (158 Bytes)

MyAnalysis.h (451 Bytes)

myana.diff (3.07 KB)

I think I know what goes wrong. LICM acutally requires another
transformation : LoopSimplify, which does not preserve MyAnalysis. So
LICM first schedules MyAnalysis before running LICM, then schedule
LoopSimplify, but scheduling LoopSimplify causes MyAnalysis to be
removed because it is not preserved, And LICM keeps repeating this
schedule & remove, and thus infinite loop.

It's nice for LLVM to add mechanism to detect this kind of conflicting