The LoopExtractor created new functions (by definition), which violates the restrictions of a LoopPass.
The correct implementation of this pass should be as a ModulePass.
Also revert r82990 implications on the LoopExtractor.
Fixes PR3082 and PR8929.
Could you add a comment on how NumLoops is used?