]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121509 - failure to detect unvectorizable loop
authorRichard Biener <rguenther@suse.de>
Tue, 12 Aug 2025 07:51:54 +0000 (09:51 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 12 Aug 2025 09:05:35 +0000 (11:05 +0200)
With the hybrid stmt detection no longer working as a gate-keeper
to detect unhandled stmts we have to, and can, detect those earlier.
The appropriate place is vect_mark_stmts_to_be_vectorized where
for trivially relevant PHIs we can stop analyzing when the PHI
wasn't classified as a known def during vect_analyze_scalar_cycles.

PR tree-optimization/121509
* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized):
Fail early when we detect a relevant but not handled PHI.

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

gcc/testsuite/gcc.dg/vect/pr121509.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr121509.c b/gcc/testsuite/gcc.dg/vect/pr121509.c
new file mode 100644 (file)
index 0000000..3a69ad3
--- /dev/null
@@ -0,0 +1,42 @@
+/* { dg-additional-options "-fgimple" } */
+
+#include "tree-vect.h"
+
+long g_73[2] = {6L,6L};
+int __GIMPLE (ssa,startwith("loop")) __attribute__((noipa))
+foo ()
+{
+  signed char g;
+  int l;
+  int _1;
+  unsigned char _3;
+  unsigned char _4;
+
+  __BB(2):
+  goto __BB3;
+
+  __BB(3,loop_header(1)):
+  l_5 = __PHI (__BB2: _Literal (int) -511973466, __BB3: 1);
+  g_6 = __PHI (__BB2: _Literal (signed char) 0, __BB3: g_12);
+  _1 = (int) g_6;
+  g_73[_1] = 0l;
+  _3 = (unsigned char) g_6;
+  _4 = _3 + _Literal (unsigned char) 1;
+  g_12 = (signed char) _4;
+  if (g_12 > _Literal (signed char) 1)
+    goto __BB4;
+  else
+    goto __BB3;
+
+  __BB(4):
+  l_14 = __PHI (__BB3: l_5);
+  return l_14;
+}
+
+int main()
+{
+  check_vect ();
+  if (foo () != 1)
+    abort ();
+  return 0;
+}
index b14680e0d7c38ec390a7935910ca1593e3712f40..22397dc8bc3376eb9a3b834d24ec9acf29b65c2e 100644 (file)
@@ -722,7 +722,12 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
                             phi_info->stmt);
 
          if (vect_stmt_relevant_p (phi_info, loop_vinfo, &relevant, &live_p))
-           vect_mark_relevant (&worklist, phi_info, relevant, live_p);
+           {
+             if (STMT_VINFO_DEF_TYPE (phi_info) == vect_unknown_def_type)
+               return opt_result::failure_at
+                 (*si, "not vectorized: unhandled relevant PHI: %G", *si);
+             vect_mark_relevant (&worklist, phi_info, relevant, live_p);
+           }
        }
       for (si = gsi_after_labels (bb); !gsi_end_p (si); gsi_next (&si))
        {