]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/115843 - fix wrong-code with fully-masked loop and peeling
authorRichard Biener <rguenther@suse.de>
Mon, 15 Jul 2024 11:50:58 +0000 (13:50 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 16 Jul 2024 08:11:16 +0000 (10:11 +0200)
When AVX512 uses a fully masked loop and peeling we fail to create the
correct initial loop mask when the mask is composed of multiple
components in some cases.  The following fixes this by properly applying
the bias for the component to the shift amount.

PR tree-optimization/115843
* tree-vect-loop-manip.cc
(vect_set_loop_condition_partial_vectors_avx512): Properly
bias the shift of the initial mask for alignment peeling.

* gcc.dg/vect/pr115843.c: New testcase.

gcc/testsuite/gcc.dg/vect/pr115843.c [new file with mode: 0644]
gcc/tree-vect-loop-manip.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr115843.c b/gcc/testsuite/gcc.dg/vect/pr115843.c
new file mode 100644 (file)
index 0000000..3dbb6c7
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-additional-options "-mavx512f --param vect-partial-vector-usage=2" { target avx512f_runtime } } */
+
+#include "tree-vect.h"
+
+typedef __UINT64_TYPE__ BITBOARD;
+BITBOARD KingPressureMask1[64], KingSafetyMask1[64];
+
+void __attribute__((noinline))
+foo()
+{
+  for (int i = 0; i < 64; i++)
+    {
+      if ((i & 7) == 0)
+       KingPressureMask1[i] = KingSafetyMask1[i + 1];
+      else if ((i & 7) == 7)
+       KingPressureMask1[i] = KingSafetyMask1[i - 1];
+      else
+       KingPressureMask1[i] = KingSafetyMask1[i];
+    }
+}
+
+BITBOARD verify[64]
+  = {1, 1, 2, 3, 4, 5, 6, 6, 9, 9, 10, 11, 12, 13, 14, 14, 17, 17, 18, 19,
+    20, 21, 22, 22, 25, 25, 26, 27, 28, 29, 30, 30, 33, 33, 34, 35, 36, 37, 38,
+    38, 41, 41, 42, 43, 44, 45, 46, 46, 49, 49, 50, 51, 52, 53, 54, 54, 57, 57,
+    58, 59, 60, 61, 62, 62};
+
+int main()
+{
+  check_vect ();
+
+#pragma GCC novector
+  for (int i = 0; i < 64; ++i)
+    KingSafetyMask1[i] = i;
+  foo ();
+#pragma GCC novector
+  for (int i = 0; i < 64; ++i)
+    if (KingPressureMask1[i] != verify[i])
+      __builtin_abort ();
+  return 0;
+}
index ac13873cd88d4181d0ac8c5b512594bedc07a3a0..57dbcbe862cda5cec1794b57d5d919348eca60ec 100644 (file)
@@ -1149,10 +1149,14 @@ vect_set_loop_condition_partial_vectors_avx512 (class loop *loop,
              /* ???  But when the shift amount isn't constant this requires
                 a round-trip to GRPs.  We could apply the bias to either
                 side of the compare instead.  */
-             tree shift = gimple_build (&preheader_seq, MULT_EXPR,
+             tree shift = gimple_build (&preheader_seq, MINUS_EXPR,
                                         TREE_TYPE (niters_skip), niters_skip,
                                         build_int_cst (TREE_TYPE (niters_skip),
-                                                       rgc.max_nscalars_per_iter));
+                                                       bias));
+             shift = gimple_build (&preheader_seq, MULT_EXPR,
+                                   TREE_TYPE (niters_skip), shift,
+                                   build_int_cst (TREE_TYPE (niters_skip),
+                                                  rgc.max_nscalars_per_iter));
              init_ctrl = gimple_build (&preheader_seq, LSHIFT_EXPR,
                                        TREE_TYPE (init_ctrl),
                                        init_ctrl, shift);