From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22350 invoked by alias); 10 May 2014 13:03:23 -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 22285 invoked by uid 48); 10 May 2014 13:03:19 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/59239] [SH] Improve decrement-and-test insn Date: Sat, 10 May 2014 13:03: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.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: olegendo at gcc dot gnu.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-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-05/txt/msg00906.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59239 --- Comment #3 from Oleg Endo --- (In reply to Oleg Endo from comment #0) > > The decrement-and-test insn seems to rely on the define_peephole. At least > taking it out shows some missed opportunities in the CSiBE set. > I've tried replacing it with a define_peephole2, but it would still show > missed cases such as: > mov.l @(...), Rn > add #-1,Rn > mov.l Rn,@(...) > tst Rn,Rn This happens especially when the mems are volatile. An isolated example: int test (volatile int* x, int a, int b, int c, int d) { int xx = x[2] - 1; x[2] = xx; if (xx == 0) return a; return b + c; } Currently compiles to (-O2): mov.l @(8,r4),r1 add #-1,r1 mov.l r1,@(8,r4) tst r1,r1 bt .L5 mov r6,r5 add r7,r5 .L5: rts mov r5,r0 which could be: mov.l @(8,r4),r1 dt r1 mov.l r1,@(8,r4) bt .L5 mov r6,r5 add r7,r5 .L5: rts mov r5,r0 The problem seems that combine will not look across volatile mems when picking insns for combination. In this particular case it could be fixed by a manual combine step, i.e. make the cmpeqsi_t an insn_and_split and in the split pass after combine check the previous insns if they are a (plus (reg) (const_int -1)), then replace the insns if matched.