aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorMircea Trofin <mtrofin@google.com>2024-09-23 15:21:25 -0700
committerGitHub <noreply@github.com>2024-09-23 15:21:25 -0700
commit783bac7ffb8f0d58d7381d90fcaa082eb0be1c1d (patch)
tree93f998c44ffb7558c2f4f3c8057a9ffaa8c5514b /llvm/lib/Transforms/Utils/InlineFunction.cpp
parent0a5edb4de408ae0405f85c3e4c6da5233f185f63 (diff)
downloadllvm-783bac7ffb8f0d58d7381d90fcaa082eb0be1c1d.zip
llvm-783bac7ffb8f0d58d7381d90fcaa082eb0be1c1d.tar.gz
llvm-783bac7ffb8f0d58d7381d90fcaa082eb0be1c1d.tar.bz2
[ctx_prof] Handle `select` and its `step` instrumentation (#109185)
The `step` instrumentation shouldn't be treated, during use, like an `increment`. The latter is treated as a BB ID. The step isn't that, it's more of a type of value profiling. We need to distinguish between the 2 when really looking for BB IDs (==increments), and handle appropriately `step`s. In particular, we need to know when to elide them because `select`s may get elided by function cloning, if the condition of the select is statically known.
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 152b494..25a0155 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2223,7 +2223,21 @@ remapIndices(Function &Caller, BasicBlock *StartBB,
}
for (auto &I : llvm::make_early_inc_range(*BB)) {
if (auto *Inc = dyn_cast<InstrProfIncrementInst>(&I)) {
- if (Inc != BBID) {
+ if (isa<InstrProfIncrementInstStep>(Inc)) {
+ // Step instrumentation is used for select instructions. Inlining may
+ // have propagated a constant resulting in the condition of the select
+ // being resolved, case in which function cloning resolves the value
+ // of the select, and elides the select instruction. If that is the
+ // case, the step parameter of the instrumentation will reflect that.
+ // We can delete the instrumentation in that case.
+ if (isa<Constant>(Inc->getStep())) {
+ assert(!Inc->getNextNode() || !isa<SelectInst>(Inc->getNextNode()));
+ Inc->eraseFromParent();
+ } else {
+ assert(isa_and_nonnull<SelectInst>(Inc->getNextNode()));
+ RewriteInstrIfNeeded(*Inc);
+ }
+ } else if (Inc != BBID) {
// If we're here it means that the BB had more than 1 IDs, presumably
// some coming from the callee. We "made up our mind" to keep the
// first one (which may or may not have been originally the caller's).