From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13678 invoked by alias); 26 Aug 2014 17:12:50 -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 13637 invoked by uid 48); 26 Aug 2014 17:12:46 -0000 From: "oneill+gccbugs at cs dot hmc.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/62263] Good codegen for bitwise rotate requires code that is technically undefined behavior Date: Tue, 26 Aug 2014 17:12:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: oneill+gccbugs at cs dot hmc.edu 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: Message-ID: In-Reply-To: References: 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: 2014-08/txt/msg01785.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62263 --- Comment #6 from M.E. O'Neill --- (In reply to Marek Polacek from comment #3) > We handle at least > (x << n) | (x >> ((-n) & 31)) > (N can be 0 here) since PR57157. Although this code does work with LLVM, testing with GCC 4.9.0, and this implementation unsigned int rotl32_doubleand4(unsigned int v, unsigned char r) { return (v << (r & 31)) | (v >> ((-r) & 31)); } (or variations with r being a char or int) produces code like this: _rotl32_doubleand4: LFB6: movl %esi, %ecx movl %edi, %eax negl %ecx shrl %cl, %eax movl %esi, %ecx sall %cl, %edi orl %edi, %eax ret ... so it failed to spot the idiom entirely.