From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42311 invoked by alias); 20 Sep 2015 06:05:39 -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 42223 invoked by uid 48); 20 Sep 2015 06:05:35 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/67646] New: [SH] Improve sign extract of bit test Date: Sun, 20 Sep 2015 06:05:00 -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: unknown 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone cf_gcctarget 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-09/txt/msg01574.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67646 Bug ID: 67646 Summary: [SH] Improve sign extract of bit test Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: olegendo at gcc dot gnu.org Target Milestone: --- Target: sh*-*-* The following: unsigned int test (unsigned int x) { return (x & 0x30) ? ~0 : 0; } compiled with -m4 -ml -O2 results in: mov r4,r0 tst #48,r0 subc r0,r0 rts not r0,r0 This is already minimal, but in some cases addc can be used: mov r4,r0 tst #48,r0 mov #0,r1 mov #-1,r0 addc r1,r0 r0 = 0 + (-1) + T T = 0: r0 = 0 + (-1) + 0 = -1 T = 1: r0 = 0 + (-1) + 1 = 0 If the constant 0 can be shared with some other insn, this would result in a mov #imm8, addc sequence, which is good for SH4A, because mov #imm8 is an MT group insn. If the test constant is only one bit: unsigned int test (unsigned int x) { return (x & 0x20) ? ~0 : 0; } -m4 -ml -O2: mov r4,r0 tst #32,r0 mov #-1,r0 negc r0,r0 rts neg r0,r0 This should result in the same code as for the constant 0x30.