From patchwork Wed Aug 30 17:22:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 807772 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-461184-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pp8Tc4np"; 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 3xjC514bGlz9sN7 for ; Thu, 31 Aug 2017 03:23:00 +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=uGAjp IApKdkTXazOi4dNLb2C4hhE83rfAfQAnPpez9PTXa7Ifs2wtJN56/Luf1nOyUoV5 feOO8bo8a6rvifXtMKcND/yLw7Ru9P9xUl6TIJoOMDNBeKuxjLHvpstSK/zYPqqm 0NnuCCHBWhxTXJWdNUnjy7u4axmFE0jlf2h8Jo= 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=SObxNlKCeAu pCPop76EruVcEFNw=; b=pp8Tc4npljL8TfPYOWVdi81CC993IEDczPU+1r2O0aE 1pc1SvLvNS9t3EukaS3MUI3XzNoGO4oDSM+9rC7C0Z8cgb7+R8V99LM6+rcyLGuX E4OGeT90xvZwAQL+2Cd3HS9znBX8TKsVotHRzOafddF8NVSmB8L6fCOBo0veCRdU = Received: (qmail 49690 invoked by alias); 30 Aug 2017 17:22:53 -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 49611 invoked by uid 89); 30 Aug 2017 17:22:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=earliest, nominal, Multiple, dominance 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; Wed, 30 Aug 2017 17:22:51 +0000 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7UHJE1M046322 for ; Wed, 30 Aug 2017 13:22:50 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cnyf4rdqy-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 30 Aug 2017 13:22:49 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 30 Aug 2017 13:22:48 -0400 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 30 Aug 2017 13:22:46 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7UHMMNx22741062; Wed, 30 Aug 2017 17:22:45 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5693AE063; Wed, 30 Aug 2017 13:23:09 -0400 (EDT) Received: from bigmac.rchland.ibm.com (unknown [9.10.86.76]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id BD8E9AE03B; Wed, 30 Aug 2017 13:23:09 -0400 (EDT) To: GCC Patches Cc: Richard Biener From: Bill Schmidt Subject: [PATCH] Fix PR81987 (SLSR dominance issue) Date: Wed, 30 Aug 2017 12:22:45 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17083017-0048-0000-0000-000001DBD4E4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007637; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000226; SDB=6.00909817; UDB=6.00456342; IPR=6.00690101; BA=6.00005562; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016930; XFM=3.00000015; UTC=2017-08-30 17:22:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17083017-0049-0000-0000-000042663BC3 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-30_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708300263 X-IsSubscribed: yes Hi, https://gcc.gnu.org/PR81987 identifies an SSA verification error following SLSR. The problem arises when SLSR places an initialization expression at a point not dominated by the definition of an SSA name it uses. When there are multiple conditional candidates for replacement, the initialization expression must dominate all of these candidates and their phi dependencies, but the nearest common dominator for these may actually be above the stride definition in some cases. In such cases a single initialization point is not possible. With sufficient analysis, it would be possible to find multiple initialization points that would satisfy availability of the stride at the cost of larger code. This is too complex for a bug fix, though. This patch instead refuses to replace candidates where a single legal initialization point isn't possible. We ensure this by setting the cost for the increment associated with this initialization to effectively infinite. Bootstrapped and tested on powerpc64le-linux-gnu with no regressions. Is this okay for trunk, and backport to all supported releases after a period of burn-in? Thanks, Bill [gcc] 2017-08-30 Bill Schmidt PR tree-optimization/81987 * gimple-ssa-strength-reduction.c (insert_initializers): Don't insert an initializer in a location not dominated by the stride definition. [gcc/testsuite] 2017-08-30 Bill Schmidt PR tree-optimization/81987 * g++.dg/torture/pr81987.C: New file. Index: gcc/gimple-ssa-strength-reduction.c =================================================================== --- gcc/gimple-ssa-strength-reduction.c (revision 251369) +++ gcc/gimple-ssa-strength-reduction.c (working copy) @@ -3340,6 +3340,23 @@ insert_initializers (slsr_cand_t c) that block, the earliest one will be returned in WHERE. */ bb = nearest_common_dominator_for_cands (c, incr, &where); + /* If the NCD is not dominated by the block containing the + definition of the stride, we can't legally insert a + single initializer. Mark the increment as unprofitable + so we don't make any replacements. FIXME: Multiple + initializers could be placed with more analysis. */ + gimple *stride_def = SSA_NAME_DEF_STMT (c->stride); + basic_block stride_bb = gimple_bb (stride_def); + + if (stride_bb && !dominated_by_p (CDI_DOMINATORS, bb, stride_bb)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Initializer #%d cannot be legally placed\n", i); + incr_vec[i].cost = COST_INFINITE; + continue; + } + /* If the nominal stride has a different type than the recorded stride type, build a cast from the nominal stride to that type. */ if (!types_compatible_p (TREE_TYPE (c->stride), c->stride_type)) Index: gcc/testsuite/g++.dg/torture/pr81987.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr81987.C (nonexistent) +++ gcc/testsuite/g++.dg/torture/pr81987.C (working copy) @@ -0,0 +1,61 @@ +extern short var_1; +extern const short var_3; +extern unsigned long int var_9; +extern short var_13; +extern const unsigned long int var_15; +extern const unsigned long int var_37; +extern unsigned long int var_40; +extern long long int var_47; +extern short var_48; +extern const short var_54; +extern long long int var_79; +extern long long int var_81; +extern long long int var_94; +extern long long int var_95; +extern long long int var_701; +extern unsigned long int var_786; +extern short var_788; +extern long long int var_844; + +struct struct_1 { + short member_1_2 : 15; + static long long int member_1_3; +}; + +extern struct_1 struct_obj_6; +extern struct_1 struct_obj_8; + +void foo() { + int a = var_3 <= 602154393864UL; + if (var_81 ? 0 : var_3 && var_9) + ; + else { + var_94 = 0; + if (var_3 && var_48 || var_13) { + if (var_48) + var_95 = 0; + short b((2364461588881776511UL + var_3) * (2 ? var_13 : 0) || var_1); + struct_obj_8.member_1_2 = b; + if (var_15) { + if (var_81) + if (var_47) + ; + else if (var_40) + var_701 = 0; + } else { + if (var_40) + var_79 = 0; + if (var_54) { + if (var_37) + var_786 = 0; + else + var_788 = 0; + struct_obj_6.member_1_3 = + (2364461588881776511UL + var_3) * (2 ? var_13 : 0); + } + } + if ((2364461588881776511UL + var_3) * (2 ? var_13 : 0)) + var_844 = 0; + } + } +}