[wasm] Fix unrolling with dead nodes

Bug: v8:13352
Change-Id: I56446ca19c4af662f1d60e23f36b42e495f21ee6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3936143
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83588}
This commit is contained in:
Manos Koukoutos 2022-10-05 12:18:41 +02:00 committed by V8 LUCI CQ
parent c2792e5803
commit 9096367a64
3 changed files with 11 additions and 4 deletions

View File

@ -5,6 +5,7 @@
#include "src/compiler/loop-analysis.h"
#include "src/codegen/tick-counter.h"
#include "src/compiler/all-nodes.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/node-marker.h"
@ -551,7 +552,8 @@ LoopTree* LoopFinder::BuildLoopTree(Graph* graph, TickCounter* tick_counter,
#if V8_ENABLE_WEBASSEMBLY
// static
ZoneUnorderedSet<Node*>* LoopFinder::FindSmallInnermostLoopFromHeader(
Node* loop_header, Zone* zone, size_t max_size, bool calls_are_large) {
Node* loop_header, AllNodes& all_nodes, Zone* zone, size_t max_size,
bool calls_are_large) {
auto* visited = zone->New<ZoneUnorderedSet<Node*>>(zone);
std::vector<Node*> queue;
@ -655,6 +657,8 @@ ZoneUnorderedSet<Node*>* LoopFinder::FindSmallInnermostLoopFromHeader(
// The loop header is allowed to point outside the loop.
if (node == loop_header) continue;
if (!all_nodes.IsLive(node)) continue;
for (Edge edge : node->input_edges()) {
Node* input = edge.to();
if (NodeProperties::IsControlEdge(edge) && visited->count(input) == 0 &&

View File

@ -26,6 +26,7 @@ namespace compiler {
static const int kAssumedLoopEntryIndex = 0; // assume loops are entered here.
class LoopFinderImpl;
class AllNodes;
using NodeRange = base::iterator_range<Node**>;
@ -190,7 +191,8 @@ class V8_EXPORT_PRIVATE LoopFinder {
// calls to a set of wasm builtins,
// 3) a nested loop is found in the loop.
static ZoneUnorderedSet<Node*>* FindSmallInnermostLoopFromHeader(
Node* loop_header, Zone* zone, size_t max_size, bool calls_are_large);
Node* loop_header, AllNodes& all_nodes, Zone* zone, size_t max_size,
bool calls_are_large);
#endif
};

View File

@ -1708,7 +1708,7 @@ struct WasmLoopUnrollingPhase {
if (!all_nodes.IsReachable(loop_info.header)) continue;
ZoneUnorderedSet<Node*>* loop =
LoopFinder::FindSmallInnermostLoopFromHeader(
loop_info.header, temp_zone,
loop_info.header, all_nodes, temp_zone,
// Only discover the loop until its size is the maximum unrolled
// size for its depth.
maximum_unrollable_size(loop_info.nesting_depth), true);
@ -1727,11 +1727,12 @@ struct WasmLoopPeelingPhase {
void Run(PipelineData* data, Zone* temp_zone,
std::vector<compiler::WasmLoopInfo>* loop_infos) {
AllNodes all_nodes(temp_zone, data->graph());
for (WasmLoopInfo& loop_info : *loop_infos) {
if (loop_info.can_be_innermost) {
ZoneUnorderedSet<Node*>* loop =
LoopFinder::FindSmallInnermostLoopFromHeader(
loop_info.header, temp_zone,
loop_info.header, all_nodes, temp_zone,
v8_flags.wasm_loop_peeling_max_size, false);
if (loop == nullptr) continue;
PeelWasmLoop(loop_info.header, loop, data->graph(), data->common(),