From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3851739A4003; Wed, 5 May 2021 10:55:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3851739A4003 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: Wed, 05 May 2021 10:55:38 +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 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: 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: Wed, 05 May 2021 10:55:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100366 --- Comment #5 from Marc Glisse --- (In reply to Martin Sebor from comment #2) > The IL looks like the warning is justified: The memcpy call is dead code, we just fail to notice it. > [local count: 230225493]: > # prephitmp_42 =3D PHI <_6(4), _7(3)> This is always _6, because in bb 3 we have _6 =3D=3D _7. > pretmp_67 =3D vec_2(D)->D.33449._M_impl.D.32762._M_start; > _69 =3D prephitmp_42 - pretmp_67; Always 0. > [local count: 220460391]: > MEM [(char * {ref-all})_155] =3D pretmp_72; > _50 =3D vec_2(D)->D.33449._M_impl.D.32762._M_finish; > _Num_51 =3D _50 - prephitmp_42; Always 0, in bb 4 we copy _M_start in _M_finish if they are not already equ= al. (sorry for the wrong FRE comment earlier) Note that if I replace operator new/delete with malloc/free inline void* operator new(std::size_t n){return __builtin_malloc(n);} inline void operator delete(void*p)noexcept{__builtin_free(p);} inline void operator delete(void*p,std::size_t)noexcept{__builtin_free(p);} we optimize quite a bit more and the warning disappears.=