Issue 52853
Summary clang-13 performs inlining after mcount instrumentation
Labels new issue
Assignees
Reporter tmiasko
    In clang-13 inlining might follow the mcount instrumentation used by -pg.
The mcount relies on frame pointers to recover a call graph, so inlining after
inserting calls to mcount produces misleading end results.  In the example
below, g which is called only once is recorded as being called 1025 times:

```c
int f(int x) {
  return (x & (x << 1u)) == 0;
}

```

```c
#include <stdio.h>
int f(int);
int __attribute__ ((noinline)) g() {
  int c = 0;
  for (int i = 0; i < (1 << 10); ++i)
    c += f(i);
  return c;
}

int main() {
  printf("%d\n", g());
}

```

```console
$ clang-13 -g -pg -flto -O2 -c a.c
$ clang-13 -g -pg -flto -O2 -c b.c
$ clang-13 -g -pg -flto -O2 a.o b.o
$ ./a.out > /dev/null && gprof -b | grep -A2 calls
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
  0.00      0.00     0.00     1025     0.00     0.00  g
```

```console
$ clang-12 -g -pg -flto -O2 -c a.c
$ clang-12 -g -pg -flto -O2 -c b.c
$ clang-12 -g -pg -flto -O2 a.o b.o
$ ./a.out > /dev/null && gprof -b | grep -A2 calls
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
   0.00      0.00     0.00        1     0.00     0.00  g
```

This seems to be result of changes from https://reviews.llvm.org/D97608,
which moved PostInlineEntryExitInstrumentationPass out of TargetPassConfig::addIRPasses.

cc @aeubanks 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to