From patchwork Fri Sep 30 15:21:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Zhuykov X-Patchwork-Id: 117155 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]) by ozlabs.org (Postfix) with SMTP id 306C4B6F62 for ; Sat, 1 Oct 2011 01:21:49 +1000 (EST) Received: (qmail 3678 invoked by alias); 30 Sep 2011 15:21:46 -0000 Received: (qmail 3665 invoked by uid 22791); 30 Sep 2011 15:21:45 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Sep 2011 15:21:31 +0000 Received: by yxj17 with SMTP id 17so1943498yxj.20 for ; Fri, 30 Sep 2011 08:21:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.9.37 with SMTP id w5mr58714520pba.97.1317396090635; Fri, 30 Sep 2011 08:21:30 -0700 (PDT) Received: by 10.68.41.3 with HTTP; Fri, 30 Sep 2011 08:21:30 -0700 (PDT) In-Reply-To: References: <1311265834-2144-1-git-send-email-zhroma@ispras.ru> <1311265834-2144-3-git-send-email-zhroma@ispras.ru> Date: Fri, 30 Sep 2011 19:21:30 +0400 Message-ID: Subject: Re: [PATCH 2/9] [doloop] Correct extracting loop exit condition From: Roman Zhuykov To: zhroma@ispras.ru, gcc-patches@gcc.gnu.org, dm@ispras.ru, richard.sandiford@linaro.org X-IsSubscribed: yes 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 2011/7/22 Richard Sandiford : > zhroma@ispras.ru writes: >> This patch fixes the compiler segfault found while regtesting trunk with SMS on >> IA64 platform.  Segfault happens on test gcc.dg/pr45259.c with -fmodulo-sched >> enabled.  The following jump instruction is given as argument for >> doloop_condition_get function: >> (jump_insn 86 85 88 7 (set (pc) >>         (reg/f:DI 403)) 339 {indirect_jump} >>      (expr_list:REG_DEAD (reg/f:DI 403) >>         (nil))) >> The patch adds checking for the form of comparison instruction before >> extracting loop exit condition. >> >> 2011-07-20  Roman Zhuykov   >>       * loop-doloop.c (doloop_condition_get): Correctly check >>       the form of comparison instruction. >> --- >>  gcc/loop-doloop.c |    2 ++ >>  1 files changed, 2 insertions(+), 0 deletions(-) >> >> diff --git a/gcc/loop-doloop.c b/gcc/loop-doloop.c >> index f8429c4..dfc4a16 100644 >> --- a/gcc/loop-doloop.c >> +++ b/gcc/loop-doloop.c >> @@ -153,6 +153,8 @@ doloop_condition_get (rtx doloop_pat) >>        else >>          inc = PATTERN (prev_insn); >>        /* We expect the condition to be of the form (reg != 0)  */ >> +      if (GET_CODE (cmp) != SET || GET_CODE (SET_SRC (cmp)) != IF_THEN_ELSE) >> +     return 0; >>        cond = XEXP (SET_SRC (cmp), 0); >>        if (GET_CODE (cond) != NE || XEXP (cond, 1) != const0_rtx) >>          return 0; > > I think it'd be better to integrate: > >      /* We expect the condition to be of the form (reg != 0)  */ >      cond = XEXP (SET_SRC (cmp), 0); >      if (GET_CODE (cond) != NE || XEXP (cond, 1) != const0_rtx) >        return 0; > > into: > >  /* We expect a GE or NE comparison with 0 or 1.  */ >  if ((GET_CODE (condition) != GE >       && GET_CODE (condition) != NE) >      || (XEXP (condition, 1) != const0_rtx >          && XEXP (condition, 1) != const1_rtx)) >    return 0; > > The next "if" already uses "GET_CODE (pattern) != PARALLEL" as a check > for the second and third cases.  E.g. something like: > >  if (GET_CODE (pattern) == PARALLEL) >    { >      /* We expect a GE or NE comparison with 0 or 1.  */ >      if ((GET_CODE (condition) != GE >           && GET_CODE (condition) != NE) >          || (XEXP (condition, 1) != const0_rtx >              && XEXP (condition, 1) != const1_rtx)) >        return 0; >    } >  else >    { >      /* In the second and third cases, we expect the condition to >         be of the form (reg != 0)  */ >      if (GET_CODE (condition) != NE || XEXP (condition, 1) != const0_rtx) >        return 0; >    } > > That's pre-approved (independently of the other patches) if it works. Changed like the following. Will commit if no objections after a couple of days. --- Roman Zhuykov zhroma@ispras.ru 2011-09-30 Roman Zhuykov * loop-doloop.c (doloop_condition_get): Correctly check the form of comparison instruction. --- gcc/loop-doloop.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gcc/loop-doloop.c b/gcc/loop-doloop.c index a7e264f..4e83649 100644 --- a/gcc/loop-doloop.c +++ b/gcc/loop-doloop.c @@ -113,7 +113,6 @@ doloop_condition_get (rtx doloop_pat) if (GET_CODE (pattern) != PARALLEL) { - rtx cond; rtx prev_insn = prev_nondebug_insn (doloop_pat); rtx cmp_arg1, cmp_arg2; rtx cmp_orig; @@ -152,10 +151,6 @@ doloop_condition_get (rtx doloop_pat) } else inc = PATTERN (prev_insn); - /* We expect the condition to be of the form (reg != 0) */ - cond = XEXP (SET_SRC (cmp), 0); - if (GET_CODE (cond) != NE || XEXP (cond, 1) != const0_rtx) - return 0; } else { @@ -193,12 +188,23 @@ doloop_condition_get (rtx doloop_pat) /* Extract loop termination condition. */ condition = XEXP (SET_SRC (cmp), 0); - /* We expect a GE or NE comparison with 0 or 1. */ - if ((GET_CODE (condition) != GE - && GET_CODE (condition) != NE) - || (XEXP (condition, 1) != const0_rtx - && XEXP (condition, 1) != const1_rtx)) - return 0; + if (GET_CODE (pattern) == PARALLEL) + { + /* We expect a GE or NE comparison with 0 or 1. */ + if ((GET_CODE (condition) != GE + && GET_CODE (condition) != NE) + || (XEXP (condition, 1) != const0_rtx + && XEXP (condition, 1) != const1_rtx)) + return 0; + } + else + { + /* In the second and third cases, we expect the condition + to be of the form (reg != 0) */ + if (GET_CODE (condition) != NE + || XEXP (condition, 1) != const0_rtx) + return 0; + } if ((XEXP (condition, 0) == reg) /* For the third case: */