slp: fix is_linear_load_p to prevent multiple answers
authorTamar Christina <tamar.christina@arm.com>
Mon, 11 Jan 2021 09:56:44 +0000 (09:56 +0000)
committerTamar Christina <tamar.christina@arm.com>
Mon, 11 Jan 2021 09:56:44 +0000 (09:56 +0000)
This fixes an issue where is_linear_load_p could return the incorrect
permutation kind because it is singe pass.

This arranges the candidates in such a way that there won't be any ambiguity so
that the function can still be linear but give correct values.

gcc/ChangeLog:

* tree-vect-slp-patterns.c (is_linear_load_p): Fix ambiguity.

gcc/tree-vect-slp-patterns.c

index 9b8ba415b159d27f7d2ecfaae5fcc6abc51a365d..e30cea110f6bf5838d9c721f7e614153d32b8dbf 100644 (file)
@@ -140,32 +140,32 @@ is_linear_load_p (load_permutation_t loads)
 
   unsigned load, i;
   complex_perm_kinds_t candidates[4]
-    = { PERM_EVENODD
-      , PERM_ODDEVEN
-      , PERM_ODDODD
+    = { PERM_ODDODD
       , PERM_EVENEVEN
+      , PERM_EVENODD
+      , PERM_ODDEVEN
       };
 
   int valid_patterns = 4;
-  FOR_EACH_VEC_ELT_FROM (loads, i, load, 1)
+  FOR_EACH_VEC_ELT (loads, i, load)
     {
-      if (candidates[0] != PERM_UNKNOWN && load != i)
+      if (candidates[0] != PERM_UNKNOWN && load != 1)
        {
          candidates[0] = PERM_UNKNOWN;
          valid_patterns--;
        }
-      if (candidates[1] != PERM_UNKNOWN
-         && load != (i % 2 == 0 ? i + 1 : i - 1))
+      if (candidates[1] != PERM_UNKNOWN && load != 0)
        {
          candidates[1] = PERM_UNKNOWN;
          valid_patterns--;
        }
-      if (candidates[2] != PERM_UNKNOWN && load != 1)
+      if (candidates[2] != PERM_UNKNOWN && load != i)
        {
          candidates[2] = PERM_UNKNOWN;
          valid_patterns--;
        }
-      if (candidates[3] != PERM_UNKNOWN && load != 0)
+      if (candidates[3] != PERM_UNKNOWN
+         && load != (i % 2 == 0 ? i + 1 : i - 1))
        {
          candidates[3] = PERM_UNKNOWN;
          valid_patterns--;