From patchwork Fri Dec 12 05:56:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 420372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B0D34140079 for ; Fri, 12 Dec 2014 16:56:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=w3fnuOvDmhIi44JP FeWNRkwe52VjcLFAhf5A2zlKjLL+0zpDy8/2db9cRwdpEzM/dwZEsarNYVK5/WMl 5EI9KPw8PAINQkpoXd9q/Nhsj6SFm0FMoEh2pwc1y+lEG4uR+I43C3fse5XrquBG DyFbAXyOO40mkJqCEnanQNxuLhI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=tJ0fAA7PY7LJaJkzrWmoyB hAoKM=; b=X1qgAHjqDr6zV4HNPF84xZ5CthG/HEl88JwnVuj9GefwxzUBlf0LWI 8M8QQJZFQ2sTz6JiyjwcWjMMbPrBhRGL45Jnr86GkLlOzWOnYsekEBrdFuEMPpTc 8wbgTjZw69Lc/fwYYn8D8DUYYPkeRZRiU4/j/1WlDkTZEvNw1Dq80= Received: (qmail 10574 invoked by alias); 12 Dec 2014 05:56:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10564 invoked by uid 89); 12 Dec 2014 05:56:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Dec 2014 05:56:26 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by service87.mimecast.com; Fri, 12 Dec 2014 05:56:23 +0000 Received: from shawin003 ([10.164.2.24]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 12 Dec 2014 05:56:22 +0000 From: "Zhenqiang Chen" To: "'Richard Henderson'" Cc: Subject: [Committed] [PATCH, ifcvt] Fix PR63917 Date: Fri, 12 Dec 2014 13:56:09 +0800 Message-ID: <000001d015d0$54b8ea50$fe2abef0$@arm.com> MIME-Version: 1.0 X-MC-Unique: 114121205562302301 X-IsSubscribed: yes > -----Original Message----- > From: Richard Henderson [mailto:rth@redhat.com] > Sent: Wednesday, December 10, 2014 8:55 AM > To: Zhenqiang Chen > Cc: gcc-patches@gcc.gnu.org > Subject: Re: [Ping] [PATCH, ifcvt] Fix PR63917 > > On 12/04/2014 05:16 PM, Zhenqiang Chen wrote: > > +static rtx > > +cc_in_cond (rtx cond) > > +{ > > + if ((HAVE_cbranchcc4) && cond > > Silly parens around the HAVE_cbranchcc4. Removed. > > + && (GET_MODE_CLASS (GET_MODE (XEXP (cond, 0))) == MODE_CC)) > > More silly parens around the ==. Removed. > > + /* Skip it if the instruction to be moved might clobber CC. */ > > + cc = cc_in_cond (cond); > > + if (cc) > > + if (set_of (cc, insn_a) > > + || (insn_b && set_of (XEXP (cond, 0), insn_b))) > > + return FALSE; > > Don't nest if's when an && will do; if the && won't do, always use braces. > > It looks like the insn_b test can be simpler, since the non-null return from > cc_in_cond is always XEXP (cond, 0). > > So: > > if (cc > && (set_of (cc, insn_a) > || (insn_b && set_of (cc, insn_b))) > return FALSE; > > Ok with those changes. Updated and committed @r218658. Here is the final patch. Index: gcc/ifcvt.c =================================================================== --- gcc/ifcvt.c (revision 218657) +++ gcc/ifcvt.c (working copy) @@ -1016,6 +1016,18 @@ 0, 0, outmode, y); } +/* Return the CC reg if it is used in COND. */ + +static rtx +cc_in_cond (rtx cond) +{ + if (HAVE_cbranchcc4 && cond + && GET_MODE_CLASS (GET_MODE (XEXP (cond, 0))) == MODE_CC) + return XEXP (cond, 0); + + return NULL_RTX; +} + /* Return sequence of instructions generated by if conversion. This function calls end_sequence() to end the current stream, ensures that are instructions are unshared, recognizable non-jump insns. @@ -1026,6 +1038,7 @@ { rtx_insn *insn; rtx_insn *seq = get_insns (); + rtx cc = cc_in_cond (if_info->cond); set_used_flags (if_info->x); set_used_flags (if_info->cond); @@ -1040,7 +1053,9 @@ allows proper placement of required clobbers. */ for (insn = seq; insn; insn = NEXT_INSN (insn)) if (JUMP_P (insn) - || recog_memoized (insn) == -1) + || recog_memoized (insn) == -1 + /* Make sure new generated code does not clobber CC. */ + || (cc && set_of (cc, insn))) return NULL; return seq; @@ -2544,6 +2559,7 @@ rtx_insn *insn_a, *insn_b; rtx set_a, set_b; rtx orig_x, x, a, b; + rtx cc; /* We're looking for patterns of the form @@ -2655,6 +2671,13 @@ if_info->a = a; if_info->b = b; + /* Skip it if the instruction to be moved might clobber CC. */ + cc = cc_in_cond (cond); + if (cc + && (set_of (cc, insn_a) + || (insn_b && set_of (cc, insn_b)))) + return FALSE; + /* Try optimizations in some approximation of a useful order. */ /* ??? Should first look to see if X is live incoming at all. If it isn't, we don't need anything but an unconditional set. */ @@ -2811,6 +2834,7 @@ rtx cond) { rtx_insn *insn; + rtx cc = cc_in_cond (cond); /* We can only handle simple jumps at the end of the basic block. It is almost impossible to update the CFG otherwise. */ @@ -2868,6 +2892,10 @@ && modified_between_p (src, insn, NEXT_INSN (BB_END (bb)))) return FALSE; + /* Skip it if the instruction to be moved might clobber CC. */ + if (cc && set_of (cc, insn)) + return FALSE; + vals->put (dest, src); regs->safe_push (dest); Index: gcc/testsuite/gcc.dg/pr64007.c =================================================================== --- gcc/testsuite/gcc.dg/pr64007.c (revision 0) +++ gcc/testsuite/gcc.dg/pr64007.c (revision 0) @@ -0,0 +1,50 @@ +/* { dg-options " -O3 " } */ +/* { dg-do run } */ + +#include + +int d, i; + +struct S +{ + int f0; +} *b, c, e, h, **g = &b; + +static struct S *f = &e; + +int +fn1 (int p) +{ + int a = 0; + return a || p < 0 || p >= 2 || 1 >> p; +} + +int +main () +{ + int k = 1, l, *m = &c.f0; + + for (;;) + { + l = fn1 (i); + *m = k && i; + if (l) + { + int n[1] = {0}; + } + break; + } + + *g = &h; + + assert (b); + + if (d) + (*m)--; + d = (f != 0) | (i >= 0); + + if (c.f0 != 0) + __builtin_abort (); + + return 0; +}