Skip to content

Commit 0394ae3

Browse files
committed
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.
1 parent d8b74d0 commit 0394ae3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
char a;
2+
char *b, *c;
3+
int d, e, f, g, h;
4+
int *i;
5+
6+
void
7+
foo (void)
8+
{
9+
unsigned p;
10+
d = i[0];
11+
e = i[1];
12+
f = i[2];
13+
g = i[3];
14+
p = d * b[0];
15+
p += f * c[h];
16+
p += e * b[h];
17+
p += g * c[h];
18+
a = (p + 8000) >> (__SIZEOF_INT__ * __CHAR_BIT__ / 2);
19+
}

gcc/tree-vect-slp.cc

+4
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,10 @@ vect_optimize_slp_pass::forward_cost (graph_edge *ud, unsigned int from_node_i,
50345034
cost.split (from_partition.out_degree);
50355035
cost.add_serial_cost (edge_cost);
50365036
}
5037+
else if (from_partition.layout == 0)
5038+
/* We must allow the source partition to have layout 0 as a fallback,
5039+
in case all other options turn out to be impossible. */
5040+
return cost;
50375041

50385042
/* Take the minimum of that cost and the cost that applies if
50395043
FROM_PARTITION instead switches to TO_LAYOUT_I. */

0 commit comments

Comments
 (0)