[committed,PR,tree-optimization/109392] Handle failure from maybe_push_res_to_seq

Message ID 15b03560-d4cf-d045-6a27-f0a6e2651fbe@gmail.com
State Committed
Commit 101380a8394c22a7a2ea70de2060ee93716156e2
Headers
Series [committed,PR,tree-optimization/109392] Handle failure from maybe_push_res_to_seq |

Commit Message

Jeff Law April 8, 2023, 6:27 p.m. UTC
  I was scanning through the P3s today and saw this patch from Jakub to 
fix 109392.  It looked quite reasonable, so I went ahead and did the 
bootstrap & regression test.  Everything looked good and I've applied it 
to the trunk.

Jeff
commit 101380a8394c22a7a2ea70de2060ee93716156e2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Apr 8 12:21:42 2023 -0600

    PR tree-optimization/109392
    
    If we have an object with SSA_NAME_OCCURS_IN_ABNORMAL_PHI, then
    maybe_push_res_to_seq may fail.  Directly build the extraction
    for that case.
    
            PR tree-optimization/109392
    
    gcc/
            * tree-vect-generic.cc (tree_vec_extract): Handle failure
            of maybe_push_res_to_seq better.
    
    gcc/testsuite/
    
            * gcc.dg/pr109392.c: New test.
  

Patch

diff --git a/gcc/testsuite/gcc.dg/pr109392.c b/gcc/testsuite/gcc.dg/pr109392.c
new file mode 100644
index 00000000000..e5bd9d440fa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109392.c
@@ -0,0 +1,15 @@ 
+/* PR tree-optimization/109392 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wno-psabi" } */
+
+typedef short __attribute__ ((__vector_size__ (64))) V;
+V v, w;
+void bar (void) __attribute__((returns_twice));
+
+V
+foo (V a, V b)
+{
+  bar ();
+  b &= v < b;
+  return (V) { foo (b, w)[3], (V) {}[3] };
+}
diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc
index 67f138a9332..445da53292e 100644
--- a/gcc/tree-vect-generic.cc
+++ b/gcc/tree-vect-generic.cc
@@ -174,7 +174,16 @@  tree_vec_extract (gimple_stmt_iterator *gsi, tree type,
   opr.resimplify (NULL, follow_all_ssa_edges);
   gimple_seq stmts = NULL;
   tree res = maybe_push_res_to_seq (&opr, &stmts);
-  gcc_assert (res);
+  if (!res)
+    {
+      /* This can happen if SSA_NAME_OCCURS_IN_ABNORMAL_PHI are
+	 used.  Build BIT_FIELD_REF manually otherwise.  */
+      t = build3 (BIT_FIELD_REF, type, t, bitsize, bitpos);
+      res = make_ssa_name (type);
+      gimple *g = gimple_build_assign (res, t);
+      gsi_insert_before (gsi, g, GSI_SAME_STMT);
+      return res;
+    }
   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   return res;
 }