From patchwork Wed Sep 27 19:15:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 819279 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-463074-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="XRSsPmLY"; 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 3y2SGJ3N8sz9t6W for ; Thu, 28 Sep 2017 05:15:50 +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=lLSLC n8jggmmESL/tBajO//2Ah6Se+vYaXVvq23m1vT0oZuwXa4ntCoGB4c4q7io0nnNs 5zCMIHcSV1lLxvIWyYFV83zWVXo45KLw5kVUyR+Do6sSYqE2rSsJeqyQEJN6z5J6 uMq4VIwqk90g/Aed7Pm2mogTxARoBnArLqJTyM= 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=lu7m3Y6j8fJ +FaeEczK9xM1JhqM=; b=XRSsPmLYh3++T1ERZw+EtKBQ+26re+bYiELbe5nOtlb STFLmdPw/iklHNP5BWZZnLlYwOyp7hlov0S50KpdWbr76cUFxvCt+FrGMC/9BkrH tGyqEWNCyQwKsONa0oCS4PoE2zdoAaSh66hWeDzWpbvjR0lUKW9Xcgxu+PRvTZvM = Received: (qmail 113747 invoked by alias); 27 Sep 2017 19:15:42 -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 113065 invoked by uid 89); 27 Sep 2017 19:15:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 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=serving 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, 27 Sep 2017 19:15:40 +0000 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8RJE7ki146420 for ; Wed, 27 Sep 2017 15:15:36 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2d8ayj1vmt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 27 Sep 2017 15:15:35 -0400 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Sep 2017 15:15:33 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 27 Sep 2017 15:15:31 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8RJFUKL29229124; Wed, 27 Sep 2017 19:15:30 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D87DAC040; Wed, 27 Sep 2017 15:16:05 -0400 (EDT) Received: from bigmac.rchland.ibm.com (unknown [9.10.86.15]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 310E9AC043; Wed, 27 Sep 2017 15:16:05 -0400 (EDT) To: GCC Patches Cc: Richard Biener From: Bill Schmidt Subject: [PATCH] Fix PR82337 (SLSR and abnormal PHIs) Date: Wed, 27 Sep 2017 14:15:30 -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: 17092719-0036-0000-0000-0000027189EE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007800; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000232; SDB=6.00923231; UDB=6.00464110; IPR=6.00703373; BA=6.00005609; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017295; XFM=3.00000015; UTC=2017-09-27 19:15:32 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092719-0037-0000-0000-000041E7AF61 Message-Id: <14297c29-261e-23fb-a9fe-7a1f539fe8d8@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-27_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-1709270269 X-IsSubscribed: yes Hi, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82337 reports a problem with SLSR performing an invalid optimization across an abnormal PHI. This is easy to avoid by ensuring that SSA names used in an abnormal PHI never appear as a basis or as a PHI basis in the candidate table. We won't optimize what we can't see... I've cleaned up the test case in the bug report so that it compiles without warnings and added it to the torture tests. Bootstrapped and tested on powerpc64le-linux-gnu with no regressions. Is this ok for trunk? I would also like to backport it to all open releases after a short wait. Thanks, Bill 2017-09-26 Bill Schmidt PR tree-optimization/82337 * gimple-ssa-strength-reduction.c (find_phi_def): Don't record a phi definition if the PHI result appears in an abnormal PHI. (find_basis_for_base_expr): Don't record a basis if the LHS of the basis appears in an abnormal PHI. Index: gcc/gimple-ssa-strength-reduction.c =================================================================== --- gcc/gimple-ssa-strength-reduction.c (revision 253232) +++ gcc/gimple-ssa-strength-reduction.c (working copy) @@ -488,7 +488,8 @@ find_phi_def (tree base) c = base_cand_from_table (base); - if (!c || c->kind != CAND_PHI) + if (!c || c->kind != CAND_PHI + || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (gimple_phi_result (c->cand_stmt))) return 0; return c->cand_num; @@ -557,6 +558,11 @@ find_basis_for_base_expr (slsr_cand_t c, tree base gimple_bb (one_basis->cand_stmt))) continue; + tree lhs = gimple_assign_lhs (one_basis->cand_stmt); + if (lhs && TREE_CODE (lhs) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs)) + continue; + if (!basis || basis->cand_num < one_basis->cand_num) basis = one_basis; } Index: gcc/testsuite/gcc.c-torture/compile/pr82337.c =================================================================== --- gcc/testsuite/gcc.c-torture/compile/pr82337.c (nonexistent) +++ gcc/testsuite/gcc.c-torture/compile/pr82337.c (working copy) @@ -0,0 +1,25 @@ +/* PR82337: SLSR needs to prevent abnormal SSA names from + serving as a basis. */ +char *a, *b, *c; + +struct d { + short e; + char f[]; +}; + +extern void j (void); + +void +g() { + struct d *h; + char *i; + int d; + do { + i = h->f + d; + 20 ? j() : 0; + i = c; + if (__builtin_setjmp (h)) + b = h->f + d; + d = (int)(*i); + } while (a); +}