]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix ICE in vectorizable_nonlinear_induction with bitfield.
authorliuhongt <hongtao.liu@intel.com>
Mon, 13 Nov 2023 09:56:49 +0000 (17:56 +0800)
committerliuhongt <hongtao.liu@intel.com>
Tue, 14 Nov 2023 08:40:46 +0000 (16:40 +0800)
 if (TREE_CODE (init_expr) == INTEGER_CST)
    init_expr = fold_convert (TREE_TYPE (vectype), init_expr);
  else
    gcc_assert (tree_nop_conversion_p (TREE_TYPE (vectype),
                                       TREE_TYPE (init_expr)));

and init_expr is a 24 bit integer type while vectype has 32bit components.

The "fix" is to bail out instead of asserting.

gcc/ChangeLog:

PR tree-optimization/112496
* tree-vect-loop.cc (vectorizable_nonlinear_induction): Return
false when !tree_nop_conversion_p (TREE_TYPE (vectype),
TREE_TYPE (init_expr)).

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112496.c: New test.

gcc/testsuite/gcc.target/i386/pr112496.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.target/i386/pr112496.c b/gcc/testsuite/gcc.target/i386/pr112496.c
new file mode 100644 (file)
index 0000000..c478fda
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct T { int x : 24; } v;
+void f1(int x) {
+  while (v.x - ((v.x <<= 1) - v.x)) ;
+}
index 7d00cc9689c7823c0daf9fa74167e9eb86872590..fb8d999ee6bfaff551ac06ac2f3aea5354914659 100644 (file)
@@ -9569,9 +9569,16 @@ vectorizable_nonlinear_induction (loop_vec_info loop_vinfo,
 
   if (TREE_CODE (init_expr) == INTEGER_CST)
     init_expr = fold_convert (TREE_TYPE (vectype), init_expr);
-  else
-    gcc_assert (tree_nop_conversion_p (TREE_TYPE (vectype),
-                                      TREE_TYPE (init_expr)));
+  else if (!tree_nop_conversion_p (TREE_TYPE (vectype), TREE_TYPE (init_expr)))
+    {
+      /* INIT_EXPR could be a bit_field, bail out for such case.  */
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                        "nonlinear induction vectorization failed:"
+                        " component type of vectype is not a nop conversion"
+                        " from type of init_expr.\n");
+      return false;
+    }
 
   switch (induction_type)
     {