[gcc r15-11392] tree-optimization/125502 - vector load decomposition issue

Richard Biener via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:39e038e218a19d01fce733f35e735199bdc25ef5

commit r15-11392-g39e038e218a19d01fce733f35e735199bdc25ef5
Author: Richard Biener <[email protected]>
Date:   Tue Jun 2 12:06:23 2026 +0200

    tree-optimization/125502 - vector load decomposition issue
    
    When forwprop decomposes a vector load based on BIT_FIELD_REF
    uses we have to avoid moving defs of abnormals.
    
            PR tree-optimization/125502
            * tree-ssa-forwprop.cc (optimize_vector_load): Do not
            move defs of abnormals.
    
            * gcc.dg/torture/pr125502.c: New testcase.
    
    (cherry picked from commit 09ec0df3217a1dc4abbad1ef7e84642597629a1c)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr125502.c | 15 +++++++++++++++
 gcc/tree-ssa-forwprop.cc                |  8 +++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr125502.c b/gcc/testsuite/gcc.dg/torture/pr125502.c
new file mode 100644
index 000000000000..c31576cae516
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr125502.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+int f() __attribute__((returns_twice));
+typedef short v16i16 __attribute__((vector_size(32)));
+void f3(short);
+void f4()
+{
+    v16i16 vec6, vec11;
+    short v13;
+    vec6[0] = f();
+    vec11 = vec6;
+    f3(v13);
+    v13 = vec11[2];
+    f4();
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 4f5f1b94184a..2ddcfe3e782e 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3243,7 +3243,13 @@ optimize_vector_load (gimple_stmt_iterator *gsi)
 	  gimple *use_stmt = USE_STMT (use_p);
 	  if (is_gimple_debug (use_stmt))
 	    continue;
-	  if (!is_gimple_assign (use_stmt))
+	  tree use_lhs;
+	  if (!is_gimple_assign (use_stmt)
+	      /* For alias reasons we move the use to the place of the
+		 load.  Avoid this when abnormals are involved.  */
+	      || ((TREE_CODE ((use_lhs = gimple_assign_lhs (use_stmt)))
+		   == SSA_NAME)
+		  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (use_lhs)))
 	    {
 	      rewrite = false;
 	      break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.