[llvm-dev] Unexpected crash in IndVarSimplify after injecting custom pass

Zhang via llvm-dev
2021-07-21T08:11:37Z

Hi:
Here in our downstream project we use a ModulePass to schedule our
TransformPasses through creating and executing Module/FunctionPassManagers
internally.
This "wrapper" pass is registered at
ExtensionPoint&nbsp;EP_ModuleOptimizerEarly.


However, when certain passes in our Pipeline are disabled, LLVM optimization
process crashes later in the pipeline with:


```
Assertion failed: (L-&gt;getLoopPreheader() &amp;&amp;
"Can't expand add recurrences without a loop preheader!"),
function getAddRecExprPHILiterally, file
LLVM/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp, line 1275
1.	<eof&gt; parser at end of file
2.	Per-module optimization passes
3.	Running pass 'CallGraph Pass Manager' on module 'src.cpp'.
4.	Running pass 'Loop Pass Manager' on function '@_ZNK8XXXX'
5.	Running pass 'Induction Variable Simplification' on basic block
'%for.body110'
0 &nbsp;clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0x0000000103df5535
llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;) + 37
1 &nbsp;clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0x0000000103df4765
llvm::sys::RunSignalHandlers() + 85
2 &nbsp;clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0x0000000103df4cc0
llvm::sys::CleanupOnSignal(unsigned long) + 208
3 &nbsp;clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0x0000000103d45f2a (anonymous
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 106
4 &nbsp;clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0x0000000103d460b7
CrashRecoverySignalHandler(int) + 135
5 &nbsp;libsystem_platform.dylib 0x00007fff2055ed7d _sigtramp + 29
6 &nbsp;libdyld.dylib &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;0x00007fff20534473 dyldGlobalLockRelease() + 0
7 &nbsp;libsystem_c.dylib &nbsp; &nbsp; &nbsp;
&nbsp;0x00007fff2046d720 abort + 120
8 &nbsp;libsystem_c.dylib &nbsp; &nbsp; &nbsp;
&nbsp;0x00007fff2046c9d6 err + 0
9 &nbsp;clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0x0000000106c11a83
llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*,
llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&amp;,
bool&amp;) (.cold.1) + 35
10 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb9643
llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*,
llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&amp;,
bool&amp;) + 4259
11 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb9bda
llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*) +
1066
12 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb5f23
llvm::SCEVExpander::expand(llvm::SCEV const*) + 1027
13 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb5aac
llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*) + 28
14 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103ebbc31
llvm::SCEVVisitor<llvm::SCEVExpander, llvm::Value*&gt;::visit(llvm::SCEV
const*) + 193
15 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb5f23
llvm::SCEVExpander::expand(llvm::SCEV const*) + 1027
16 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb5aac
llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*) + 28
17 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb8c49
llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*,
llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&amp;,
bool&amp;) + 1705
18 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb9bda
llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*) +
1066
19 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb5f23
llvm::SCEVExpander::expand(llvm::SCEV const*) + 1027
20 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb5aac
llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*) + 28
21 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103eb9794
llvm::SCEVExpander::expandCodeFor(llvm::SCEV const*, llvm::Type*,
llvm::Instruction*) + 148
22 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103b3969a (anonymous
namespace)::IndVarSimplify::run(llvm::Loop*) + 8522
23 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000103b463c7 (anonymous
namespace)::IndVarSimplifyLegacyPass::runOnLoop(llvm::Loop*,
llvm::LPPassManager&amp;) + 951
24 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001030ee209
llvm::LPPassManager::runOnFunction(llvm::Function&amp;) + 1513
25 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001036afe41
llvm::FPPassManager::runOnFunction(llvm::Function&amp;) + 1073
26 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000102ff4534 (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&amp;) + 1540
27 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001036b049f
llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) + 1103
28 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x000000010407b653
clang::EmitBackendOutput(clang::DiagnosticsEngine&amp;,
clang::HeaderSearchOptions const&amp;, clang::CodeGenOptions const&amp;,
clang::TargetOptions const&amp;, clang::LangOptions const&amp;,
llvm::DataLayout const&amp;, llvm::Module*, clang::BackendAction,
std::__1::unique_ptr<llvm::raw_pwrite_stream,
std::__1::default_delete<llvm::raw_pwrite_stream&gt; &gt;) + 15075
29 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001043456fb
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) + 1131
30 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000105438483
clang::ParseAST(clang::Sema&amp;, bool, bool) + 643
31 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x0000000104612d04
clang::FrontendAction::Execute() + 84
32 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001045b9f13
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) + 2179
33 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001046878fb
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1435
34 clang++ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;0x00000001025db371
cc1_main(llvm::ArrayRef<char const*&gt;, char const*, void*) + 2081



```


I added&nbsp;createVerifierPass() at the end of our "WrapperPass"
and the transformed IR passed the verification. I also didn't
overload&nbsp;getAnalysisUsage, which, if my understanding is correct,
invalidates all previous analysis including Loops Identified.


I'm kinda lost about why this issue exists and any hint would be much
appreciated




Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20210721/faee813b/attachment.html>