From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 973583858C66; Mon, 20 Mar 2023 18:09:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 973583858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679335767; bh=SiXa4Nqqp2z0wruJY4Q0oFb2Jc3j15ewvFTfCJeKTos=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KMXsiw4a87UCLh/R5X55tnwhp//yzu2fPPY/NW4zB1cX+C2hux6DqQkT5hMBI87Ny Qy9e0rJWgwufI2rkjHdPZap9D4ljCnp0Hyx0BqhlevMEVvhGQQYZPNoTcyZmgwyaSq ldWAFpiDLYRn0LM5/6ln37o1rodZOn1olJhVTQuk= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109205] vector.resize( v.size() + 100 ) does unnecessary comparison Date: Mon, 20 Mar 2023 18:09:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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=3D109205 --- Comment #1 from Andrew Pinski --- So the IR looks like: _4 =3D MEM[(const struct vector *)v_3(D)].D.25711._M_impl.D.25018._M_fini= sh; _6 =3D MEM[(const struct vector *)v_3(D)].D.25711._M_impl.D.25018._M_star= t; _7 =3D _4 - _6; _8 =3D (long unsigned int) _7; _1 =3D _8 + 100; GCC does not know this statement holds true: if (v.end() < v.begin()) __builtin_unreachable(); If you add that, then it will optimize away the comparison.=