From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BA5973898383; Tue, 6 Dec 2022 07:43:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA5973898383 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670312612; bh=+TGXYGMhPP1srJOHZDNNV0qTlnKHcA1ZZakU7xLrm3I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=J0Ewh3GUiDcUFhL79pwexwBrPsOxhxNwpMi4EWNlM08z9SOh4+/sqJ42iShdPimej 2OBBgyO59uV/++8bbec/y2AcljnmI/qEb0oCab/BehiHMpnQXhr0uxXzjo25Yrn4Oq Q/3/G1RtCUn6CjTjzcoVQucqgPzi3HZQRwqfyo2I= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107986] [12/13 Regression] Bogus -Warray-bounds diagnostic with std::sort Date: Tue, 06 Dec 2022 07:43:32 +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: 12.2.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: blocked cc keywords 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=3D107986 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |85316 CC| |aldyh at gcc dot gnu.org Keywords| |missed-optimization --- Comment #1 from Richard Biener --- One of the reasons we diagnose this is that we fail to compute a range for 'qa_7'. Before the VRP pass that diagnoses the -Warray-bounds violatio= n we have [local count: 1073741824]: # qa_7 =3D PHI <0(2), qa_6(5)> # RANGE [irange] int [0, 3] NONZERO 0x3 # i_8 =3D PHI <0(2), i_16(5)> if (i_8 !=3D 3) goto ; [75.00%] else goto ; [25.00%] [local count: 268435456]: # RANGE [irange] long unsigned int [0, 2147483647][18446744071562067968, +INF] _3 =3D (long unsigned int) qa_7; # RANGE [irange] long unsigned int [0, 8589934588][18446744065119617024, 18446744073709551612] NONZERO 0xfffffffffffffffc _4 =3D _3 * 4; # PT =3D { D.18799 } (escaped) # ALIGN =3D 4, MISALIGN =3D 0 _5 =3D &a + _4; if (&a !=3D _5) goto ; [53.47%] else goto ; [46.53%] [local count: 143532440]: _11 =3D (signed long) _4; # RANGE [irange] long int [-2305843009213693952, 2305843009213693951] _20 =3D _11 /[ex] 4; # RANGE [irange] long unsigned int [0, 2305843009213693951][16140901064495857664, +INF] __n.3_21 =3D (long unsigned int) _20; # RANGE [irange] int [0, 63] NONZERO 0x3f _22 =3D __builtin_clzl (__n.3_21); # RANGE [irange] int [0, 63] NONZERO 0x3f _23 =3D 63 - _22; # RANGE [irange] long int [0, 63] NONZERO 0x3f _24 =3D (long int) _23; # RANGE [irange] long int [0, 126] NONZERO 0x7e _25 =3D _24 * 2; # USE =3D nonlocal escaped null { D.18799 } (escaped) # CLB =3D nonlocal escaped null { D.18799 } (escaped) std::__introsort_loop.isra (&a, _5, _25); if (_11 > 64) goto ; [50.00%] else goto ; [50.00%] and we fail to eliminate this last conditional. We also fail to eliminate the (long)(((unsigned long)qa_37) * 4) /[ex] 4 round-trip (because of possible overflow). So even proving qa_7 is [0, +INF] would help a bit (not the diagnostic), realizing qa_7 is [0, 3] like i_8 would be even better. A testcase for this could look like void bar (); void foo (int *a) { int qa =3D 0; for (int i =3D 0; i < 3; i++) if (a[i]) a[qa++] =3D 0; if (qa > 3) bar (); } where we should be able to eliminate the call to bar (). Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D85316 [Bug 85316] [meta-bug] VRP range propagation missed cases=