[InstrProf] Fix promoter when using counter relocations
authorEllis Hoag <ellis.sparky.hoag@gmail.com>
Mon, 16 May 2022 17:36:20 +0000 (10:36 -0700)
committerEllis Hoag <ellis.sparky.hoag@gmail.com>
Mon, 16 May 2022 21:32:39 +0000 (14:32 -0700)
commit9a90ea1fdcd29f7245ec0bc1295ce96fc0ec2365
tree291c36490f1f6173d1348105e57da0bbd5f4a7c5
parent0b293bf0451cd695239867d8dac9b239ab601a70
[InstrProf] Fix promoter when using counter relocations

When using counter relocations, two instructions are emitted to compute
the address of the counter variable.

```
%BiasAdd = add i64 ptrtoint <__profc_>, <__llvm_profile_counter_bias>
%Addr = inttoptr i64 %BiasAdd to i64*
```

When promoting a counter, these instructions might not be available in
the block, so we need to copy these instructions.

This fixes https://github.com/llvm/llvm-project/issues/55125

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D125710
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Transforms/PGOProfile/counter_promo_with_bias.ll [new file with mode: 0644]