From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CAACC384012F; Tue, 13 Dec 2022 10:04:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAACC384012F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670925897; bh=mpQtXkRdeZd9Ohk8qmOcM0Y4oowwwMuy0iDkgiHWF0c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JMWdI/agBrHhZfX0UebEyx8HQgVuXbBNziXqx5LwK6yY4Kbnho7OEdhBFUWOf24Ug FUwgYp9FqVgM7s61fb05AR0ESzz7vdol9XdaZpuhNR8QSjSJItEhU6TV9hXTC/4bl/ /bmjjBzad8x431av+xT8NIv1oxxZJ2HItQG6xEYM= From: "fxue at os dot amperecomputing.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107828] tree-inlining would generate SSA with incorrect def stmt Date: Tue, 13 Dec 2022 10:04:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fxue at os dot amperecomputing.com X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: resolution bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107828 Feng Xue changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|INVALID |--- Status|RESOLVED |WAITING --- Comment #4 from Feng Xue --- (In reply to Martin Jambor from comment #2) > I don't see any correctness issue here. It is true that when IPA-SRA > needs to create a temporary SSA_NAME for an assignment with > VIEW_CONVERT_EXPR (that is the only statement that extra_stmts can > contain at the moment), the SSA_NAME then get's re-mapped to another > while woe could have just re-use the existing one, it is already > created within the new function. >=20 > We could use the knowledge that extra_stmts is really only this one > statement or nothing and avoid the remapping but that would be at the > expense of universality and extensibility of the interface between > tree-inline.cc and ipa-param-manipulations.cc. >=20 > Please let me know if I am missing something (and preferably with a > test-case that demonstrates the problem). Sorry for late response. It is hard to compose a simple test case, since this could only be exposed = with our own private code. To reproduce it is not that straightforward, but we c= ould forcefully do that with a minor change to "ipa_param_body_adjustments::modify_assignment" in ipa-param-manipulation.c= c. diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc index cee0e23f946..202c0fda32b 100644 --- a/gcc/ipa-param-manipulation.cc +++ b/gcc/ipa-param-manipulation.cc @@ -1787,7 +1787,7 @@ ipa_param_body_adjustments::modify_assignment (gimple *stmt, any =3D modify_expression (lhs_p, false); any |=3D modify_expression (rhs_p, false); if (any - && !useless_type_conversion_p (TREE_TYPE (*lhs_p), TREE_TYPE (*rhs_p= ))) + && true /* !useless_type_conversion_p (TREE_TYPE (*lhs_p), TREE_TYPE (*rhs_p)) */) { if (TREE_CODE (*rhs_p) =3D=3D CONSTRUCTOR) { @@ -1805,7 +1805,14 @@ ipa_param_body_adjustments::modify_assignment (gimple *stmt, *rhs_p); tree tmp =3D force_gimple_operand (new_rhs, extra_stmts, true, NULL_TREE); - gimple_assign_set_rhs1 (stmt, tmp); + + tree tmp1 =3D make_ssa_name (tmp); + gimple *copy =3D gimple_build_assign (tmp1, tmp); + + auto gsi =3D gsi_last (*extra_stmts); + gsi_insert_after_without_update (&gsi, copy, GSI_NEW_STMT); + + gimple_assign_set_rhs1 (stmt, tmp1); } return true; } The purpose of above code piece is to add trivial ssa copy statement to make the below "extra_stmts" not empty: remap_gimple_stmt() { ... if (id->param_body_adjs) { ... if (!gimple_seq_empty_p (extra_stmts)) { memset (&wi, 0, sizeof (wi)); wi.info =3D id; for (gimple_stmt_iterator egsi =3D gsi_start (extra_stmts); !gsi_end_p (egsi); gsi_next (&egsi)) walk_gimple_op (gsi_stmt (egsi), remap_gimple_op_r, &wi); ^^^^^^^^^^^^^^^^^ ... } } ... } Now, we use the case gcc.dg/ipa/ipa-sra-1.c, and option is "-O3 -flto -fipa-sra". Trace into "remap_gimple_op_r" as above, check remapping on cop= y: <&0x7ffff6c282d0> ISRA.0_1 =3D ISRA.0; A new SSA name "ISRA.0_2" is created, after setting definition statement fo= r it via: if (TREE_CODE (*tp) =3D=3D SSA_NAME) { *tp =3D remap_ssa_name (*tp, id); *walk_subtrees =3D 0; if (is_lhs) SSA_NAME_DEF_STMT (*tp) =3D wi_p->stmt; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ return NULL; } Here, both "ISRA.0_1" and "ISRA.O_2" belong to same function, and point to = same def stmt.=