(1) The problem was originally reported on bugzilla, for more context please see: https://bugs.llvm.org/show_bug.cgi?id=33776
(2) Steps to reproduce the bug :
the test case queens.c is under directory: test-suite/SingleSource/Benchmarks/McGill
With the old pass manager, it is OK:
clang -fprofile-use -fsave-optimization-record -foptimization-record-file=pgo.yaml -O2 queens.c
But with the new pass manager, it emits fatal error:
clang -fprofile-use -fsave-optimization-record -foptimization-record-file=pgo.yaml -fexperimental-new-pass-manager -O2 queens.c
fatal error: error in backend: LICM: OptimizationRemarkEmitterAnalysis not cached at a higher level
(3) What have been done in this patch:
The other places which use getCachedResult(), they check the pointer is not NULL. So probably we just need to check the ORE pointer is not NULL as well (the crash happens at line 203 in lib/Transforms/Scalar/LICM.cpp). Especially there is a comment in the source code which says the fatal error emitting when ORE pointer is NULL should probably be optional rather than required.
With the proper checks in this patch, the crash goes away. However, this may not be the eventual solution, if people have other better solutions for this issue, we are very interested to hear them.