From 6c8e16aea85286721eb5689f9bcae09d36003cb1 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 27 May 2020 13:05:07 +0200 Subject: [PATCH] tree-optimization/95295 - fix sinking after path merging in new SM code This fixes a missed sinking of remat stores across unrelated stores after merging from different paths. 2020-05-27 Richard Biener PR tree-optimization/95295 * tree-ssa-loop-im.c (sm_seq_valid_bb): Fix sinking after merging stores from paths. * gcc.dg/torture/pr95295-3.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr95295-3.c | 16 ++++++++++++++++ gcc/tree-ssa-loop-im.c | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr95295-3.c diff --git a/gcc/testsuite/gcc.dg/torture/pr95295-3.c b/gcc/testsuite/gcc.dg/torture/pr95295-3.c new file mode 100644 index 00000000000..a506af9a63f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr95295-3.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +extern short var_15, var_20; +extern int var_18, var_21, var_23; +extern _Bool arr_2[]; +extern long arr_3[]; +void test() +{ + var_20 = 1; + for (int a = 0; a < 12; a += 2) + for (short b = 0; b < 8; b += 2) { + arr_2[b] = var_21 = var_18 ? var_15 : 0; + arr_3[b] = 8569; + } + var_23 = -1096835496; +} diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index b399bd0f729..d33f5335e2b 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2447,12 +2447,16 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef, unsigned id = first_edge_seq[i].first; seq.safe_push (first_edge_seq[i]); unsigned new_idx; - if (first_edge_seq[i].second == sm_ord + if ((first_edge_seq[i].second == sm_ord + || (first_edge_seq[i].second == sm_other + && first_edge_seq[i].from != NULL_TREE)) && !sm_seq_push_down (seq, seq.length () - 1, &new_idx)) { - bitmap_set_bit (refs_not_supported, id); + if (first_edge_seq[i].second == sm_ord) + bitmap_set_bit (refs_not_supported, id); /* Mark it sm_other. */ seq[new_idx].second = sm_other; + seq[new_idx].from = NULL_TREE; } } return 1; -- 2.30.2