From 4acca1c0635dfa43cd8c4bfe2b22e17909fc23a3 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 25 May 2020 10:09:44 +0200 Subject: [PATCH] tree-optimization/95295 - fix wrong-code with SM We failed to compare the rematerialized store values when merging paths after walking PHIs. 2020-05-25 Richard Biener PR tree-optimization/95295 * tree-ssa-loop-im.c (sm_seq_valid_bb): Compare remat stores RHSes and drop to full sm_other if they are not equal. * gcc.dg/torture/pr95295-1.c: New testcase. * gcc.dg/torture/pr95295-2.c: Likewise. * gcc.dg/torture/pr95283.c: Likewise. --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gcc.dg/torture/pr95283.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr95295-1.c | 15 +++++++++++++++ gcc/testsuite/gcc.dg/torture/pr95295-2.c | 14 ++++++++++++++ gcc/tree-ssa-loop-im.c | 8 ++++++++ 6 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr95283.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr95295-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr95295-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e037dabe49..150dc096c7a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-05-25 Richard Biener + + PR tree-optimization/95295 + * tree-ssa-loop-im.c (sm_seq_valid_bb): Compare remat stores + RHSes and drop to full sm_other if they are not equal. + 2020-05-25 Richard Biener PR tree-optimization/95271 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abe0f32be3e..cba153f166e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2020-05-25 Richard Biener + + PR tree-optimization/95295 + * gcc.dg/torture/pr95295-1.c: New testcase. + * gcc.dg/torture/pr95295-2.c: Likewise. + * gcc.dg/torture/pr95283.c: Likewise. + 2020-05-25 Richard Biener PR tree-optimization/95271 diff --git a/gcc/testsuite/gcc.dg/torture/pr95283.c b/gcc/testsuite/gcc.dg/torture/pr95283.c new file mode 100644 index 00000000000..950d3b07ead --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr95283.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ + +short c; +_Bool d; +unsigned e, f; +char g, h; +extern _Bool i[]; +void j() +{ + for (char a = 0; a < 100; a++) + for (char b = 0; b < 20; b += 2) + { + if (e) + d = f = 0; + else + g = i[8] = 0; + h = c; + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr95295-1.c b/gcc/testsuite/gcc.dg/torture/pr95295-1.c new file mode 100644 index 00000000000..76a19f3d17b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr95295-1.c @@ -0,0 +1,15 @@ +/* { dg-do run } */ +/* { dg-additional-sources "pr95295-2.c" } */ + +extern int var_4, a; +extern unsigned var_9; +extern short arr_272[]; +void test() +{ + for (int b = 0; b < 9; b++) + for (int c = 0; c < 9; c += 4) + { + arr_272[c] = var_9 ? var_4 : 0; + a = 0; + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr95295-2.c b/gcc/testsuite/gcc.dg/torture/pr95295-2.c new file mode 100644 index 00000000000..80caeb8740d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr95295-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ + +int a; +int var_4 = 1; +unsigned var_9 = 8; +short arr_272[20]; +void test(); +int main() +{ + test(); + if (arr_272[4] != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index fcca099355a..b399bd0f729 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2402,6 +2402,7 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef, if (edge_seq[i].second == sm_ord) bitmap_set_bit (refs_not_supported, edge_seq[i].first); first_edge_seq[i].second = sm_other; + first_edge_seq[i].from = NULL_TREE; } /* sm_other prevails. */ else if (first_edge_seq[i].second != edge_seq[i].second) @@ -2410,7 +2411,14 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef, gcc_assert (bitmap_bit_p (refs_not_supported, first_edge_seq[i].first)); first_edge_seq[i].second = sm_other; + first_edge_seq[i].from = NULL_TREE; } + else if (first_edge_seq[i].second == sm_other + && first_edge_seq[i].from != NULL_TREE + && (edge_seq[i].from == NULL_TREE + || !operand_equal_p (first_edge_seq[i].from, + edge_seq[i].from, 0))) + first_edge_seq[i].from = NULL_TREE; } /* Any excess elements become sm_other since they are now coonditionally executed. */