From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 81A943857B9D; Thu, 22 Sep 2022 07:08:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A943857B9D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663830488; bh=Y7R83qXOjmjq5YmV5kMNlxNc+TvCGHWJHVg4Y4XessE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=v8lIlrKEGACW/aUWQUYkCJhSHE5zKAv0Z9w0OwMDrRtyzjB7RLlR3nUNkD63zndH+ uNVlB3RnhqF020R8/XcXY++QEJqxCt0n5QMak1t7wuGRzNIT3kyUOoA5I6jjCHXxVd L3TNi8MPgCpK2M8MFtBY+LZSl0HVz0oRd1BDRZ8g= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107006] Missing optimization: common idiom for external data Date: Thu, 22 Sep 2022 07:08:08 +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.1 X-Bugzilla-Keywords: 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: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: component cf_reconfirmed_on everconfirmed bug_status 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=3D107006 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Component|rtl-optimization |tree-optimization Last reconfirmed| |2022-09-22 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Keywords| |missed-optimization --- Comment #10 from Richard Biener --- The reason is that the loops are not unrolled (early enough or at all) for = the bswap/load detection. So to work you have to unroll the loops manually or direct GCC to do that, for example inline uint64_t get_le64 (const unsigned char x[64/8]) { uint64_t y =3D 0; #pragma GCC unroll 8 for (size_t i =3D 0; i < sizeof y; i++) if (0) y |=3D (uint64_t)x[i] << ((sizeof y - 1 - i)*8); else y |=3D (uint64_t)x[i] << i*8; return y;=20 } produces get_le64: .LFB11: .cfi_startproc movq (%rdi), %rax ret the unroll heuristics do not anticipate that later bswap/load detection will merge all the loads and thus not grow code too much.=