From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 020213858416; Sat, 4 Dec 2021 22:41:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 020213858416 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103542] [10/11/12 Regregression] bogus -Warray-bounds while index is limited by switch/case Date: Sat, 04 Dec 2021 22:41:06 +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: 11.2.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor 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: 10.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: keywords blocked cc 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: Sat, 04 Dec 2021 22:41:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103542 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Blocks| |56456 CC| |msebor at gcc dot gnu.org --- Comment #2 from Martin Sebor --- The IL for the function is below. It seems quite inefficient compared to G= CC 9. void get_default_config.part.0 (const uint32_t id) { uint32_t error; uint32_t entry; unsigned int _4; uint32_t * _5; [local count: 118111600]: goto ; [100.00%] [local count: 955630225]: entry_2 =3D entry_1 + 1; [local count: 1073741824]: # entry_1 =3D PHI _4 =3D config[id_3(D)].num_apples; if (entry_1 < _4) goto ; [89.00%] else goto ; [11.00%] [local count: 118111600]: config[id_3(D)].num_apples =3D 0; _5 =3D &config[id_3(D)].num_lemons; switch (id_3(D)) [20.00%], case 0: [20.00%], case 1: = [20.00%], case 2: [20.00%], case 3: [20.00%]> [local count: 23622320]: : MEM [(uint32_t *)&config][0].num_lemons =3D 0; goto ; [100.00%] [local count: 23622320]: : MEM [(uint32_t *)&config][1].num_lemons =3D 0; goto ; [100.00%] [local count: 23622320]: : MEM [(uint32_t *)&config][2].num_lemons =3D 0; goto ; [100.00%] [local count: 23622320]: : MEM [(uint32_t *)&config][3].num_lemons =3D 0; goto ; [100.00%] [local count: 23622320]: : MEM [(uint32_t *)&config][id_3(D)].num_lemons = =3D 0;=20=20 <<< -Warray-bounds [local count: 118111602]: # error_14 =3D PHI <0(7), 255(10), 0(6), 0(9), 0(8)> config[id_3(D)].num_lemons =3D 0; config[id_3(D)].lemons =3D 0B; foo (0); return; } In GCC 9 both the function and the final assembly are much more compact: et_default_config.part.0 (const uint32_t id) { struct fruit_config[4] * _2; sizetype _13; sizetype _14; [local count: 118111601]: _13 =3D (sizetype) id_3(D); _14 =3D _13 * 16; _2 =3D &config + _14; MEM[(unsigned int *)_2] =3D 0; config[id_3(D)].lemons =3D 0B; foo (0); [tail call] return; } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D56456 [Bug 56456] [meta-bug] bogus/missing -Warray-bounds=