8266528: Optimize C2 VerifyIterativeGVN execution time

Reviewed-by: kvn, thartmann
This commit is contained in:
Hui Shi 2021-05-22 11:51:37 +00:00 committed by Jie Fu
parent 24623167ff
commit 4023646ed1
4 changed files with 35 additions and 24 deletions

View File

@ -2212,22 +2212,16 @@ void Node::verify_edges(Unique_Node_List &visited) {
}
// Verify all nodes if verify_depth is negative
void Node::verify(Node* n, int verify_depth) {
void Node::verify(int verify_depth, VectorSet& visited, Node_List& worklist) {
assert(verify_depth != 0, "depth should not be 0");
ResourceMark rm;
VectorSet old_space;
VectorSet new_space;
Node_List worklist;
worklist.push(n);
Compile* C = Compile::current();
uint last_index_on_current_depth = 0;
uint last_index_on_current_depth = worklist.size() - 1;
verify_depth--; // Visiting the first node on depth 1
// Only add nodes to worklist if verify_depth is negative (visit all nodes) or greater than 0
bool add_to_worklist = verify_depth != 0;
for (uint list_index = 0; list_index < worklist.size(); list_index++) {
n = worklist[list_index];
Node* n = worklist[list_index];
if (n->is_Con() && n->bottom_type() == Type::TOP) {
if (C->cached_top_node() == NULL) {
@ -2236,17 +2230,28 @@ void Node::verify(Node* n, int verify_depth) {
assert(C->cached_top_node() == n, "TOP node must be unique");
}
for (uint i = 0; i < n->len(); i++) {
Node* x = n->in(i);
uint in_len = n->len();
for (uint i = 0; i < in_len; i++) {
Node* x = n->_in[i];
if (!x || x->is_top()) {
continue;
}
// Verify my input has a def-use edge to me
// Count use-def edges from n to x
int cnt = 0;
for (uint j = 0; j < n->len(); j++) {
if (n->in(j) == x) {
int cnt = 1;
for (uint j = 0; j < i; j++) {
if (n->_in[j] == x) {
cnt++;
break;
}
}
if (cnt == 2) {
// x is already checked as n's previous input, skip its duplicated def-use count checking
continue;
}
for (uint j = i + 1; j < in_len; j++) {
if (n->_in[j] == x) {
cnt++;
}
}
@ -2260,11 +2265,7 @@ void Node::verify(Node* n, int verify_depth) {
}
assert(cnt == 0, "mismatched def-use edge counts");
// Contained in new_space or old_space?
VectorSet* v = C->node_arena()->contains(x) ? &new_space : &old_space;
// Check for visited in the proper space. Numberings are not unique
// across spaces so we need a separate VectorSet for each space.
if (add_to_worklist && !v->test_set(x->_idx)) {
if (add_to_worklist && !visited.test_set(x->_idx)) {
worklist.push(x);
}
}

View File

@ -1202,7 +1202,7 @@ public:
void collect_nodes_out_all_ctrl_boundary(GrowableArray<Node*> *ns) const;
void verify_edges(Unique_Node_List &visited); // Verify bi-directional edges
static void verify(Node* n, int verify_depth);
static void verify(int verify_depth, VectorSet& visited, Node_List& worklist);
// This call defines a class-unique string used to identify class instances
virtual const char *Name() const;

View File

@ -1021,11 +1021,17 @@ void PhaseIterGVN::shuffle_worklist() {
#ifndef PRODUCT
void PhaseIterGVN::verify_step(Node* n) {
if (VerifyIterativeGVN) {
ResourceMark rm;
VectorSet visited;
Node_List worklist;
_verify_window[_verify_counter % _verify_window_size] = n;
++_verify_counter;
if (C->unique() < 1000 || 0 == _verify_counter % (C->unique() < 10000 ? 10 : 100)) {
++_verify_full_passes;
Node::verify(C->root(), -1);
worklist.push(C->root());
Node::verify(-1, visited, worklist);
return;
}
for (int i = 0; i < _verify_window_size; i++) {
Node* n = _verify_window[i];
@ -1038,8 +1044,11 @@ void PhaseIterGVN::verify_step(Node* n) {
continue;
}
// Typical fanout is 1-2, so this call visits about 6 nodes.
Node::verify(n, 4);
if (!visited.test_set(n->_idx)) {
worklist.push(n);
}
}
Node::verify(4, visited, worklist);
}
}
@ -1238,7 +1247,7 @@ Node *PhaseIterGVN::transform_old(Node* n) {
// Remove 'n' from hash table in case it gets modified
_table.hash_delete(n);
if (VerifyIterativeGVN) {
assert(!_table.find_index(n->_idx), "found duplicate entry in table");
assert(!_table.find_index(n->_idx), "found duplicate entry in table");
}
// Apply the Ideal call in a loop until it no longer applies

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +24,7 @@
/*
* @test
*
* @requires vm.debug == true & vm.compiler2.enabled
* @run main/othervm -Xbatch -XX:-TieredCompilation
* -XX:+IgnoreUnrecognizedVMOptions -XX:+TraceIterativeGVN
* compiler.debug.TraceIterativeGVN