From patchwork Thu Jul 26 02:25:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 173317 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 E9C4B2C0091 for ; Thu, 26 Jul 2012 12:25:21 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343874322; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=s6n18z2nUoPcxSN8vzgAcGYcoHo=; b=x/oYVbHhQJlEEmYnhGRsAuFr7/ad2eaujuGSTknainXudJ+fVLcyvcWmBS2NcL NCJLKIj79nuURUEgEuz4gVQWUIAokLI8IBbqrIASBw7ciCtGNDCUj1Mv7OWJ/oa5 beGrREjLLiX7n7/ovnIopNmVIgI625h3ofRLKRMLRFupk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=N5JwCxa8XsEXTK0Osr6DD5GSiP1I+dVzqV2AFbtoDx1H6i9mEDSm7etkIUXfW/ eVNfafnrqD8WQbcOBDV3G734Mt28qRdWZvNwJt8g31GIIyGKEVjZmN0T9cj1eNzA DbOAbirKlY/0bwkgrko/To57w0DzK14ABvnPpdFdoPUS8=; Received: (qmail 13342 invoked by alias); 26 Jul 2012 02:25:18 -0000 Received: (qmail 13327 invoked by uid 22791); 26 Jul 2012 02:25:15 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Jul 2012 02:24:55 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1SuDl0-000222-8W from Sandra_Loosemore@mentor.com ; Wed, 25 Jul 2012 19:24:54 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 25 Jul 2012 19:24:53 -0700 Received: from [IPv6:::1] (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.1.289.1; Wed, 25 Jul 2012 19:24:53 -0700 Message-ID: <5010AA7E.7000608@codesourcery.com> Date: Wed, 25 Jul 2012 20:25:02 -0600 From: Sandra Loosemore User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Paolo Bonzini CC: , Andrew Jenner Subject: Re: [PATCH] Detect loops in find_comparison_args References: <500F02E3.5080804@codesourcery.com> <500F9FE5.5040302@gnu.org> In-Reply-To: <500F9FE5.5040302@gnu.org> 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 On 07/25/2012 01:27 AM, Paolo Bonzini wrote: > > What I'm worried about is the extra cost of malloc-ing and free-ing the > pointer set. Perhaps you can skip the pointer set creation in the common > case where find_comparison_args does not iterate? Something like this: > > [snip] I think this version is a little neater; it just defers initialization of the pointer set to the end of the loop. I checked the test case on the two targets where we've previously observed failures (the original one on MIPS and the current one on PowerPC), as well as doing a full bootstrap and regression-test on x86_64. OK to check in? -Sandra 2012-07-25 Andrew Jenner Sandra Loosemore gcc/ * cse.c (find_comparison_args): Check for cycles of any length. gcc/testsuite/ * gcc.c-torture/compile/pr50380.c: Add code to cause cycle of length 2. Index: gcc/cse.c =================================================================== --- gcc/cse.c (revision 189859) +++ gcc/cse.c (working copy) @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. #include "tree-pass.h" #include "df.h" #include "dbgcnt.h" +#include "pointer-set.h" /* The basic idea of common subexpression elimination is to go through the code, keeping a record of expressions that would @@ -2897,6 +2898,7 @@ find_comparison_args (enum rtx_code code enum machine_mode *pmode1, enum machine_mode *pmode2) { rtx arg1, arg2; + struct pointer_set_t *visited = NULL; arg1 = *parg1, arg2 = *parg2; @@ -2985,10 +2987,8 @@ find_comparison_args (enum rtx_code code if (! exp_equiv_p (p->exp, p->exp, 1, false)) continue; - /* If it's the same comparison we're already looking at, skip it. */ - if (COMPARISON_P (p->exp) - && XEXP (p->exp, 0) == arg1 - && XEXP (p->exp, 1) == arg2) + /* If it's a comparison we've used before, skip it. */ + if (visited && pointer_set_contains (visited, p->exp)) continue; if (GET_CODE (p->exp) == COMPARE @@ -3062,6 +3062,10 @@ find_comparison_args (enum rtx_code code else if (COMPARISON_P (x)) code = GET_CODE (x); arg1 = XEXP (x, 0), arg2 = XEXP (x, 1); + + if (!visited) + visited = pointer_set_create (); + pointer_set_insert (visited, x); } /* Return our results. Return the modes from before fold_rtx @@ -3069,6 +3073,8 @@ find_comparison_args (enum rtx_code code *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2); *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0); + if (visited) + pointer_set_destroy (visited); return code; } Index: gcc/testsuite/gcc.c-torture/compile/pr50380.c =================================================================== --- gcc/testsuite/gcc.c-torture/compile/pr50380.c (revision 189859) +++ gcc/testsuite/gcc.c-torture/compile/pr50380.c (working copy) @@ -1,12 +1,22 @@ -/* This test used to get stuck in an infinite loop in find_comparison_args - when compiling for MIPS at -O2. */ - __attribute__ ((__noreturn__)) extern void fail (void); char x; +/* This used to get stuck in an infinite loop in find_comparison_args + when compiling this function for MIPS at -O2. */ + void foo (const unsigned char y) { ((void) (__builtin_expect((!! y == y), 1) ? 0 : (fail (), 0))); x = ! y; } + +/* This used to similarly get stuck when compiling for PowerPC at -O2. */ + +int foo2 (int arg) +{ + if (arg != !arg) + fail (); + if (arg) + fail (); +}