From patchwork Tue May 22 21:37:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 918570 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-478211-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Vv060LUn"; 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 40r8BX0CcKz9s1d for ; Wed, 23 May 2018 07:37:39 +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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=l0lI4 e0ROD2ygl4qcYTOSmx9NBKbOiCrhwEDGH/cf1pF/aMnGDe84iOStAEYEpYOOpKkH GPn5EVLyR2cfaIfleAWXn1bzFMFpzCwSHFZ5ClcxqEAfsrdud1fePLF0Wwhn47IG 4hb7JUcX64uFCCNmqxJmFM5RVrJobVS6jLFeVY= 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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=y6HuDMFG8W+ IYF3ISmHJHWMAPVE=; b=Vv060LUnEy+zVgyaFKfxaV6Nh1RaS4Fc+57FBU+Qjfr LZM74waDqBjhN9AAkkoNbNlqozQ+K4edgIyg/1bCGVNoXGzEcxghLQ6o7TEITOA+ kZetsegmvFFVj2QchOcfEyILfWL8DwIv/4rCXL/f2N+b/a4bboT9Ip7ZACgGTSEc = Received: (qmail 73590 invoked by alias); 22 May 2018 21:37:29 -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 73571 invoked by uid 89); 22 May 2018 21:37:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=versus, 260484, interpretation X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 May 2018 21:37:25 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4MLOcok062841 for ; Tue, 22 May 2018 17:37:24 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j4qqv91tf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 22 May 2018 17:37:23 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 May 2018 17:37:22 -0400 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 22 May 2018 17:37:20 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4MLbI0m45613294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 22 May 2018 21:37:19 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88C52B205F; Tue, 22 May 2018 18:39:08 -0400 (EDT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57995B2068; Tue, 22 May 2018 18:39:08 -0400 (EDT) Received: from bigmac.rchland.ibm.com (unknown [9.10.86.136]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 22 May 2018 18:39:08 -0400 (EDT) To: GCC Patches Cc: Richard Biener From: Bill Schmidt Subject: [PATCH] Fix PR85712 (SLSR cleanup of alternative interpretations) Date: Tue, 22 May 2018 16:37:18 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18052221-0040-0000-0000-0000042F38F5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009065; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000261; SDB=6.01036001; UDB=6.00529949; IPR=6.00815130; MB=3.00021234; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-22 21:37:21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052221-0041-0000-0000-0000083554CA Message-Id: <875f0508-ae57-1cb1-f7c3-41aa6561f75a@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-22_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805220218 Hi, PR85712 shows where an existing test case fails in the SLSR pass because the code is flawed that cleans up alternative interpretations (CAND_ADD versus CAND_MULT, for example) after a replacement. This patch fixes the flaw by ensuring that we always visit all interpretations, not just subsequent ones in the next_interp chain. I found six occurrences of this mistake in the code. Bootstrapped and tested on powerpc64le-linux-gnu with no regressions. No new test case is added since the failure occurs on an existing test in the test suite. Is this okay for trunk, and for backports to all supported branches after some burn-in time? Thanks, Bill 2018-05-22 Bill Schmidt * gimple-ssa-strength-reduction.c (struct slsr_cand_d): Add first_interp field. (alloc_cand_and_find_basis): Initialize first_interp field. (slsr_process_mul): Modify first_interp field. (slsr_process_add): Likewise. (slsr_process_cast): Modify first_interp field for each new interpretation. (slsr_process_copy): Likewise. (dump_candidate): Dump first_interp field. (replace_mult_candidate): Process all interpretations, not just subsequent ones. (replace_rhs_if_not_dup): Likewise. (replace_one_candidate): Likewise. Index: gcc/gimple-ssa-strength-reduction.c =================================================================== --- gcc/gimple-ssa-strength-reduction.c (revision 260484) +++ gcc/gimple-ssa-strength-reduction.c (working copy) @@ -266,6 +266,10 @@ struct slsr_cand_d of a statement. */ cand_idx next_interp; + /* Index of the first candidate record in a chain for the same + statement. */ + cand_idx first_interp; + /* Index of the basis statement S0, if any, in the candidate vector. */ cand_idx basis; @@ -686,6 +690,7 @@ alloc_cand_and_find_basis (enum cand_kind kind, gi c->kind = kind; c->cand_num = cand_vec.length () + 1; c->next_interp = 0; + c->first_interp = c->cand_num; c->dependent = 0; c->sibling = 0; c->def_phi = kind == CAND_MULT ? find_phi_def (base) : 0; @@ -1261,6 +1266,7 @@ slsr_process_mul (gimple *gs, tree rhs1, tree rhs2 is the stride and RHS2 is the base expression. */ c2 = create_mul_ssa_cand (gs, rhs2, rhs1, speed); c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; } else if (TREE_CODE (rhs2) == INTEGER_CST) { @@ -1498,7 +1504,10 @@ slsr_process_add (gimple *gs, tree rhs1, tree rhs2 { c2 = create_add_ssa_cand (gs, rhs2, rhs1, false, speed); if (c) - c->next_interp = c2->cand_num; + { + c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; + } else add_cand_for_stmt (gs, c2); } @@ -1621,6 +1630,8 @@ slsr_process_cast (gimple *gs, tree rhs1, bool spe if (base_cand && base_cand->kind != CAND_PHI) { + slsr_cand_t first_cand = NULL; + while (base_cand) { /* Propagate all data from the base candidate except the type, @@ -1635,6 +1646,12 @@ slsr_process_cast (gimple *gs, tree rhs1, bool spe base_cand->index, base_cand->stride, ctype, base_cand->stride_type, savings); + if (!first_cand) + first_cand = c; + + if (first_cand != c) + c->first_interp = first_cand->cand_num; + if (base_cand->next_interp) base_cand = lookup_cand (base_cand->next_interp); else @@ -1657,6 +1674,7 @@ slsr_process_cast (gimple *gs, tree rhs1, bool spe c2 = alloc_cand_and_find_basis (CAND_MULT, gs, rhs1, 0, integer_one_node, ctype, sizetype, 0); c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; } /* Add the first (or only) interpretation to the statement-candidate @@ -1681,6 +1699,8 @@ slsr_process_copy (gimple *gs, tree rhs1, bool spe if (base_cand && base_cand->kind != CAND_PHI) { + slsr_cand_t first_cand = NULL; + while (base_cand) { /* Propagate all data from the base candidate. */ @@ -1693,6 +1713,12 @@ slsr_process_copy (gimple *gs, tree rhs1, bool spe base_cand->index, base_cand->stride, base_cand->cand_type, base_cand->stride_type, savings); + if (!first_cand) + first_cand = c; + + if (first_cand != c) + c->first_interp = first_cand->cand_num; + if (base_cand->next_interp) base_cand = lookup_cand (base_cand->next_interp); else @@ -1717,6 +1743,7 @@ slsr_process_copy (gimple *gs, tree rhs1, bool spe integer_one_node, TREE_TYPE (rhs1), sizetype, 0); c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; } /* Add the first (or only) interpretation to the statement-candidate @@ -1887,8 +1914,9 @@ dump_candidate (slsr_cand_t c) print_generic_expr (dump_file, c->cand_type); fprintf (dump_file, "\n basis: %d dependent: %d sibling: %d\n", c->basis, c->dependent, c->sibling); - fprintf (dump_file, " next-interp: %d dead-savings: %d\n", - c->next_interp, c->dead_savings); + fprintf (dump_file, + " next-interp: %d first-interp: %d dead-savings: %d\n", + c->next_interp, c->first_interp, c->dead_savings); if (c->def_phi) fprintf (dump_file, " phi: %d\n", c->def_phi); fputs ("\n", dump_file); @@ -2147,14 +2175,13 @@ replace_mult_candidate (slsr_cand_t c, tree basis_ tree lhs = gimple_assign_lhs (c->cand_stmt); gassign *copy_stmt = gimple_build_assign (lhs, basis_name); gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); - slsr_cand_t cc = c; + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_set_location (copy_stmt, gimple_location (c->cand_stmt)); gsi_replace (&gsi, copy_stmt, false); - c->cand_stmt = copy_stmt; - while (cc->next_interp) + while (cc) { - cc = lookup_cand (cc->next_interp); cc->cand_stmt = copy_stmt; + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = copy_stmt; @@ -2181,14 +2208,13 @@ replace_mult_candidate (slsr_cand_t c, tree basis_ else { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); - slsr_cand_t cc = c; + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, code, basis_name, bump_tree); update_stmt (gsi_stmt (gsi)); - c->cand_stmt = gsi_stmt (gsi); - while (cc->next_interp) + while (cc) { - cc = lookup_cand (cc->next_interp); cc->cand_stmt = gsi_stmt (gsi); + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = gsi_stmt (gsi); @@ -3597,14 +3623,13 @@ replace_rhs_if_not_dup (enum tree_code new_code, t || !operand_equal_p (new_rhs2, old_rhs1, 0)))) { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); - slsr_cand_t cc = c; + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, new_code, new_rhs1, new_rhs2); update_stmt (gsi_stmt (gsi)); - c->cand_stmt = gsi_stmt (gsi); - while (cc->next_interp) + while (cc) { - cc = lookup_cand (cc->next_interp); cc->cand_stmt = gsi_stmt (gsi); + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3709,14 +3734,13 @@ replace_one_candidate (slsr_cand_t c, unsigned i, || !operand_equal_p (rhs2, orig_rhs2, 0)) { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); - slsr_cand_t cc = c; + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, MINUS_EXPR, basis_name, rhs2); update_stmt (gsi_stmt (gsi)); - c->cand_stmt = gsi_stmt (gsi); - while (cc->next_interp) + while (cc) { - cc = lookup_cand (cc->next_interp); cc->cand_stmt = gsi_stmt (gsi); + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3736,14 +3760,13 @@ replace_one_candidate (slsr_cand_t c, unsigned i, { gassign *copy_stmt = gimple_build_assign (lhs, basis_name); gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); - slsr_cand_t cc = c; + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_set_location (copy_stmt, gimple_location (c->cand_stmt)); gsi_replace (&gsi, copy_stmt, false); - c->cand_stmt = copy_stmt; - while (cc->next_interp) + while (cc) { - cc = lookup_cand (cc->next_interp); cc->cand_stmt = copy_stmt; + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3753,14 +3776,13 @@ replace_one_candidate (slsr_cand_t c, unsigned i, { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); gassign *cast_stmt = gimple_build_assign (lhs, NOP_EXPR, basis_name); - slsr_cand_t cc = c; + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_set_location (cast_stmt, gimple_location (c->cand_stmt)); gsi_replace (&gsi, cast_stmt, false); - c->cand_stmt = cast_stmt; - while (cc->next_interp) + while (cc) { - cc = lookup_cand (cc->next_interp); cc->cand_stmt = cast_stmt; + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; } if (dump_file && (dump_flags & TDF_DETAILS))