> Am 14.02.2026 um 01:41 schrieb Andrew Pinski <[email protected]>:
>
> 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.
Ok
Richard
> 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 <[email protected]>
> ---
> gcc/testsuite/c-c++-common/torture/pr124086-1.c | 15 +++++++++++++++
> gcc/testsuite/g++.dg/torture/pr124086-1.C | 14 ++++++++++++++
> gcc/tree-complex.cc | 12 ++++++++----
> 3 files changed, 37 insertions(+), 4 deletions(-)
> create mode 100644 gcc/testsuite/c-c++-common/torture/pr124086-1.c
> create mode 100644 gcc/testsuite/g++.dg/torture/pr124086-1.C
>
> 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
> index 00000000000..6bca0431e4c
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/torture/pr124086-1.c
> @@ -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
> index 00000000000..f01bd35ce3c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/torture/pr124086-1.C
> @@ -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;
> +}
> diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc
> index 90401925f26..0937cb442bf 100644
> --- a/gcc/tree-complex.cc
> +++ b/gcc/tree-complex.cc
> @@ -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));
> --
> 2.43.0
>