From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68908 invoked by alias); 14 Mar 2015 14:31:34 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 68874 invoked by uid 48); 14 Mar 2015 14:31:31 -0000 From: "fuz at fuz dot su" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/65424] New: gcc does not recognize byte swaps implemented as loop. Date: Sat, 14 Mar 2015 14:31:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fuz at fuz dot su X-Bugzilla-Status: UNCONFIRMED 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 attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg01478.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65424 Bug ID: 65424 Summary: gcc does not recognize byte swaps implemented as loop. Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fuz at fuz dot su Created attachment 35034 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35034&action=edit endianess-aware reading / writing macros gcc (r221432) is able to recognize the following code and implements it with either a bswap or a straight load on x86. #include extern uint32_t rbe32(const uint8_t a[4]) { uint32_t x = 0; x |= a[0] << 24; x |= a[1] << 16; x |= a[2] << 8; x |= a[3] << 0; return x; } extern uint32_t rle32(const uint8_t a[4]) { uint32_t x = 0; x |= a[0] << 0; x |= a[1] << 8; x |= a[2] << 16; x |= a[3] << 24; return x; } it isn't able to recognize the following two functions which yield identical results: extern uint32_t rle32(const uint8_t a[4]) { int i; uint32_t x = 0; for (i = 0; i < 4; i++) x |= a[i] << 8 * i; return x; } extern uint32_t rbe32(const uint8_t a[4]) { int i; uint32_t x = 0; for (i = 0; i < 4; i++) x |= a[i] << 8 * (3 - i); return x; } It would be great if gcc was able to recognize these implementations of endianess-aware reads; this kind of code is produced by macros I use to generate a bunch of read / write functions for differently sized types. Attached is a file containing the macros I want to use.