https://gcc.gnu.org/g:a5d05111bde1e07824fd85d3a97785022ae30b8a

commit r12-10913-ga5d05111bde1e07824fd85d3a97785022ae30b8a
Author: Richard Biener <rguent...@suse.de>
Date:   Tue Nov 12 11:15:15 2024 +0100

    tree-optimization/117417 - ICE with complex load optimization
    
    When we decompose a complex load only used as real and imaginary
    parts we fail to honor IL constraints which are that a BIT_FIELD_REF
    of register type should be outermost in a ref.  The following
    simply avoids the transform when the complex load has such a
    BIT_FIELD_REF.
    
            PR tree-optimization/117417
            * tree-ssa-forwprop.cc (pass_forwprop::execute): Avoid
            decomposing BIT_FIELD_REF complex load.
    
            * gcc.dg/torture/pr117417.c: New testcase.
    
    (cherry picked from commit d976daa931642d940b7b27032ca6139210c07eed)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117417.c | 16 ++++++++++++++++
 gcc/tree-ssa-forwprop.cc                |  6 +++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117417.c 
b/gcc/testsuite/gcc.dg/torture/pr117417.c
new file mode 100644
index 000000000000..2c80dd5d77cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117417.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+typedef __attribute__((__vector_size__ (8))) double V;
+int bar (int a, V *p)
+{
+  V v;
+  v = *p;
+  a += *(_Complex short *) &v;
+  return a;
+}
+V x;
+int
+foo ()
+{
+  return bar (0, &x);
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 062f5667f14a..1b36ffb0bbe7 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3542,9 +3542,9 @@ pass_forwprop::execute (function *fun)
          else if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE
                   && gimple_assign_load_p (stmt)
                   && !gimple_has_volatile_ops (stmt)
-                  && (TREE_CODE (gimple_assign_rhs1 (stmt))
-                      != TARGET_MEM_REF)
-                  && !stmt_can_throw_internal (cfun, stmt))
+                  && TREE_CODE (rhs) != TARGET_MEM_REF
+                  && TREE_CODE (rhs) != BIT_FIELD_REF
+                  && !stmt_can_throw_internal (fun, stmt))
            {
              /* Rewrite loads used only in real/imagpart extractions to
                 component-wise loads.  */

Reply via email to