From patchwork Thu May 19 08:12:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 68110 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3061178qge; Thu, 19 May 2016 01:12:32 -0700 (PDT) X-Received: by 10.98.24.88 with SMTP id 85mr17889937pfy.52.1463645552314; Thu, 19 May 2016 01:12:32 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o25si18380168pfa.151.2016.05.19.01.12.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 May 2016 01:12:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-427692-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-427692-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-427692-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=em1sVOn/V3cCgO2+0J hBnL8QgI2p2rUciStEaxzp8goFN1jqGHfp+AwEhualrTT3J9/VAzsLF/IBpEtInr 4b8dXiUIcif+eODHxNC0vFiGfr/Jqgc0WDXU+O8GeL1XyhQXDMFF8PlsKQP6UNBA NlZVQfIpPV/fTwMzBEXiOymf4= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=OrSmhgbn5gz+XmAPErC+X3CM 7Y0=; b=CAPTgbedQE4Qj8uVPMTK266ijn/VdBF4c8IlHwA/LNzKXn/jilP3fusS S+Jy7yfVC0aOULMDFghyCForw7CnK4z/jcMY4XIdhLfJn2GMFoi2Dou4z2lJ/5sT DqYpE/tV/MtogXUC1j+Ei3n3ziFD/fTlH3nzJD7p8CNxi++DucI= Received: (qmail 46760 invoked by alias); 19 May 2016 08:12:15 -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 46749 invoked by uid 89); 19 May 2016 08:12:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2972 X-HELO: mail-qg0-f47.google.com Received: from mail-qg0-f47.google.com (HELO mail-qg0-f47.google.com) (209.85.192.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 19 May 2016 08:12:02 +0000 Received: by mail-qg0-f47.google.com with SMTP id a75so8701413qge.2 for ; Thu, 19 May 2016 01:12:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=is+LApw9JUoh4GANzqdDVEhzBG/6AL1zTroxsdhn7sM=; b=Joe9A4LshuVCM+OZAvf/R22BPyeNGYRVPmYkc998tycN48cJhjVixUO1jZQneiOmK5 bgE3TM8CcKrwUs+MDNxBrN0GbXOGtcsb4YxrS/ZPH8A8oIADKCd7t4DpzdDwFEwdK3ig J6ms9ATh2eIZKgUvtdiTwCAw5pTHaftKc14bOIeCDCfuxbYmqST5VnwPXQwTcKRTWr+l 5WRoCv1bQSVc/PljxoYV+GI32bjFgJWRFjYvxDhu86EjIBeoWcZc0103JpchLmNmhsWF WPQTSedMO5w2snnTTXXjkw644TNQsjMsdEyRDqQTgLF9hXxqjL8KcDhELmW9u/Us/QfM vP/Q== X-Gm-Message-State: AOPr4FW2Zcd2sA/2vdMyKNZrnMwax/q1Hr3/D1kg8T+ZsmPMNTwIva7wNeA8hv0Zt8H4qhupLm8NY/fmuvRsaB+X MIME-Version: 1.0 X-Received: by 10.140.18.197 with SMTP id 63mr12037742qgf.18.1463645520604; Thu, 19 May 2016 01:12:00 -0700 (PDT) Received: by 10.200.42.71 with HTTP; Thu, 19 May 2016 01:12:00 -0700 (PDT) In-Reply-To: <573D7394.5050208@suse.cz> References: <573D7394.5050208@suse.cz> Date: Thu, 19 May 2016 18:12:00 +1000 Message-ID: Subject: Re: [PATCH] Fix PR tree-optimization/71170 From: Kugan Vivekanandarajah To: =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches X-IsSubscribed: yes Hi Martin, Thanks for the fix. Just to elaborate (as mentioned in PR) At tree-ssa-reassoc.c:3897, we have: stmt: _15 = _4 + c_7(D); oe->op def_stmt: _17 = c_7(D) * 3; : a1_6 = s_5(D) * 2; _1 = (long int) a1_6; x1_8 = _1 + c_7(D); a2_9 = s_5(D) * 4; _2 = (long int) a2_9; a3_11 = s_5(D) * 6; _3 = (long int) a3_11; _16 = x1_8 + c_7(D); _18 = _1 + _2; _4 = _16 + _2; _15 = _4 + c_7(D); _17 = c_7(D) * 3; x_13 = _15 + _3; return x_13; The root cause of this the place in which we are adding (_17 = c_7(D) * 3). Finding the right place is not always straightforward as this case shows. We could try Martin Liška's approach, We could also move _17 = c_7(D) * 3; at tree-ssa-reassoc.c:3897 satisfy the gcc_assert. We could do this based on the use count of _17. This patch does this. I have no preferences. Any thoughts ? Thanks, Kugan On 19 May 2016 at 18:04, Martin Liška wrote: > Hello. > > Following patch fixes the ICE as it defensively finds the right > place where a new STMT should be inserted. > > Patch bootstraps on x86_64-linux-gnu and no new regression is introduced. > > Ready for trunk? > Thanks, > Martin diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 3b5f36b..11beb28 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3830,6 +3830,29 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, } else { + /* Change the position of newly added stmt. */ + if (TREE_CODE (oe1->op) == SSA_NAME + && has_zero_uses (oe1->op) + && reassoc_stmt_dominates_stmt_p (stmt, SSA_NAME_DEF_STMT (oe1->op))) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (oe1->op); + gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt); + gsi_remove (&gsi, true); + gsi = gsi_for_stmt (stmt); + gsi_insert_before (&gsi, def_stmt, GSI_SAME_STMT); + } + + /* Change the position of newly added stmt. */ + if (TREE_CODE (oe2->op) == SSA_NAME + && has_zero_uses (oe2->op) + && reassoc_stmt_dominates_stmt_p (stmt, SSA_NAME_DEF_STMT (oe2->op))) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (oe2->op); + gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt); + gsi_remove (&gsi, true); + gsi = gsi_for_stmt (stmt); + gsi_insert_before (&gsi, def_stmt, GSI_SAME_STMT); + } gcc_checking_assert (find_insert_point (stmt, oe1->op, oe2->op) == stmt); gimple_assign_set_rhs1 (stmt, oe1->op); @@ -3894,6 +3917,17 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, } else { + /* Change the position of newly added stmt. */ + if (TREE_CODE (oe->op) == SSA_NAME + && has_zero_uses (oe->op) + && reassoc_stmt_dominates_stmt_p (stmt, SSA_NAME_DEF_STMT (oe->op))) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (oe->op); + gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt); + gsi_remove (&gsi, true); + gsi = gsi_for_stmt (stmt); + gsi_insert_before (&gsi, def_stmt, GSI_SAME_STMT); + } gcc_checking_assert (find_insert_point (stmt, new_rhs1, oe->op) == stmt); gimple_assign_set_rhs1 (stmt, new_rhs1);