From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B25FE39B90BC; Thu, 19 Aug 2021 19:20:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B25FE39B90BC From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/86723] not optimizing with bswap, that casts to int aftwards Date: Thu, 19 Aug 2021 19:20:47 +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: 8.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jakub 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: 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: Thu, 19 Aug 2021 19:20:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D86723 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #5 from Jakub Jelinek --- It boils down to even simpler: int bar (unsigned long long value) { return ((value & 0x000000ff00000000ull) >> 8) | ((value & 0x0000ff0000000000ull) >> 24) | ((value & 0x00ff000000000000ull) >> 40) | ((value & 0xff00000000000000ull) >> 56); } which is what you get from #c2 after optimizations. The bswap pass tries to ATM recognize just nops - 0x0807060504030201 permutation markers - and full bswaps - 0x0102030405060708 permutations, where in those permutation bytes 0 - target byte has the value 0 FF - target byte has an unknown value (eg. due to sign extension) 1..size - marker value is the byte index in the source (0 for lsb). But we could very well handle also masked bswaps, either just those one can= get from zero extensions, so 0x0000000005060708 or 0x0000000000000708 etc., or generally with clearing of arbitrary bytes in it, say 0x0100030400060700 by doing __builtin_bswap64 (arg) & 0xff00ffff00ffff00ULL etc. Then this optimization would fall out from that, because we'd do (int) (__builtin_bswap64 (arg) & 0xffffffffULL) and further opts would opti= mize away the masking.=