From patchwork Tue Nov 1 22:29:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 80419 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp856952qge; Tue, 1 Nov 2016 15:31:09 -0700 (PDT) X-Received: by 10.98.1.200 with SMTP id 191mr680658pfb.102.1478039469460; Tue, 01 Nov 2016 15:31:09 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ww9si1660692pab.171.2016.11.01.15.31.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2016 15:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-440112-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-440112-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440112-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=mwmyCYI6tNapL0NWfD6pw+EiQqzT0eX+r9tfxUzKw9M C+lY8t9TddjnsZDRuNg1RO0UiGmsEZRVOxuTyHqEG5FdtUq69VRMTNh0ZHuBA+99 yuMUgWyuj6g8u2LMGemhu/DxsoKyYlYF/vYQjJuSjgedZ4t6QwS2wIRX/Gufo1DI = 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=LgwEjToAGa99Y9FOz8jG1FJituU=; b=YkObcfsdoOSGdUqFH /TWomzAdejc+hA6XKkZlQAev4PgrG050fWDbi8CI3X/GF+A+Y0v2l96FRbbqsNBB GmhYJxkKrgCvUNvsytGtXcdhixfpL0ovllc/8eoozvcCfkhsvlsM0Pic5tJTDkXr jtLY2MVQFYLC9TIRbdWFrBkGVo= Received: (qmail 62018 invoked by alias); 1 Nov 2016 22:29:30 -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 61899 invoked by uid 89); 1 Nov 2016 22:29:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.2 spammy=H*Ad:U*olegendo, Aaron, aaron, Toolchain 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; Tue, 01 Nov 2016 22:29:19 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uA1MSYOw133623 for ; Tue, 1 Nov 2016 18:29:17 -0400 Received: from e18.ny.us.ibm.com (e18.ny.us.ibm.com [129.33.205.208]) by mx0a-001b2d01.pphosted.com with ESMTP id 26euu230uf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 01 Nov 2016 18:29:17 -0400 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Nov 2016 18:29:16 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e18.ny.us.ibm.com (146.89.104.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 1 Nov 2016 18:29:14 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id BDBCC38C8046; Tue, 1 Nov 2016 18:29:13 -0400 (EDT) Received: from b01ledav03.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uA1MTE6w16384388; Tue, 1 Nov 2016 22:29:14 GMT Received: from b01ledav03.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E41ACB2050; Tue, 1 Nov 2016 18:29:13 -0400 (EDT) Received: from ragesh3a.rchland.ibm.com (unknown [9.10.86.150]) by b01ledav03.gho.pok.ibm.com (Postfix) with ESMTP id A1C25B2046; Tue, 1 Nov 2016 18:29:13 -0400 (EDT) Subject: [PATCH 1/2, i386] cmpstrnsi needs string length 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:13 -0500 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16110122-0044-0000-0000-000001A0EB30 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:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16110122-0045-0000-0000-000005CDED55 Message-Id: <1478039353.9676.67.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 a test to the cmpstrnsi pattern in i386.md so that it will bail out (FAIL) if neither of the strings is a constant string. It can only work as a proper strncmp if the length is not longer than both of the strings. This change is required if expand_builtin_strncmp is going to try expansion of strncmp when neither string argument 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: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 241743) +++ config/i386/i386.md (working copy) @@ -16909,6 +16909,21 @@ if (fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG]) FAIL; + /* One of the strings must be a constant. If so, expand_builtin_strncmp() + will have rewritten the length arg to be the minimum of the const string + length and the actual length arg. If both strings are the same and + shorter than the length arg, repz cmpsb will not stop at the 0 byte and + will incorrectly base the results on chars past the 0 byte. */ + tree t1 = MEM_EXPR (operands[1]); + tree t2 = MEM_EXPR (operands[2]); + if (!((t1 && TREE_CODE (t1) == MEM_REF + && TREE_CODE (TREE_OPERAND (t1, 0)) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (TREE_OPERAND (t1, 0), 0)) == STRING_CST) + || (t2 && TREE_CODE (t2) == MEM_REF + && TREE_CODE (TREE_OPERAND (t2, 0)) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (TREE_OPERAND (t2, 0), 0)) == STRING_CST))) + FAIL; + out = operands[0]; if (!REG_P (out)) out = gen_reg_rtx (SImode);