From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129637 invoked by alias); 20 Sep 2015 03:37:43 -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 126798 invoked by uid 48); 20 Sep 2015 03:36:48 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/52394] SH Target: SH2A defunct bitops Date: Sun, 20 Sep 2015 03:37:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.7.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: olegendo at gcc dot gnu.org 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: 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: 2015-09/txt/msg01569.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52394 --- Comment #2 from Oleg Endo --- The SH2A bitops seem to produce some of the insns, but it seems the generated code is either really bad (defeating the original purpose) or broken. For example: volatile struct { union { unsigned char BYTE; struct { unsigned char BIT7:1; unsigned char BIT6:1; unsigned char BIT5:1; unsigned char BIT4:1; unsigned char BIT3:1; unsigned char BIT2:1; unsigned char BIT1:1; unsigned char BIT0:1; } BIT; } ICR0; } USRSTR; int main (unsigned char a, unsigned char b, unsigned char c) { USRSTR.ICR0.BIT.BIT5 |= b & 1; return 0; } compiled with -m2a -mb -mbitops -O2: mov.l .L2,r2 // addr of USRSTR mov #1,r1 and r1,r5 // b & 1 mov #0,r0 bor.b #5,@(0,r2) // T |= (bit in mem) movt r7 // r7 = T mov.b @r2,r3 // load byte cmp/pl r7 // T = r7 mov #5,r7 movt r1 // r1 = T bclr #5,r3 // clear bit 5 of loaded byte shld r7,r1 // T << 5 or r3,r1 // OR bit mov.b r1,@r2 // write back rts/n It seems that this will produce funny results at the first bor.b insn because at function entry the T bit is undefined. The code should actually be something like this: mov.l .L2,r2 bld #0,r5 mov #0,r0 bor.b #5,@(0,r2) bst.b #5,@(0,r2)