From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EF2EF3858D35; Fri, 16 Jun 2023 14:20:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF2EF3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686925203; bh=Vs6cUNZZKu20eaRnLGXt45erbHdYPUuVFjeJt+eWcMs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JeVlsYzChp185gO9S11LaAEAem8ij3ChI7i/T8YZxdccN53tbAWrQdTC3UvNpG155 iARdIYS5LBDjLynJA3RPD83VXq68CjUUHoWC7NetiydYxoUYLk1mw2ucdruAdWlvly GF/xqsHybF62tNigaK8LZOmVoHf0VOu66u2E1u7E= From: "hubicka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109849] suboptimal code for vector walking loop Date: Fri, 16 Jun 2023 14:20:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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=3D109849 --- Comment #14 from Jan Hubicka --- One interesting situation is: void std::vector >::push_back (struct vector * const this, const struct value_type & __x) { struct __normal_iterator D.27894; struct pair * _1; struct pair * _2; struct pair * _3; [local count: 1073741824]: _1 =3D this_6(D)->D.26707._M_impl.D.26014._M_finish; _2 =3D this_6(D)->D.26707._M_impl.D.26014._M_end_of_storage; if (_1 !=3D _2) goto ; [82.57%] else goto ; [17.43%] [local count: 886588625]: *_1 =3D MEM[(const struct pair &)__x_7(D)]; _3 =3D _1 + 8; this_6(D)->D.26707._M_impl.D.26014._M_finish =3D _3; goto ; [100.00%] [local count: 187153200]: D.27894._M_current =3D _1; std::vector >::_M_realloc_insert&> (this_6(D), D.27894, __x_7(D)); [local count: 1073741824]: return; } here we could do partial inlining and offline the call to _M_realloc_insert= but we fail to cut since _1 is already load: Split point at BB 4 header time: 9.302800 header size: 9 split time: 2.440200 split size: 5 bbs: 4 SSA names to pass: 1, 9, 11 Refused: need to pass non-param values=20 It should be easy to insert code loading the parameter again in the split p= art. We still hit the SRA limitation since this would be still escaping, but it = is another missed optimization on this simple testcase.=