fix useless unsharing of SLP tree
authorRichard Biener <rguenther@suse.de>
Wed, 9 Sep 2020 11:58:45 +0000 (13:58 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 9 Sep 2020 12:46:14 +0000 (14:46 +0200)
This avoids unsharing the SLP tree when optimizing load permutations
for reductions but there is no actual permute taking place.

2020-09-09  Richard Biener  <rguenther@suse.de>

* tree-vect-slp.c (vect_attempt_slp_rearrange_stmts): Do
nothing when the permutation doesn't permute.

gcc/tree-vect-slp.c

index dcc80d559177aa8b32dd66f94a640277a4c3c1ea..7860fe3f32bc6046144e622c9a3967aef785bd45 100644 (file)
@@ -1903,11 +1903,14 @@ vect_attempt_slp_rearrange_stmts (slp_instance slp_instn)
     }
 
   /* Check that the loads in the first sequence are different and there
-     are no gaps between them.  */
+     are no gaps between them and that there is an actual permutation.  */
+  bool any_permute = false;
   auto_sbitmap load_index (group_size);
   bitmap_clear (load_index);
   FOR_EACH_VEC_ELT (node->load_permutation, i, lidx)
     {
+      if (lidx != i)
+       any_permute = true;
       if (lidx >= group_size)
        return false;
       if (bitmap_bit_p (load_index, lidx))
@@ -1915,6 +1918,8 @@ vect_attempt_slp_rearrange_stmts (slp_instance slp_instn)
 
       bitmap_set_bit (load_index, lidx);
     }
+  if (!any_permute)
+    return false;
   for (i = 0; i < group_size; i++)
     if (!bitmap_bit_p (load_index, i))
       return false;