From patchwork Tue Nov 1 22:29:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 80418 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp856880qge; Tue, 1 Nov 2016 15:30:56 -0700 (PDT) X-Received: by 10.99.164.9 with SMTP id c9mr480392pgf.173.1478039456082; Tue, 01 Nov 2016 15:30:56 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v4si32712373pgb.232.2016.11.01.15.30.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2016 15:30:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-440111-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-440111-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440111-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=WZ0vwZDZX+orcgi0RI/US8ihRaN98ejHK8EKbX6OdhJ ltBjXnKUYGU6CNJ0evXFLnx9IC7nEWNuOa0lUENp3fyH480A2cQ7R7SvaxXx7SeA 7du6cIGRw0VFNe2vpvQTWTGnV9chW6rX7no/uWOdzw7PeRjNQMiNxkhGD+OXFnLo = 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=F13BNvyoVcxirGF88YF1eA51NCI=; b=XgKizjsLLnhg5wYZ1 Lj9L9xhQ9sO00p4zztSHbAFNcGZPsIIuyIAto2cq04dM91LYXnHKzKSwtEOPGdZG xaefPpANKnTlARD3Eg3pIFBNHzGDVY+jerjz6K6glNWdlYt2qWPvx6uQuzHI12ad QKfpoacIMcI7MvMuUYqgy5YHSQ= Received: (qmail 61401 invoked by alias); 1 Nov 2016 22:29:24 -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 61306 invoked by uid 89); 1 Nov 2016 22:29:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=H*Ad:U*olegendo, aaron, Aaron, Toolchain 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; Tue, 01 Nov 2016 22:29:21 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uA1MSZL9002758 for ; Tue, 1 Nov 2016 18:29:20 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 26ewcu6au1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 01 Nov 2016 18:29:20 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Nov 2016 16:29:19 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 1 Nov 2016 16:29:17 -0600 Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id DD1FE19D8045; Tue, 1 Nov 2016 16:28:40 -0600 (MDT) Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uA1MTGMj15728928; Tue, 1 Nov 2016 22:29:16 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C60D112051; Tue, 1 Nov 2016 18:29:16 -0400 (EDT) Received: from ragesh3a.rchland.ibm.com (unknown [9.10.86.150]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id 012F4112034; Tue, 1 Nov 2016 18:29:15 -0400 (EDT) Subject: [PATCH 2/2, expand] make expand_builtin_strncmp more general From: Aaron Sawdey To: "gcc-patches@gcc.gnu.org" Cc: kkojima@gcc.gnu.org, olegendo@gcc.gnu.org, nickc@redhat.com Date: Tue, 01 Nov 2016 17:29:15 -0500 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16110122-0012-0000-0000-00001106C319 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006016; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00775557; UDB=6.00372896; IPR=6.00552628; BA=6.00004849; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013178; XFM=3.00000011; UTC=2016-11-01 22:29:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16110122-0013-0000-0000-000046CC8845 Message-Id: <1478039355.9676.68.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-01_10:, , 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-1611010387 X-IsSubscribed: yes This patch adds code to expand_builtin_strncmp so it also attempts expansion via cmpstrnsi in the case where c_strlen() returns NULL for both string arguments, meaning that neither one is a 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: builtins.c =================================================================== --- builtins.c (revision 241743) +++ builtins.c (working copy) @@ -3929,61 +3929,85 @@ unsigned int arg1_align = get_pointer_alignment (arg1) / BITS_PER_UNIT; unsigned int arg2_align = get_pointer_alignment (arg2) / BITS_PER_UNIT; + /* If we don't have POINTER_TYPE, call the function. */ + if (arg1_align == 0 || arg2_align == 0) + return NULL_RTX; + 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) + { + /* If neither arg1 nor arg2 are constant strings. */ + /* Stabilize the arguments in case gen_cmpstrnsi fails. */ + arg1 = builtin_save_expr (arg1); + arg2 = builtin_save_expr (arg2); + /* Use save_expr here because cmpstrnsi may modify arg3 + and builtin_save_expr() doesn't force the save to happen. */ + len = save_expr (arg3); + len = fold_convert_loc (loc, sizetype, len); + } + 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 (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; + /* Stabilize the arguments in case gen_cmpstrnsi fails. */ + arg1 = builtin_save_expr (arg1); + arg2 = builtin_save_expr (arg2); + len = builtin_save_expr (len); + } - /* Stabilize the arguments in case gen_cmpstrnsi fails. */ - arg1 = builtin_save_expr (arg1); - arg2 = builtin_save_expr (arg2); - len = builtin_save_expr (len); - arg1_rtx = get_memory_rtx (arg1, len); arg2_rtx = get_memory_rtx (arg2, len); arg3_rtx = expand_normal (len); + + /* Set MEM_SIZE as appropriate. This will only happen in + the case where incoming arg3 is constant and arg1/arg2 are not. */ + if (CONST_INT_P (arg3_rtx)) + { + set_mem_size (arg1_rtx, INTVAL (arg3_rtx)); + set_mem_size (arg2_rtx, INTVAL (arg3_rtx)); + } + result = expand_cmpstrn_or_cmpmem (cmpstrn_icode, target, arg1_rtx, arg2_rtx, TREE_TYPE (len), arg3_rtx, MIN (arg1_align, arg2_align)); + if (result) { /* Return the value in the proper mode for this function. */