From patchwork Wed Nov 16 19:22:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 82602 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp337051qge; Wed, 16 Nov 2016 11:23:53 -0800 (PST) X-Received: by 10.99.110.10 with SMTP id j10mr770587pgc.134.1479324233486; Wed, 16 Nov 2016 11:23:53 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p64si33099186pfa.181.2016.11.16.11.23.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Nov 2016 11:23:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441713-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-441713-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441713-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=VZgzmBm6eV8SMOO1KQIca74P6wDJtV88190pcDpSstd wHcrnfEVmG8Cg5qUUNxKTONBZO8Tg5VcUCLwPV7MjVZViUntXlt0O55SElBM8Z3T yYTJgWZuFfc2Jz2f1bY1PjzNwcQDKn9WoYKqEHx1nA2nIjxeAejDEBIKlG2v0A3s = 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=euy+COvxDnSwr3kaEIb1z+X7AAs=; b=r33FKBiZX4lkFI16o NCQQree7x5rOKUt8X9gWeMDtFmp0UT5u8hhjmhWjVpE9gsaRcfWEw1eQfpUqsbNx OcOi87dGqJuXje6aLneIg+6xHHHpAs4r7c+ZzMmSOUVqcBF9PvWzquZrHDz06tKv Gemusd8U3U6BtDW3UnmH/YzXxo= Received: (qmail 45636 invoked by alias); 16 Nov 2016 19:22:47 -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 45558 invoked by uid 89); 16 Nov 2016 19:22:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=builtins.c, H*Ad:U*olegendo, UD:builtins.c, builtinsc X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Nov 2016 19:22:44 +0000 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAGJIhnP134635 for ; Wed, 16 Nov 2016 14:22:42 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 26rnvw0vkk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Nov 2016 14:22:42 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Nov 2016 12:22:41 -0700 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 16 Nov 2016 12:22:38 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 5344C1FF0023; Wed, 16 Nov 2016 12:22:16 -0700 (MST) Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAGJMa3W16122182; Wed, 16 Nov 2016 12:22:36 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60236BE040; Wed, 16 Nov 2016 12:22:36 -0700 (MST) Received: from ragesh3a (unknown [9.85.128.170]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 15ECFBE038; Wed, 16 Nov 2016 12:22:34 -0700 (MST) Subject: [PATCH v2 2/2, expand] make expand_builtin_strncmp more general From: Aaron Sawdey To: "gcc-patches@gcc.gnu.org" Cc: Richard Biener , Kaz Kojima , olegendo@gcc.gnu.org, Nick Clifton , Jeff Law , Uros Bizjak , David Edelsohn Date: Wed, 16 Nov 2016 13:22:29 -0600 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111619-0012-0000-0000-00001127C358 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006089; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00781581; UDB=6.00377041; IPR=6.00559094; BA=6.00004886; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013348; XFM=3.00000011; UTC=2016-11-16 19:22:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111619-0013-0000-0000-0000473A3BEC Message-Id: <1479324149.6279.31.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-16_06:, , 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-1609300000 definitions=main-1611160288 X-IsSubscribed: yes This patch makes expand_builtin_strncmp attempt to expand via cmpstrnsi even if neither of the string arguments are string constants. 2016-11-16  Aaron Sawdey   * builtins.c (expand_builtin_strncmp): Attempt expansion of strncmp via cmpstrnsi even if neither string is constant. -- 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: gcc/builtins.c =================================================================== --- gcc/builtins.c (revision 242428) +++ gcc/builtins.c (working copy) @@ -3918,7 +3918,7 @@ insn_code cmpstrn_icode = direct_optab_handler (cmpstrn_optab, SImode); if (cmpstrn_icode != CODE_FOR_nothing) { - tree len, len1, len2; + tree len, len1, len2, len3; rtx arg1_rtx, arg2_rtx, arg3_rtx; rtx result; tree fndecl, fn; @@ -3937,14 +3937,19 @@ if (len2) len2 = size_binop_loc (loc, PLUS_EXPR, ssize_int (1), len2); + len3 = fold_convert_loc (loc, sizetype, arg3); + /* 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 + of the second, if we know it. If neither string is constant length, + use the given length argument. 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) + if (!len1 && !len2) + len = len3; + else if (!len1) len = len2; else if (!len2) len = len1; @@ -3961,23 +3966,10 @@ else len = len2; - /* 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)); - - /* 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); - arg2 = builtin_save_expr (arg2); - len = builtin_save_expr (len); - + /* If we are not using the given length, we must incorporate it here. + The actual new length parameter will be MIN(len,arg3) in this case. */ + if (len != len3) + len = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (len), len, len3); arg1_rtx = get_memory_rtx (arg1, len); arg2_rtx = get_memory_rtx (arg2, len); arg3_rtx = expand_normal (len);