When forwprop decomposes a vector load based on BIT_FIELD_REF
uses we have to avoid moving defs of abnormals.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        PR tree-optimization/125502
        * tree-ssa-forwprop.cc (optimize_vector_load): Do not
        move defs of abnormals.

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr125502.c 
b/gcc/testsuite/gcc.dg/torture/pr125502.c
new file mode 100644
index 00000000000..c31576cae51
--- /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 6c94675e0ac..922e36590fd 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4425,7 +4425,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;
-- 
2.51.0

Reply via email to