]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
complex-lowering: Fix up extraction with VCEs [PR124086]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 13 Feb 2026 19:30:53 +0000 (11:30 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 14 Feb 2026 07:52:33 +0000 (23:52 -0800)
This was an oversight on my part when I converted extract_component
to use gimple_build_assign instead of force_gimple_operand_gsi.
I had provided a special case for VCE of a SSA_NAME but I missed
that the same issue would be caused with invariants too and invariants
would show up with VCE; I assumed they would be folded.
This changes the check to include invariants too.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/124086

gcc/ChangeLog:

* tree-complex.cc (extract_component): Extend the check
for ssa names for VCE to include invariants.

gcc/testsuite/ChangeLog:

* c-c++-common/torture/pr124086-1.c: New test.
* g++.dg/torture/pr124086-1.C: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/c-c++-common/torture/pr124086-1.c [new file with mode: 0644]
gcc/testsuite/g++.dg/torture/pr124086-1.C [new file with mode: 0644]
gcc/tree-complex.cc

diff --git a/gcc/testsuite/c-c++-common/torture/pr124086-1.c b/gcc/testsuite/c-c++-common/torture/pr124086-1.c
new file mode 100644 (file)
index 0000000..6bca043
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* PR tree-optimization/124086 */
+
+
+typedef __attribute__((__vector_size__(2*sizeof(long double)))) int V;
+int j;
+
+void
+foo()
+{
+  V v = (V){0, -0xd};
+  _Complex long double t =  *(_Complex long double *)&v;
+  j = __real__ t;
+}
diff --git a/gcc/testsuite/g++.dg/torture/pr124086-1.C b/gcc/testsuite/g++.dg/torture/pr124086-1.C
new file mode 100644 (file)
index 0000000..f01bd35
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile { target lp64 } }
+
+// PR tree-optimization/124086
+
+int j;
+int *v;
+void
+foo()
+{
+  int t;
+  v = &t;
+  auto t1 = __builtin_bit_cast(_Complex int, v);
+  j = __real__ t1;
+}
index 90401925f26e1c0b4b4c5e2c0fa2ee5bbeb23dbc..0937cb442bf9c475ac64f915caa55f6dc94a1828 100644 (file)
@@ -664,14 +664,18 @@ extract_component (gimple_stmt_iterator *gsi, tree t, bool imagpart_p,
       }
 
     case VIEW_CONVERT_EXPR:
-      /* Getting the real/imag parts of a VCE of a ssa-name requires
-        to place the complex into a ssa name before getting the
-        2 parts.
+      /* Getting the real/imag parts of a VCE of a ssa-name
+         (or gimple invariant) requires to place the complex
+        into a ssa name before getting the 2 parts.
         As `IMAGPART_EXPR<VIEW_CONVERT_EXPR<a_BN>>` is an invalid
         gimple. This will only show up when gimplifying it.
         Note this creates an extra copy.  The call to
         force_gimple_operand_gsi would create one too.  */
-      if (TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME)
+      tree expr;
+      expr = TREE_OPERAND (t, 0);
+      if (TREE_CODE (expr) == SSA_NAME
+         || (is_gimple_min_invariant (expr)
+             && TREE_CODE (expr) != STRING_CST))
        {
          gcc_assert (gimple_p);
          tree new_cplx = make_ssa_name (TREE_TYPE (t));