From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4A13F3856627; Thu, 15 Jun 2023 18:38:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A13F3856627 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686854314; bh=7BsDsNlbCdzu40TNtSeqHR1wQ4+wgyZ2P+aCvXNtRpI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GMTmbE/eP9DlltkXukGI9f+u5ObQASFZeVFlpjvdHMpEsr7/o/bAqWE0rWmbGq2vQ q26GxgAocS8+rMGJrE+9APc9cTHiOuuvQl7kEo+F8MRzzXFCKfu+F6tRT1Zjm+Exe/ F3vZMg0/mfa29ttw2Uzs6MR/NqSSCLai7wt5K49U= From: "hiraditya at msn dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109442] Dead local copy of std::vector not removed from function Date: Thu, 15 Jun 2023 18:38:32 +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: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: hiraditya at msn dot com X-Bugzilla-Status: REOPENED 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=3D109442 --- Comment #17 from AK --- With recent changes in libc++ (https://reviews.llvm.org/D147741) clang optimizes away the new-delete pair. https://godbolt.org/z/a6PG54Pvb $ clang++ -O3 -stdlib=3Dlibc++ -fno-exceptions vat1(std::__1::vector >): # @vat1(std::__1::vector >) sub rsp, 24 xorps xmm0, xmm0 movaps xmmword ptr [rsp], xmm0 mov qword ptr [rsp + 16], 0 mov rax, qword ptr [rdi + 8] sub rax, qword ptr [rdi] je .LBB0_2 js .LBB0_3 .LBB0_2: mov eax, 10 add rsp, 24 ret .LBB0_3: mov rdi, rsp call std::__1::vector >::__throw_length_error[abi:v170000]() const .L.str: .asciz "vector" .L.str.1: .asciz "length_error was thrown in -fno-exceptions mode with message \"%s= \"" Previously clang couldn't even convert the copy to a memmove and would gene= rate a raw loop e.g., https://godbolt.org/z/G8ax1o5bc .LBB0_6: # =3D>This Inner Loop Header: Depth=3D1 movups xmm0, xmmword ptr [r15 + 4*rdi] movups xmm1, xmmword ptr [r15 + 4*rdi + 16] movups xmmword ptr [rax + 4*rdi], xmm0 movups xmmword ptr [rax + 4*rdi + 16], xmm1 add rdi, 8 cmp rsi, rdi jne .LBB0_6 cmp rbx, rsi jne .LBB0_8 jmp .LBB0_9 .LBB0_3:=