From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 968E83858C50; Sun, 21 Jan 2024 01:44:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 968E83858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705801490; bh=EyBFFs7JVExSpAcDrVfY9I3lsSKZxILdpMnd9BbWp0I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OJXwMnTTPRVRhdG7mIxea+sDmQdPgxfv1tUebOIC+Umkn3o+uwMCYURVdJVKy51f4 yKUb1u1uIKG7Hkv5XuTClVYhp3la+YiUaS3ITUuHIJxT8XkXKotToJPLft74gQVSTy 7KREnxf8na8MMG/pWK3ZdvE/geU7EkWiTeIkOf6M= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector Date: Sun, 21 Jan 2024 01:44:25 +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: 14.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: 13.3 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=3D113239 --- Comment #5 from Andrew Pinski --- Note the missed optimization was there in GCC 12, just the diagnostic was n= ot. We have: ``` _4 =3D MEM[(const unsigned char * const &)current_frame__2(D) + 24]; _7 =3D MEM[(const unsigned char * const &)current_frame__2(D) + 16]; if (_4 =3D=3D _7) goto ; [17.43%] else goto ; [82.57%] [local count: 187153200]: ... MEM [(unsigned char * *)_5(D) + 16B] =3D { = 0, 0 }; MEM[(struct _Vector_base *)_5(D) + 16B]._M_impl.D.21112._M_end_of_storage= =3D 0B; _21 =3D MEM[(const unsigned char * const &)current_frame__2(D) + 24]; _22 =3D MEM[(const unsigned char * const &)current_frame__2(D) + 16]; _Num_23 =3D _21 - _22; ``` But based on the original condition (and the stores to offset of _5 [which technically cannot alias current_frame__2]), _Num_23 will be 0. What g:822a11a1e642e0abe92a996e7033a5066905a447 does is just add an extra if statement where we get: ``` if (_Num_24 > 1) goto ; [90.00%] else goto ; [10.00%] [local count: 156478790]: _Num.5_28 =3D (long unsigned int) _Num_24; __builtin_memmove (0B, _22, _Num.5_28); goto ; [100.00%] [local count: 17386533]: if (_Num_24 =3D=3D 1) goto ; [34.00%] else goto ; [66.00%] [local count: 5911421]: MEM[(unsigned char *)0B] =3D{v} 0; /// <<<<<< This is causing the warning __builtin_trap (); ``` Instead of just: ``` if (_Num_23 !=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 57375556]: _Num.4_24 =3D (long unsigned int) _Num_23; __builtin_memmove (0B, _22, _Num.4_24); ```=