https://gcc.gnu.org/g:60cbce6499e5e616024e48eeeab469b2789c79dc

commit r16-9095-g60cbce6499e5e616024e48eeeab469b2789c79dc
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 f060275d72d9..a753aa708d28 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4419,7 +4419,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;

Reply via email to