<div><font>Hi:</font></div><div><font>Here in our downstream project we use a ModulePass to schedule our TransformPasses through creating and executing Module/FunctionPassManagers internally.</font></div><div><font>This "wrapper" pass is registered at ExtensionPoint EP_ModuleOptimizerEarly.</font></div><div><font><br></font></div><div><font>However, when certain passes in our Pipeline are disabled, LLVM optimization process crashes later in the pipeline with:</font></div><div><font><br></font></div><div><font>```</font></div><div><div>Assertion failed: (L->getLoopPreheader() && "Can't expand add recurrences without a loop preheader!"), function getAddRecExprPHILiterally, file LLVM/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp, line 1275</div><div>1.<span class="Apple-tab-span" style="white-space:pre">  </span><eof> parser at end of file</div><div>2.<span class="Apple-tab-span" style="white-space:pre">  </span>Per-module optimization passes</div><div>3.<span class="Apple-tab-span" style="white-space:pre">     </span>Running pass 'CallGraph Pass Manager' on module 'src.cpp'.</div><div>4.<span class="Apple-tab-span" style="white-space:pre"> </span>Running pass 'Loop Pass Manager' on function '@_ZNK8XXXX'</div><div>5.<span class="Apple-tab-span" style="white-space:pre">  </span>Running pass 'Induction Variable Simplification' on basic block '%for.body110'</div><div>0  clang++                  0x0000000103df5535 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37</div><div>1  clang++                  0x0000000103df4765 llvm::sys::RunSignalHandlers() + 85</div><div>2  clang++                  0x0000000103df4cc0 llvm::sys::CleanupOnSignal(unsigned long) + 208</div><div>3  clang++                  0x0000000103d45f2a (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 106</div><div>4  clang++                  0x0000000103d460b7 CrashRecoverySignalHandler(int) + 135</div><div>5  libsystem_platform.dylib 0x00007fff2055ed7d _sigtramp + 29</div><div>6  libdyld.dylib            0x00007fff20534473 dyldGlobalLockRelease() + 0</div><div>7  libsystem_c.dylib        0x00007fff2046d720 abort + 120</div><div>8  libsystem_c.dylib        0x00007fff2046c9d6 err + 0</div><div>9  clang++                  0x0000000106c11a83 llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*, llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&, bool&) (.cold.1) + 35</div><div>10 clang++                  0x0000000103eb9643 llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*, llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&, bool&) + 4259</div><div>11 clang++                  0x0000000103eb9bda llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*) + 1066</div><div>12 clang++                  0x0000000103eb5f23 llvm::SCEVExpander::expand(llvm::SCEV const*) + 1027</div><div>13 clang++                  0x0000000103eb5aac llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*) + 28</div><div>14 clang++                  0x0000000103ebbc31 llvm::SCEVVisitor<llvm::SCEVExpander, llvm::Value*>::visit(llvm::SCEV const*) + 193</div><div>15 clang++                  0x0000000103eb5f23 llvm::SCEVExpander::expand(llvm::SCEV const*) + 1027</div><div>16 clang++                  0x0000000103eb5aac llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*) + 28</div><div>17 clang++                  0x0000000103eb8c49 llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*, llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&, bool&) + 1705</div><div>18 clang++                  0x0000000103eb9bda llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*) + 1066</div><div>19 clang++                  0x0000000103eb5f23 llvm::SCEVExpander::expand(llvm::SCEV const*) + 1027</div><div>20 clang++                  0x0000000103eb5aac llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*) + 28</div><div>21 clang++                  0x0000000103eb9794 llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*, llvm::Instruction*) + 148</div><div>22 clang++                  0x0000000103b3969a (anonymous namespace)::IndVarSimplify::run(llvm::Loop*) + 8522</div><div>23 clang++                  0x0000000103b463c7 (anonymous namespace)::IndVarSimplifyLegacyPass::runOnLoop(llvm::Loop*, llvm::LPPassManager&) + 951</div><div>24 clang++                  0x00000001030ee209 llvm::LPPassManager::runOnFunction(llvm::Function&) + 1513</div><div>25 clang++                  0x00000001036afe41 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1073</div><div>26 clang++                  0x0000000102ff4534 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) + 1540</div><div>27 clang++                  0x00000001036b049f llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1103</div><div>28 clang++                  0x000000010407b653 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream> >) + 15075</div><div>29 clang++                  0x00000001043456fb clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1131</div><div>30 clang++                  0x0000000105438483 clang::ParseAST(clang::Sema&, bool, bool) + 643</div><div>31 clang++                  0x0000000104612d04 clang::FrontendAction::Execute() + 84</div><div>32 clang++                  0x00000001045b9f13 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 2179</div><div>33 clang++                  0x00000001046878fb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1435</div><div>34 clang++                  0x00000001025db371 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2081</div><div><br></div></div><div><font>```</font></div><div><font><br></font></div><div><font>I added createVerifierPass() at the end of our "WrapperPass" and the transformed IR passed the verification. I also didn't overload getAnalysisUsage, which, if my understanding is correct, invalidates all previous analysis including Loops Identified.</font></div><div><font><br></font></div><div><font>I'm kinda lost about why this issue exists and any hint would be much appreciated</font></div><div><font><br></font></div><div><font><br></font></div><div>Zhang</div><div><includetail><!--<![endif]--></includetail></div>