From 7c592aad23c22b9f888837020cd0a7475d8f3938 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 22 May 2020 09:03:40 +0200 Subject: tree-optimization/95268 - fix commoning of clobbers This fixes handling of clobbers when commoning stores. 2020-05-22 Richard Biener PR tree-optimization/95268 * tree-ssa-sink.c (sink_common_stores_to_bb): Handle clobbers properly. * g++.dg/torture/pr95268.C: New testcase. --- gcc/tree-ssa-sink.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'gcc/tree-ssa-sink.c') diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c index c5b535be..b61ecf1 100644 --- a/gcc/tree-ssa-sink.c +++ b/gcc/tree-ssa-sink.c @@ -534,7 +534,9 @@ sink_common_stores_to_bb (basic_block bb) /* ??? We could handle differing SSA uses in the LHS by inserting PHIs for them. */ else if (! operand_equal_p (gimple_assign_lhs (first_store), - gimple_assign_lhs (def), 0)) + gimple_assign_lhs (def), 0) + || (gimple_clobber_p (first_store) + && !gimple_clobber_p (def))) { first_store = NULL; break; @@ -546,16 +548,17 @@ sink_common_stores_to_bb (basic_block bb) /* Check if we need a PHI node to merge the stored values. */ bool allsame = true; - for (unsigned i = 1; i < vdefs.length (); ++i) - { - gimple *def = SSA_NAME_DEF_STMT (vdefs[i]); - if (! operand_equal_p (gimple_assign_rhs1 (first_store), - gimple_assign_rhs1 (def), 0)) - { - allsame = false; - break; - } - } + if (!gimple_clobber_p (first_store)) + for (unsigned i = 1; i < vdefs.length (); ++i) + { + gimple *def = SSA_NAME_DEF_STMT (vdefs[i]); + if (! operand_equal_p (gimple_assign_rhs1 (first_store), + gimple_assign_rhs1 (def), 0)) + { + allsame = false; + break; + } + } /* We cannot handle aggregate values if we need to merge them. */ tree type = TREE_TYPE (gimple_assign_lhs (first_store)); -- cgit v1.1