From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26926 invoked by alias); 2 Nov 2012 09:59:46 -0000 Received: (qmail 26896 invoked by uid 48); 2 Nov 2012 09:59:32 -0000 From: "dwmw2 at infradead dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/55177] New: Missed optimisation: bswap, mask with constant, bswap back again. Date: Fri, 02 Nov 2012 09:59: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dwmw2 at infradead dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-11/txt/msg00123.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55177 Bug #: 55177 Summary: Missed optimisation: bswap, mask with constant, bswap back again. Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: dwmw2@infradead.org extern int x; void foo(void) { int a = __builtin_bswap32(x); a &= 0x5a5b5c5d; x = __builtin_bswap32(a); } With GCC 4.7.2 (x86_64 Fedora) this compiles to: foo: .LFB0: .cfi_startproc movl x(%rip), %eax bswap %eax andl $-1515936861, %eax bswap %eax movl %eax, x(%rip) ret .cfi_endproc Surely the actual swap should be optimised out, and the 0x5a5b5c5d constant mask should be swapped instead so we just load, mask with 0x5d5c5b5a and store without any runtime swapping? (See also PR42586 which may be related)