Passmanager assertion failure in PassAnalysisSupport.h
| Bugzilla Link | 27697 |
| Version | trunk |
| OS | Linux |
| CC | @chandlerc,@coffezhou,@uabjean,@mikaelholmen |
Extended Description
Running this command:
opt -globals-aa -loop-simplify -basiccg -aa -functionattrs /dev/null -o /dev/null -debug-pass=Details
Fails an assert like this:
-- 'Canonicalize natural loops' is not preserving 'CallGraph Construction' -- 'Canonicalize natural loops' is not preserving 'Function Pass Manager' Pass Arguments: -targetlibinfo -tti -assumption-cache-tracker -basiccg -globals-aa -domtree -loops -loop-simplify -basiccg -domtree -basicaa -aa -functionattrs -verify -write-bitcode Target Library Information Target Transform Information Assumption Cache Tracker ModulePass Manager CallGraph Construction Globals Alias Analysis FunctionPass Manager Dominator Tree Construction Natural Loop Information Canonicalize natural loops CallGraph Construction FunctionPass Manager Dominator Tree Construction Basic Alias Analysis (stateless AA impl) Function Alias Analysis Results Call Graph SCC Pass Manager Deduce function attributes FunctionPass Manager Module Verifier Bitcode Writer [2016-05-10 10:54:29.299387000] 0x5b7a9c0 Executing Pass 'CallGraph Construction' on Module '/dev/null'... [2016-05-10 10:54:29.299525000] 0x5b7a9c0 Executing Pass 'Globals Alias Analysis' on Module '/dev/null'... 0x5b7a270 Required Analyses: CallGraph Construction, Target Library Information [2016-05-10 10:54:29.299628000] 0x5b7a9c0 Executing Pass 'Function Pass Manager' on Module '/dev/null'... [2016-05-10 10:54:29.299666000] 0x5b7a9c0 Executing Pass 'CallGraph Construction' on Module '/dev/null'... [2016-05-10 10:54:29.299705000] 0x5b7a9c0 Executing Pass 'Function Pass Manager' on Module '/dev/null'... -- 'Function Pass Manager' is the last user of following pass instances. Free these instances [2016-05-10 10:54:29.299752000] 0x5b7a9c0 Freeing Pass 'CallGraph Construction' on Module '/dev/null'... [2016-05-10 10:54:29.299788000] 0x5b7a9c0 Executing Pass 'CallGraph Pass Manager' on Module '/dev/null'... 0x5b7e750 Required Analyses: CallGraph Construction opt: ../include/llvm/PassAnalysisSupport.h:236: AnalysisType &llvm::Pass::getAnalysisID(AnalysisID) const [AnalysisType = llvm::CallGraphWrapperPass]: Assertion `ResultPass && "getAnalysis() called on an analysis that was not " "'required' by pass!"' failed. 0 opt 0x00000000024d46ee llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46 1 opt 0x00000000024d4af9 2 opt 0x00000000024d3403 llvm::sys::RunSignalHandlers() + 131 3 opt 0x00000000024d4f3f 4 libpthread.so.0 0x00007fc450436340 5 libc.so.6 0x00007fc44f65ecc9 gsignal + 57 6 libc.so.6 0x00007fc44f6620d8 abort + 328 7 libc.so.6 0x00007fc44f657b86 8 libc.so.6 0x00007fc44f657c32 9 opt 0x000000000094e897 llvm::CallGraphWrapperPass& llvm::Pass::getAnalysisIDllvm::CallGraphWrapperPass(void const*) const + 199 10 opt 0x000000000094a416 llvm::CallGraphWrapperPass& llvm::Pass::getAnalysisllvm::CallGraphWrapperPass() const + 86 11 opt 0x00000000017ce3a6 12 opt 0x0000000001ebc6c1 13 opt 0x0000000001ebc1bb llvm::legacy::PassManagerImpl::run(llvm::Module&) + 347 14 opt 0x0000000001ebcc01 llvm::legacy::PassManager::run(llvm::Module&) + 33 15 opt 0x00000000009555fb main + 9147 16 libc.so.6 0x00007fc44f649ec5 __libc_start_main + 245 17 opt 0x000000000092ad98 Stack dump: 0. Program arguments: build-master/bin/opt -globals-aa -loop-simplify -basiccg -aa -functionattrs /dev/null -o /dev/null -debug-pass=Details
-
Running pass 'CallGraph Pass Manager' on module '/dev/null'.
Aborted
The current trunk version of LLVM still has this bug. $cat small.c void main() {}
$clang -v clang version 12.0.0 (https://github.com/llvm/llvm-project.git 65f6810d3a4b0ef1fdaad49e808459fbd133bb20) Target: x86_64-unknown-linux-gnu Thread model: posix
$clang -O3 -c -emit-llvm -femit-all-decls -mllvm -disable-llvm-optzns small.c
$opt -memoryssa -loop-reduce -early-cse-memssa -loop-load-elim small.bc -o small-opt.bc
opt: /home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/llvm/include/llvm/PassAnalysisSupport.h:239: AnalysisType& llvm::Pass::getAnalysisID(llvm::AnalysisID) const [with AnalysisType = llvm::AAResultsWrapperPass; llvm::AnalysisID = const void*]: Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump: 0. Program arguments: /home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt -memoryssa -loop-reduce -early-cse-memssa -loop-load-elim small.bc -o small-opt.bc
- Running pass 'Function Pass Manager' on module 'small.bc'.
- Running pass 'Loop Access Analysis' on function '@main' #0 0x000055fa9c63899c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b9999c) #1 0x000055fa9c636714 llvm::sys::RunSignalHandlers() (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b97714) #2 0x000055fa9c636863 SignalHandler(int) (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x2b97863) #3 0x00007f10074e18a0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0) #4 0x00007f1006193f47 raise /build/glibc-2ORdQG/glibc-2.27/sysdeps/unix/sysv/linux/raise.c:51:0 #5 0x00007f10061958b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0 #6 0x00007f100618542a __assert_fail_base /build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0 #7 0x00007f10061854a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2) #8 0x000055fa9b6c1779 llvm::LoopAccessLegacyAnalysis::runOnFunction(llvm::Function&) (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x1c22779) #9 0x000055fa9be79cc8 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23dacc8) #10 0x000055fa9be7a7c9 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23db7c9) #11 0x000055fa9be79546 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x23da546) #12 0x000055fa9a3014c9 main (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x8624c9) #13 0x00007f1006176b97 __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/libc-start.c:344:0 #14 0x000055fa9a3b07ca _start (/home/jack-zhou/Documents/llvm/llvm_truck/llvm-project/build/bin/opt+0x9117ca) Aborted (core dumped)
Hi,
I have a patch solving this pending since about a year ago. It solves at least three other registered bugs as well (that they are duplicates is not obvious from the symptoms). https://reviews.llvm.org/D21468
Was unable to get it approved for landing, but we have had it locally in our tree since.
We can easily fix this for now in the legacy PM by teaching all the function passes in the main pipeline to preserve the call graph analysis.
That said, this is likely to be at least a partial lie -- we're not realistically going to start refining the call graph in the legacy PM, the new PM does this but it is hard.
Chandler, any chance this can be fixed with the current infra or we need to wait for the new PM to be the default? FWIW, Zhendong found another case of this.
I investigated some and it gets kindof involved.
We have two CallGraph Constructions. The first one is used by "Globals Alias Analysis" and then not preserved by "Canonicalize natural loops". Then another CallGraph Construction is added, and then a later pass, "Basic Alias Analysis" which is requiring the "Global Alias Analysis".
At this point, the BAA (or rather its function pass manager) becomes the "last user" of the first callgraph transitively because of the use of GAA. This means the "last user" is beyond where the pass is not preserved and beyond the second call graph construction. The first call graph is thus removed at its late "last use" (when the second call graph have been executed already) and then the user of the second call graph cannot find it and crashes.
It seems there might be several weaknesses in the pass manager algorithm and it's not obvious how this should be fixed. There are several options - try to block transitive "last use" settings beyond non-preserved points, for instance. None of the options I can think of is trivial nor clean, so I think I'll leave it at that for now and move on to other things.
The new pass manager has been the default for a while and the legacy PM is deprecated. I am closing this issue, as it appears LegacyPM specific.