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: 695763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tJvLm0Zn3z9t0v for ; Thu, 17 Nov 2016 06:23:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="t4YfGlN4"; dkim-atps=neutral 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=ZDVORhLzvVahGXzP23hpjZ9KsvlB1vIsaM0xCYxZESR cwy2PUeuJacDy1obthu6KrY4FKp07uHZbcixM5Uy1AzqMW75I0Ay6drkoDgh05VK 7fbcMhnIMu/NkISrJKZigjCfpzug98p0sCDQatEgqeMhM3TXnGe0alPU90tpUAA8 = 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=t4YfGlN4Y24I3dtaH lGLpxe+KaOO/OMvH8ldnv8tG2xwXSw6LhTXhlLyUF3MMzolR02HOseF2pjrDmYLI RPhnK3JMChKiiq68D2cwq98xm1Ty3iRxGEHTbWTyBX3IDQ7AyToVIFv1/sxBmpwC bUgLOoPGuTRZAWzSAMp6VbUOlU= 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. 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);