From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6B025388C024; Sun, 21 Jun 2020 18:03:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B025388C024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592762639; bh=TzvQH2THYCcLbIA27VBOuxG+gzd+JIUaQmzVQT0cWfE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tZkLOpbQq8woYn1Oke5IDyYXLUfB3XBj99YfJhuoFeQSVQ+whjudBG5W6H7k/9+Ur 1dkgUEpNq5aFhaChyHowCPil2hhiWe73bF9j+Ro8hkcs4D7ckejBzPLk85gLQCn7JL P4yeQjNifsrNVBwv7H7PdMYTbyVtg0i5Rqapy4ng= From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/90436] Redundant size checking in vector Date: Sun, 21 Jun 2020 18:03:59 +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: 10.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: glisse 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 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, 21 Jun 2020 18:03:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D90436 --- Comment #4 from Marc Glisse --- (side note not related to the redundant size checking) It is surprising how, in the code from comment 2, adding v.reserve(1000) do= es not help, it even slows the program down slightly here (yes, that's rather = hard to believe). To reap the benefits, I also need to add in the loop: if(v.size()=3D=3Dv.capacity())__builtin_abort(); which enables the compiler to remove the reallocation code, and once that c= ode is removed it can actually prove that size never reaches capacity and remove the call to abort! We don't even need __builtin_unreachable there. And once= all that dead code is removed, it can finally vectorize.=