https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122270
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> Reduced:
> ```
> #pragma riscv intrinsic "vector"
> void a(vfloat32m1_t b, vfloat32m1x4_t *c) {
> *c = __riscv_vset_v_f32m1_f32m1x4(*c, 3, b);
> }
> ```
>
> Note we also get an ICE without using -march=rv64g_v with the C++ front-end
> (but that is a different bug).
>
>
> gcc_assert (!gimple_has_lhs (orig_stmt) || !gimple_has_lhs (stmt)
> || gimple_get_lhs (orig_stmt) == gimple_get_lhs (stmt));
So we are replacing the __riscv_vset_v_f32m1_f32m1x4 call stmt with:
*c = *c;
/* Replace the call with two statements: a copy of the full tuple
to the call result, followed by an update of the individual vector.
The fold routines expect the replacement statement to have the
same lhs as the original call, so return the copy statement
rather than the field update. */
gassign *copy = gimple_build_assign (unshare_expr (f.lhs), rhs_tuple);
But unshare_expr is used here even with this comment ...
This fixes the problem, switch around which get the original expression vs an
unshared version:
diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc
b/gcc/config/riscv/riscv-vector-builtins-bases.cc
index 7e4d396f05a..ffe7c5e53d7 100644
--- a/gcc/config/riscv/riscv-vector-builtins-bases.cc
+++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc
@@ -1793,12 +1793,12 @@ public:
The fold routines expect the replacement statement to have the
same lhs as the original call, so return the copy statement
rather than the field update. */
- gassign *copy = gimple_build_assign (unshare_expr (f.lhs), rhs_tuple);
+ gassign *copy = gimple_build_assign (f.lhs, rhs_tuple);
/* Get a reference to the individual vector. */
tree field = tuple_type_field (TREE_TYPE (f.lhs));
tree lhs_array
- = build3 (COMPONENT_REF, TREE_TYPE (field), f.lhs, field, NULL_TREE);
+ = build3 (COMPONENT_REF, TREE_TYPE (field), unshare_expr (f.lhs), field,
NULL_TREE);
tree lhs_vector = build4 (ARRAY_REF, TREE_TYPE (rhs_vector), lhs_array,
index, NULL_TREE, NULL_TREE);
gassign *update = gimple_build_assign (lhs_vector, rhs_vector);