Hi!

Like in many other spots, when walking immediate uses for optimization decisions
we should just ignore debug stmts.  aarch64_possible_by_lane_insn_p wasn't
ignoring those and wasted time on doing lookup for those and ICEd because
it wasn't a vectorizable stmt.

Fixed by ignoring debug stmts early during the immediate use walk.

Bootstrapped/regtested on aarch64-linux, preapproved in the PR by Andrew P.,
committed to trunk.

2026-01-20  Jakub Jelinek  <[email protected]>

        PR target/123724
        * config/aarch64/aarch64.cc (aarch64_possible_by_lane_insn_p): Ignore
        debug stmts.

        * g++.dg/opt/pr123724.C: New test.

--- gcc/config/aarch64/aarch64.cc.jj    2026-01-14 17:08:42.202383986 +0100
+++ gcc/config/aarch64/aarch64.cc       2026-01-19 20:45:36.826395280 +0100
@@ -18536,6 +18536,8 @@ aarch64_possible_by_lane_insn_p (vec_inf
   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
     {
       gimple *new_stmt = USE_STMT (use_p);
+      if (is_gimple_debug (new_stmt))
+       continue;
       auto stmt_info = vect_stmt_to_vectorize (m_vinfo->lookup_stmt 
(new_stmt));
       auto rep_stmt = STMT_VINFO_STMT (stmt_info);
       /* Re-association is a problem here, since lane instructions are only
--- gcc/testsuite/g++.dg/opt/pr123724.C.jj      2026-01-19 21:05:20.127661283 
+0100
+++ gcc/testsuite/g++.dg/opt/pr123724.C 2026-01-19 21:25:11.828776367 +0100
@@ -0,0 +1,31 @@
+// PR target/123724
+// { dg-do compile { target c++17 } }
+// { dg-options "-O2 -g" }
+
+namespace std {
+template <typename T> struct initializer_list {
+  const T *_M_array;
+  decltype (sizeof 0) _M_len;
+  auto size () const { return _M_len; }
+  const T *begin () const { return _M_array; }
+  const T *end () const { return _M_array + _M_len; }
+};
+}
+
+typedef std::initializer_list <int> A;
+struct B {
+  int b, c;
+  short d[4][3];
+  void foo (int);
+  void bar (A x) { for (auto i : x) d[b][c] |= i; }
+};
+
+void
+B::foo (int x)
+{
+  for (int i = 0; i < x; i++)
+    {
+      A x = { 1, 2 };
+      bar (x);
+    }
+}

        Jakub

Reply via email to