This patch exclude the direct calls to intrinsic functions that cannot
be an indirect-call target in the heuristics. The debug intrinsics make
the algorithm unstable for builds with and without "-g" option.
We found this issue in the CSPGO compilation where we only use -g
in the CSPGO optimized build (but not in CSPGO instrumentation build).
This issue leads to some profile hash-mismatch.
Here is an example to show the problem.
extern int (*goo)(); static int bar(int n, int n2, int n3) { return n*n + n2 + n3; } int foo(int sum) { int n = bar(2, 0, 0); if (n != 4) sum += goo(); sum += bar(sum, sum, sum); return sum; }
Compile with: clang -O2.
Without -g:
before CGSCC indirect_call=1 direct_call=2
after CGSCC round1: indirect_call=0 direct_call=0 ==> stopped
With -g:
before CGSCC indirect_call=1 direct_call=7
after CGSCC round1: indirect_call=0 direct_call=9 ==> run round2
after CGSCC round2: indirect_call=0 direct_call=9 ==> stopped
The above simple example generates the same IR with extra round of CGSCC
pass. But it's not hard to notice that they can easily leads to
different CodeGen in the real world program, not to mentioning the extra
compile time.
With this patch, -g will have the same behavior as without -g.
this comment needs to be updated. I think it makes sense that we don't support this behavior since at this point it's more a phase ordering issue, rather than wanting to rerun the entire pipeline
I also want to change the pipeline to run function-attrs after the function simplification pipeline rather than before it, so this test is a little less relevant