From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 94CC33835820; Sun, 2 May 2021 11:27:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94CC33835820 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/100366] spurious warning - std::vector::clear followed by std::vector::insert(vec.end(), ...) with -O2 Date: Sun, 02 May 2021 11:27:22 +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: 11.1.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: glisse 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: cf_reconfirmed_on everconfirmed component keywords 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2021 11:27:22 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100366 Marc Glisse changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2021-05-02 Ever confirmed|0 |1 Component|c++ |tree-optimization Keywords| |diagnostic, | |missed-optimization Status|UNCONFIRMED |NEW --- Comment #1 from Marc Glisse --- Assuming the warning happens during the strlen pass, we are still missing a= lot of optimizations at that point if (_6 !=3D _7) goto ; [70.00%] else goto ; [30.00%] [local count: 322122544]: _158 =3D _7 - _6; once VRP2 (2 passes after strlen) replaces _158 with 0 and propagates it, m= aybe the code becomes nice enough to avoid confusing this fragile warning (I did= n't check). Before FRE3, we have _6 =3D vec_2(D)->D.33506._M_impl.D.32819._M_start; _7 =3D vec_2(D)->D.33506._M_impl.D.32819._M_finish; if (_6 !=3D _7) goto ; [70.00%] else goto ; [30.00%] [local count: 1073741824]: _5 =3D MEM[(char * const &)vec_2(D) + 8]; MEM[(struct __normal_iterator *)&D.33862] =3D{v} {CLOBBER}; MEM[(struct __normal_iterator *)&D.33862]._M_current =3D _5; __position =3D D.33862; _12 =3D MEM[(const char * const &)vec_2(D)]; _13 =3D MEM[(const char * const &)&__position]; _14 =3D _13 - _12; and after FRE3 [local count: 1073741824]: _5 =3D MEM[(char * const &)vec_2(D) + 8]; MEM[(struct __normal_iterator *)&D.33862] =3D{v} {CLOBBER}; MEM[(struct __normal_iterator *)&D.33862]._M_current =3D _5; __position =3D D.33862; _14 =3D _5 - _6; Only PRE manages to notice that _5 is the same as _7, which is already late. And it then takes until VRP2 to realize that _7 - _6 must be 0 in the else branch of _6 !=3D _7. * I am not sure why FRE manages to optimize _12 and not _5, that seems like= the first thing to check (maybe the +8 means it is obviously "partial") * I don't know if some other pass than VRP could learn that b-a is 0 if not a!=3Db.=