From patchwork Thu Oct 27 01:14:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 79571 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp369311qge; Wed, 26 Oct 2016 18:14:41 -0700 (PDT) X-Received: by 10.98.141.217 with SMTP id p86mr9236002pfk.109.1477530881708; Wed, 26 Oct 2016 18:14:41 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id n124si5248725pfn.198.2016.10.26.18.14.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Oct 2016 18:14:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439672-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-439672-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439672-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:date:content-type:mime-version:message-id; q=dns; s=default; b=x/5C7gRjxD6nFRmJr2V5t5YpjSRB+kMlF/Hk7XCDMVy LS8WY5i4KcGPk3bgpm7XwWX+Ab6Pl02kG4B7ObdQJiFNJz9A0LbdnuSRj0+8U3P4 prE/TVQnt08LO7tXH/xWOyAbJqLvS0QaTc3IWgKWoMpgYfxRHBVPhwuQr2Oa0NOo = 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 :subject:from:to:cc:date:content-type:mime-version:message-id; s=default; bh=FgDfwlTmwCbmhSPNkSz23D9sj90=; b=eCHrH8T0LBBa50i5j KIJRj/mvhQ0w5wWra9dXiTnTvpN+nDZQMOr07u50cJAtQBjzIxzc1Z4ytxM5h8RB EZTj8gmY4VAZIc5WN/SLbgNTuCZXsvzc+Ig0GhiPgnRdix+2/mEe8rEqRNPto5ii oz2trS9WkemdJymBAMBdkUpNMk= Received: (qmail 19844 invoked by alias); 27 Oct 2016 01:14:12 -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 19828 invoked by uid 89); 27 Oct 2016 01:14:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.2 spammy=MIN_EXPR, acsawdeylinuxvnetibmcom, MIN, sk:acsawde 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; Thu, 27 Oct 2016 01:14:10 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u9R1DspL066687 for ; Wed, 26 Oct 2016 21:14:08 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 26b7kgr85s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 26 Oct 2016 21:14:08 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 26 Oct 2016 19:14:07 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 26 Oct 2016 19:14:05 -0600 Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 4875F1FF001E; Wed, 26 Oct 2016 19:13:45 -0600 (MDT) Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9R1E4I418219198; Thu, 27 Oct 2016 01:14:04 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1E57112047; Wed, 26 Oct 2016 21:14:04 -0400 (EDT) Received: from ragesh3a (unknown [9.85.156.33]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id 3D048112034; Wed, 26 Oct 2016 21:14:04 -0400 (EDT) Subject: [RFC PATCH] expand_strn_compare should attempt expansion even if neither string is constant From: Aaron Sawdey To: gcc-patches@gcc.gnu.org Cc: Richard Sandiford , Segher Boessenkool , Bill Schmidt Date: Wed, 26 Oct 2016 20:14:03 -0500 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16102701-0016-0000-0000-00000503C51C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005985; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000188; SDB=6.00773239; UDB=6.00371256; IPR=6.00550075; BA=6.00004835; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013112; XFM=3.00000011; UTC=2016-10-27 01:14:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16102701-0017-0000-0000-0000341EED4D Message-Id: <1477530843.5924.27.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-26_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610270018 X-IsSubscribed: yes I'm currently working on a builtin expansion of strncmp for powerpc similar to the one for memcmp I checked recently. One thing I encountered is that the code in expand_strn_compare will not attempt to expand the cmpstrnsi pattern at all if neither string parameter is a constant string. This doesn't make a lot of sense in light of the fact that expand_str_compare starts with an attempt to expand cmpstrsi and then if that does not work, looks at the string args to see if one is constant so it can use cmpstrnsi with the known length. The attached patch is my attempt to add this fallback path to expand_strn_compare, i.e. if neither length is known, just attempt expansion of cmpstrnsi using the given 3 arguments. It looks like in addition to rs6000, there are 3 other targets that have cmpstrnsi patterns: i386, sh, and rx.  Is this a reasonable approach to take with this? If so I'll bootstrap/regtest on i386 as rs6000 does not as yet have an expansion for cmpstrsi or cmpstrnsi. Thanks,    Aaron -- Aaron Sawdey, Ph.D. acsawdey@linux.vnet.ibm.com 050-2/C113 (507) 253-7520 home: 507/263-0782 IBM Linux Technology Center - PPC Toolchain Index: builtins.c =================================================================== --- builtins.c (revision 241593) +++ builtins.c (working copy) @@ -3932,46 +3932,53 @@ len1 = c_strlen (arg1, 1); len2 = c_strlen (arg2, 1); - if (len1) - len1 = size_binop_loc (loc, PLUS_EXPR, ssize_int (1), len1); - if (len2) - len2 = size_binop_loc (loc, PLUS_EXPR, ssize_int (1), len2); + if (!len1 && !len2) + { + len = arg3; + } + else + { + if (len1) + len1 = size_binop_loc (loc, PLUS_EXPR, ssize_int (1), len1); + if (len2) + len2 = size_binop_loc (loc, PLUS_EXPR, ssize_int (1), len2); - /* If we don't have a constant length for the first, use the length - of the second, if we know it. We don't require a constant for - this case; some cost analysis could be done if both are available - but neither is constant. For now, assume they're equally cheap, - unless one has side effects. If both strings have constant lengths, - use the smaller. */ + /* If we don't have a constant length for the first, use the length + of the second, if we know it. We don't require a constant for + this case; some cost analysis could be done if both are available + but neither is constant. For now, assume they're equally cheap, + unless one has side effects. If both strings have constant lengths, + use the smaller. */ - if (!len1) - len = len2; - else if (!len2) - len = len1; - else if (TREE_SIDE_EFFECTS (len1)) - len = len2; - else if (TREE_SIDE_EFFECTS (len2)) - len = len1; - else if (TREE_CODE (len1) != INTEGER_CST) - len = len2; - else if (TREE_CODE (len2) != INTEGER_CST) - len = len1; - else if (tree_int_cst_lt (len1, len2)) - len = len1; - else - len = len2; + if (!len1) + len = len2; + else if (!len2) + len = len1; + else if (TREE_SIDE_EFFECTS (len1)) + len = len2; + else if (TREE_SIDE_EFFECTS (len2)) + len = len1; + else if (TREE_CODE (len1) != INTEGER_CST) + len = len2; + else if (TREE_CODE (len2) != INTEGER_CST) + len = len1; + else if (tree_int_cst_lt (len1, len2)) + len = len1; + else + len = len2; - /* If both arguments have side effects, we cannot optimize. */ - if (!len || TREE_SIDE_EFFECTS (len)) - return NULL_RTX; + /* If both arguments have side effects, we cannot optimize. */ + if (!len || TREE_SIDE_EFFECTS (len)) + return NULL_RTX; - /* The actual new length parameter is MIN(len,arg3). */ - len = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (len), len, - fold_convert_loc (loc, TREE_TYPE (len), arg3)); + /* The actual new length parameter is MIN(len,arg3). */ + len = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (len), len, + fold_convert_loc (loc, TREE_TYPE (len), arg3)); - /* If we don't have POINTER_TYPE, call the function. */ - if (arg1_align == 0 || arg2_align == 0) - return NULL_RTX; + /* If we don't have POINTER_TYPE, call the function. */ + if (arg1_align == 0 || arg2_align == 0) + return NULL_RTX; + } /* Stabilize the arguments in case gen_cmpstrnsi fails. */ arg1 = builtin_save_expr (arg1);