From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B2E13858D32; Mon, 27 Feb 2023 02:51:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B2E13858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677466284; bh=DwpEWTHHVA73tO7+5veSP9gOD/dQiA1ltoQlkP06mwk=; h=From:To:Subject:Date:From; b=mMlEjzACAs5OcXS+56Ktv0zZttUbEYao7yDjvGgcx2lGmGQ1hqbpstCijZ0iYF1Jf q9nrJHLcOR35SNqZQ90VRDa/0r52UuATP5X5/PtuT5w+T5cF4JmG5W/xJBC2Eq11Wh mxjFJu6A+astNUjNH7oxFx6p3eefnkjvI/baDShc= From: "crazylht at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108938] New: Missing bswap detection Date: Mon, 27 Feb 2023 02:51:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: crazylht at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D108938 Bug ID: 108938 Summary: Missing bswap detection Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: crazylht at gmail dot com Target Milestone: --- This is the x86 version of this bug. +++ This bug was initially created as a clone of Bug #108874 +++ If we look at the arm testcases in gcc.target/arm/rev16.c typedef unsigned int __u32; __u32 __rev16_32_alt (__u32 x) { return (((__u32)(x) & (__u32)0xff00ff00UL) >> 8) | (((__u32)(x) & (__u32)0x00ff00ffUL) << 8); } __u32 __rev16_32 (__u32 x) { return (((__u32)(x) & (__u32)0x00ff00ffUL) << 8) | (((__u32)(x) & (__u32)0xff00ff00UL) >> 8); } we should be able to generate bswap instructions for x86 GCC fails to do so and generates: __rev16_32_alt(unsigned int): mov eax, edi sal edi, 8 shr eax, 8 and edi, -16711936 and eax, 16711935 or eax, edi ret __rev16_32(unsigned int): mov eax, edi shr edi, 8 sal eax, 8 and edi, 16711935 and eax, -16711936 or eax, edi ret whereas clang manages to recognise it all into: __rev16_32_alt(unsigned int): # @__rev16_32_alt(unsigned int) mov eax, edi bswap eax ror eax, 16 ret __rev16_32(unsigned int): # @__rev16_32(unsigned int) mov eax, edi bswap eax ror eax, 16 ret=