This patch is to improve CGPassManager::RefreshCallGraph to remove an invalid call graph edge corrupted by Instruction Combiner, triggered an assert in CallGraphNode::addCalledFunction later.
With commit d8214db0868f228026fa6ab1d5ca6c76ab3b5ce0, llvm's Instruction Combiner now can turn an sqrtl into a llvm.fabs.f64, the call graph edge (to be more precise, one Entry in B's CalledFunctions list) originally representing call to sqrtl now becomes invalid: the instruction is the call instruction for llvm.fabs.f64 (done by Value:: replaceAllUsesWith(..)), and the call graph node is still sqrtl, note that intrinsic shouldn't be in call graph, and call graph node for sqrtl should be gone too.
The problem can only be reproduced if we meet the all following conditions:
- Compile the program with NDK sysroot, and program need to be complicate enough to invoke CGPassManager::RunAllPassesOnSCC.
- For program with function A and B, A calls B, B calls some other functions, B need to be compiled before A to reproduce the problem.
- While compiling function B, inlining is invoked and instruction combiner is able to turn a call to sqrtl into llvm.fabs.f64
- Inlining is invoked while compiling function A (a bigger inlining threshold is needed)
This problem can't be reproduced with llvm trunk, because it doesn't turn a sqrtl into llvm.fabs.f64, but I think it is a real problem.