Commit 7c0e2003 authored by Mythri A's avatar Mythri A Committed by Commit Bot

Reset optimization markers on OSR if function has insufficient feedback

With lazy feedback allocation, we don't have feedback vectors when function
starts executing. If we mark the function on the first execution we would
be missing feedback for the initial part of the function and hence the
optimized code will not be useful.

This cl resets the optimization markers on OSR if the invocation count of
the function is less than 1. We may still do wasted optimizations if the
function is hot enough for optimizing but not for OSRing. In the long term
we may want to fix it differently. This fix covers the most common cases
in benchmarks.

Bug: chromium:987523
Change-Id: I1cfe82e6b9f95278b77c99b77d4b981828b5c0ab
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1739373
Commit-Queue: Mythri Alle <mythria@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63124}
parent 1fefb929
......@@ -266,7 +266,26 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
}
DCHECK(result->is_turbofanned());
if (!function->HasOptimizedCode()) {
if (function->feedback_vector().invocation_count() <= 1 &&
function->HasOptimizationMarker()) {
// With lazy feedback allocation we may not have feedback for the
// initial part of the function that was executed before we allocated a
// feedback vector. Reset any optimization markers for such functions.
//
// TODO(mythria): Instead of resetting the optimization marker here we
// should only mark a function for optimization if it has sufficient
// feedback. We cannot do this currently since we OSR only after we mark
// a function for optimization. We should instead change it to be based
// based on number of ticks.
DCHECK(!function->IsInOptimizationQueue());
function->ClearOptimizationMarker();
}
// TODO(mythria): Once we have OSR code cache we may not need to mark
// the function for non-concurrent compilation. We could arm the loops
// early so the second execution uses the already compiled OSR code and
// the optimization occurs concurrently off main thread.
if (!function->HasOptimizedCode() &&
function->feedback_vector().invocation_count() > 1) {
// If we're not already optimized, set to optimize non-concurrently on
// the next call, otherwise we'd run unoptimized once more and
// potentially compile for OSR again.
......
......@@ -15,4 +15,5 @@ function f() {
%PrepareFunctionForOptimization(f);
f();
f();
f();
assertOptimized(f);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment