From patchwork Thu Feb 28 20:20:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 224181 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 8875A2C02A1 for ; Fri, 1 Mar 2013 07:21:13 +1100 (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=1362687674; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=LAkdQ8i z13NWT6o94K8FFkvenz0=; b=dCJCib984appZa6fEnNoh/W7b+TvJqClsz8Tfa6 TZywq/NkkrQDuJomRs4Zfw8YYPuoP0Is8/hOf/nEWwpayQmkNMRRx3E91sIB5qXK 4ONwit/3D70I+IP/M1l615oO6jDxv5N7wvo5ikqO2CAqCRwO7+XZGBG4hctqph6j VNHM= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=I4+XsLFLe1CjkTN9X52R6e0f61VGyKq6NEPOnz6AQp0iJr4qgpdQCM3V4jaRE1 L75fzHJRvGjJC8b8h42J3CufjmA9j+9BGkEFTw3cGMtPcwWSf+z67JdXxZZ6gEvq fMfPazr8irIP8fSK69gsbgE0oCS+yAxFW4n4/jjf/FspE=; Received: (qmail 25889 invoked by alias); 28 Feb 2013 20:21:04 -0000 Received: (qmail 25875 invoked by uid 22791); 28 Feb 2013 20:21:02 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 28 Feb 2013 20:20:52 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1SKKp11012062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Feb 2013 15:20:52 -0500 Received: from [10.3.113.60] (ovpn-113-60.phx2.redhat.com [10.3.113.60]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1SKKpo9006360 for ; Thu, 28 Feb 2013 15:20:51 -0500 Message-ID: <512FBC23.5030507@redhat.com> Date: Thu, 28 Feb 2013 15:20:51 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56481 (time hog with repeated &&) 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 The problem with this testcase was that for a repeated &&, each call of potential_constant_expression_1 led to two calls for the LHS, giving it O(N^2) complexity. Fixed by avoiding the redundant call in maybe_constant_value by calling cxx_eval_outermost_constant_expr directly. Tested x86_64-pc-linux-gnu, applying to trunk. commit 001c03d979ea1aaa9bc9565f2b9c82371cc481f1 Author: Jason Merrill Date: Thu Feb 28 12:30:40 2013 -0500 PR c++/56481 * semantics.c (potential_constant_expression_1): Use cxx_eval_outermost_constant_expr rather than maybe_constant_value. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 9446f83..8038aa2 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8683,10 +8683,12 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) case ROUND_MOD_EXPR: { tree denom = TREE_OPERAND (t, 1); - /* We can't call maybe_constant_value on an expression + if (!potential_constant_expression_1 (denom, rval, flags)) + return false; + /* We can't call cxx_eval_outermost_constant_expr on an expression that hasn't been through fold_non_dependent_expr yet. */ if (!processing_template_decl) - denom = maybe_constant_value (denom); + denom = cxx_eval_outermost_constant_expr (denom, true); if (integer_zerop (denom)) { if (flags & tf_error) @@ -8696,7 +8698,8 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) else { want_rval = true; - goto binary; + return potential_constant_expression_1 (TREE_OPERAND (t, 0), + want_rval, flags); } } @@ -8731,7 +8734,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) if (!potential_constant_expression_1 (op, rval, flags)) return false; if (!processing_template_decl) - op = maybe_constant_value (op); + op = cxx_eval_outermost_constant_expr (op, true); if (tree_int_cst_equal (op, tmp)) return potential_constant_expression_1 (TREE_OPERAND (t, 1), rval, flags); else @@ -8793,7 +8796,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) if (!potential_constant_expression_1 (tmp, rval, flags)) return false; if (!processing_template_decl) - tmp = maybe_constant_value (tmp); + tmp = cxx_eval_outermost_constant_expr (tmp, true); if (integer_zerop (tmp)) return potential_constant_expression_1 (TREE_OPERAND (t, 2), want_rval, flags);