public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/104151] [9/10/11/12 Regression] x86: excessive code generated for 128-bit byteswap Date: Fri, 28 Jan 2022 12:20:08 +0000 [thread overview] Message-ID: <bug-104151-4-MOwSCsHREk@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-104151-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104151 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> --- With -O3 it regresses with r7-2009-g8d4fc2d3d0c8f87bb3e182be1a618a511f8f9465 __uint128_t bswap(__uint128_t a) { return __builtin_bswap128 (a); } emits the optimal code but is only in GCC 11.1 and later. One fix for this might be to handle _8 = BIT_FIELD_REF <a_3(D), 64, 64>; _1 = __builtin_bswap64 (_8); y[0] = _1; _10 = BIT_FIELD_REF <a_3(D), 64, 0>; _2 = __builtin_bswap64 (_10); y[1] = _2; _7 = MEM <uint128_t> [(char * {ref-all})&y]; in bswap or store merging. Though, current bswap infrastructure I'm afraid limits it to 64-bit size, because it tracks the bytes in uint64_t vars and uses 8 bits to determine which byte it is (0 value of zero, 1-8 byte index and 0xff unknown). While that is 10 different values right now, if we handled uint128_t we'd need 18 different values times 16. Note, even: unsigned long long bswap (unsigned long long a) { unsigned int x[2]; __builtin_memcpy (x, &a, 8); unsigned int y[2]; y[0] = __builtin_bswap32 (x[1]); y[1] = __builtin_bswap32 (x[0]); __builtin_memcpy (&a, y, 8); return a; } unsigned long long bswap2 (unsigned long long a) { return __builtin_bswap64 (a); } emits better code in the latter function rather than former store-merging isn't able to handle even that. So we want to handle it in store-merging, we should start with handling _8 = BIT_FIELD_REF <a_3(D), 32, 32>; _1 = __builtin_bswap32 (_8); _10 = (unsigned int) a_3(D); _2 = __builtin_bswap32 (_10); _11 = {_1, _2}; _5 = VIEW_CONVERT_EXPR<unsigned long>(_11); and _8 = BIT_FIELD_REF <a_3(D), 32, 32>; _1 = __builtin_bswap32 (_8); y[0] = _1; _10 = (unsigned int) a_3(D); _2 = __builtin_bswap32 (_10); y[1] = _2; _7 = MEM <unsigned long> [(char * {ref-all})&y]; and only once that is handled try _8 = BIT_FIELD_REF <a_3(D), 64, 64>; _1 = __builtin_bswap64 (_8); _10 = (long long unsigned int) a_3(D); _2 = __builtin_bswap64 (_10); _11 = {_1, _2}; _5 = VIEW_CONVERT_EXPR<uint128_t>(_11); Doesn't look like stage4 material though. So in the meantime perhaps some other improvements.
next prev parent reply other threads:[~2022-01-28 12:20 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-20 23:24 [Bug target/104151] New: " nekotekina at gmail dot com 2022-01-20 23:41 ` [Bug middle-end/104151] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org 2022-01-21 1:03 ` crazylht at gmail dot com 2022-01-21 1:25 ` crazylht at gmail dot com 2022-01-21 1:28 ` crazylht at gmail dot com 2022-01-21 1:32 ` crazylht at gmail dot com 2022-01-21 8:28 ` rguenth at gcc dot gnu.org 2022-01-21 9:11 ` rsandifo at gcc dot gnu.org 2022-01-21 10:18 ` rguenth at gcc dot gnu.org 2022-01-21 10:29 ` rguenth at gcc dot gnu.org 2022-01-21 12:20 ` ubizjak at gmail dot com 2022-01-28 12:20 ` jakub at gcc dot gnu.org [this message] 2022-01-31 14:06 ` ubizjak at gmail dot com 2022-05-06 8:32 ` [Bug middle-end/104151] [9/10/11/12/13 " jakub at gcc dot gnu.org 2022-09-06 22:04 ` [Bug middle-end/104151] [10/11/12/13 " pobrn at protonmail dot com 2022-09-07 8:18 ` rguenth at gcc dot gnu.org 2023-05-08 12:23 ` [Bug middle-end/104151] [10/11/12/13/14 " rguenth at gcc dot gnu.org 2023-05-11 13:17 ` chfast at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-104151-4-MOwSCsHREk@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).