From patchwork Thu Jul 12 07:07:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 942821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481401-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fhFPa0xV"; dkim-atps=neutral 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 41R6TS6Fy7z9s1R for ; Thu, 12 Jul 2018 17:07:55 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=mvuxaazKpJ+Ajr6m6rId+kjl2aNlV+42O8CTcUdmuG6b1D3ZqEAl4 jPemlorQqfz4QLM1em4nn6YNo1cW5qyhoH6ZGkTq4y1ona4m51rezyWrzE4l+bIh 1uoYx1JgFjJNquPROyXqimhEProbEyFjX67hakxwZvxKpyBR7zy+bc= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=WXHjj8REwVvQ87vEf4z9XUkdisg=; b=fhFPa0xVP56XJvhLNz/I FyplE38QdsI+b9HwixGO5QOcSGsiv1Btyi0FRpbVjkbJZYXUbcGzeJFg1qpyjXIs RNX41eZ54Hb4Pm07lBxEvHWsHMJc2ZUYs9AH0WX9Gs3+n+djWQOWpziIj4w4G7bq suM0T7Pth6m9QNq2ugkfZTY= Received: (qmail 65791 invoked by alias); 12 Jul 2018 07:07:48 -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 65781 invoked by uid 89); 12 Jul 2018 07:07:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy=leader, seq, presenting, match.pd X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Jul 2018 07:07:45 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E56DFAE22 for ; Thu, 12 Jul 2018 07:07:42 +0000 (UTC) Date: Thu, 12 Jul 2018 09:07:42 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Move match-and-simplify recursion limit from SCCVN to generic place Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This moves a recursion limit installed for PR80887 from vn_lookup_simplify_result to gimple_resimplify* where it also applies to a testcase I'm running into with modified VN without ever calling vn_lookup_simplify_result. Basically with VN we are not presenting the match.pd patterns with simplified expressions but for example we happily feed it ((_50 + 0) + 8) via valueization of def-stmt operands. With the correct IL setup it can easily happen that _50 is a leader for itself, thus with _50 = _2 + _3; it is value-numbered as a copy but the value doesn't have a leader here so _50 becomes the leader. This effectively turns it into _50 = _50; Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2018-07-12 Richard Biener * tree-ssa-sccvn.c (mprts_hook_cnt): Remove. (vn_lookup_simplify_result): Remove recursion limit applied here. (vn_nary_build_or_lookup_1): Adjust. (try_to_simplify): Likewise. * gimple-match-head.c (gimple_resimplify1): Instead apply one here. (gimple_resimplify2): Likewise. (gimple_resimplify3): Likewise. (gimple_resimplify4): Likewise. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 262551) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -1648,7 +1648,6 @@ vn_reference_lookup_or_insert_for_pieces } static vn_nary_op_t vn_nary_op_insert_stmt (gimple *stmt, tree result); -static unsigned mprts_hook_cnt; /* Hook for maybe_push_res_to_seq, lookup the expression in the VN tables. */ @@ -1672,13 +1671,8 @@ vn_lookup_simplify_result (gimple_match_ vn_nary_op_t vnresult = NULL; tree res = vn_nary_op_lookup_pieces (length, (tree_code) res_op->code, res_op->type, ops, &vnresult); - /* We can end up endlessly recursing simplifications if the lookup above - presents us with a def-use chain that mirrors the original simplification. - See PR80887 for an example. Limit successful lookup artificially - to 10 times if we are called as mprts_hook. */ if (res - && mprts_hook - && --mprts_hook_cnt == 0) + && mprts_hook) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Resetting mprts_hook after too many " @@ -1701,7 +1695,6 @@ vn_nary_build_or_lookup_1 (gimple_match_ So first simplify and lookup this expression to see if it is already available. */ mprts_hook = vn_lookup_simplify_result; - mprts_hook_cnt = 9; bool res = false; switch (TREE_CODE_LENGTH ((tree_code) res_op->code)) { @@ -4051,7 +4044,6 @@ try_to_simplify (gassign *stmt) /* First try constant folding based on our current lattice. */ mprts_hook = vn_lookup_simplify_result; - mprts_hook_cnt = 9; tem = gimple_fold_stmt_to_constant_1 (stmt, vn_valueize, vn_valueize); mprts_hook = NULL; if (tem Index: gcc/gimple-match-head.c =================================================================== --- gcc/gimple-match-head.c (revision 262551) +++ gcc/gimple-match-head.c (working copy) @@ -97,13 +97,30 @@ gimple_resimplify1 (gimple_seq *seq, gim } } + /* Limit recursion, there are cases like PR80887 and others, for + example when value-numbering presents us with unfolded expressions + that we are really not prepared to handle without eventual + oscillation like ((_50 + 0) + 8) where _50 gets mapped to _50 + itself as available expression. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_FOLDING)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; gimple_match_op res_op2 (*res_op); if (gimple_simplify (&res_op2, seq, valueize, res_op->code, res_op->type, res_op->ops[0])) { + --depth; *res_op = res_op2; return true; } + --depth; return false; } @@ -151,14 +168,27 @@ gimple_resimplify2 (gimple_seq *seq, gim canonicalized = true; } + /* Limit recursion, see gimple_resimplify1. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_FOLDING)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; gimple_match_op res_op2 (*res_op); if (gimple_simplify (&res_op2, seq, valueize, res_op->code, res_op->type, res_op->ops[0], res_op->ops[1])) { + --depth; *res_op = res_op2; return true; } + --depth; return canonicalized; } @@ -205,14 +235,27 @@ gimple_resimplify3 (gimple_seq *seq, gim canonicalized = true; } + /* Limit recursion, see gimple_resimplify1. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_FOLDING)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; gimple_match_op res_op2 (*res_op); if (gimple_simplify (&res_op2, seq, valueize, res_op->code, res_op->type, res_op->ops[0], res_op->ops[1], res_op->ops[2])) { + --depth; *res_op = res_op2; return true; } + --depth; return canonicalized; } @@ -229,15 +272,28 @@ gimple_resimplify4 (gimple_seq *seq, gim { /* No constant folding is defined for four-operand functions. */ + /* Limit recursion, see gimple_resimplify1. */ + static unsigned depth; + if (depth > 10) + { + if (dump_file && (dump_flags & TDF_FOLDING)) + fprintf (dump_file, "Aborting expression simplification due to " + "deep recursion\n"); + return false; + } + + ++depth; gimple_match_op res_op2 (*res_op); if (gimple_simplify (&res_op2, seq, valueize, res_op->code, res_op->type, res_op->ops[0], res_op->ops[1], res_op->ops[2], res_op->ops[3])) { + --depth; *res_op = res_op2; return true; } + --depth; return false; }