From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1130) id 8AEA73858D34; Sat, 24 Feb 2024 11:58:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AEA73858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708775915; bh=Wq7uCbsjgAQozRRQJ+0mh5CtDX2KvY+WJ0Q8qpVgaj4=; h=From:To:Subject:Date:From; b=WQ4UNt+QksK0wy1uxRGAxNgA4PENMc39LeFGreasb8kTJ78AD4TCGLA2eJcly6/m/ YeDftNAaTkpR0ycIauS5//CyOZenEly5HwHXskuGEO7UvSRQsdFtC7B3tfyQw09Dqk AncnTMzCO9i6j4JwxzEGxBM47+C59UZUgQHw6OX8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Sandiford To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9165] vect: Tighten check for impossible SLP layouts [PR113205] X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/heads/trunk X-Git-Oldrev: d8b74d0b1ce0d5c31fad7ef6aa970a9b7fa4e7be X-Git-Newrev: 0394ae31e832c5303f3b4aad9c66710a30c097f0 Message-Id: <20240224115835.8AEA73858D34@sourceware.org> Date: Sat, 24 Feb 2024 11:58:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0394ae31e832c5303f3b4aad9c66710a30c097f0 commit r14-9165-g0394ae31e832c5303f3b4aad9c66710a30c097f0 Author: Richard Sandiford Date: Sat Feb 24 11:58:22 2024 +0000 vect: Tighten check for impossible SLP layouts [PR113205] During its forward pass, the SLP layout code tries to calculate the cost of a layout change on an incoming edge. This is taken as the minimum of two costs: one in which the source partition keeps its current layout (chosen earlier during the pass) and one in which the source partition switches to the new layout. The latter can sometimes be arranged by the backward pass. If only one of the costs is valid, the other cost was ignored. But the PR shows that this is not safe. If the source partition has layout 0 (the normal layout), we have to be prepared to handle the case in which that ends up being the only valid layout. Other code already accounts for this restriction, e.g. see the code starting with: /* Reject the layout if it would make layout 0 impossible for later partitions. This amounts to testing that the target supports reversing the layout change on edges to later partitions. gcc/ PR tree-optimization/113205 * tree-vect-slp.cc (vect_optimize_slp_pass::forward_cost): Reject the proposed layout if it does not allow a source partition with layout 2 to keep that layout. gcc/testsuite/ PR tree-optimization/113205 * gcc.dg/torture/pr113205.c: New test. Diff: --- gcc/testsuite/gcc.dg/torture/pr113205.c | 19 +++++++++++++++++++ gcc/tree-vect-slp.cc | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/gcc/testsuite/gcc.dg/torture/pr113205.c b/gcc/testsuite/gcc.dg/torture/pr113205.c new file mode 100644 index 000000000000..edfba7fcd0e7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr113205.c @@ -0,0 +1,19 @@ +char a; +char *b, *c; +int d, e, f, g, h; +int *i; + +void +foo (void) +{ + unsigned p; + d = i[0]; + e = i[1]; + f = i[2]; + g = i[3]; + p = d * b[0]; + p += f * c[h]; + p += e * b[h]; + p += g * c[h]; + a = (p + 8000) >> (__SIZEOF_INT__ * __CHAR_BIT__ / 2); +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 7cf9504398c9..895f4f7fb6be 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -5034,6 +5034,10 @@ vect_optimize_slp_pass::forward_cost (graph_edge *ud, unsigned int from_node_i, cost.split (from_partition.out_degree); cost.add_serial_cost (edge_cost); } + else if (from_partition.layout == 0) + /* We must allow the source partition to have layout 0 as a fallback, + in case all other options turn out to be impossible. */ + return cost; /* Take the minimum of that cost and the cost that applies if FROM_PARTITION instead switches to TO_LAYOUT_I. */