From patchwork Wed Nov 16 19:22:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 82601 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp336819qge; Wed, 16 Nov 2016 11:23:28 -0800 (PST) X-Received: by 10.99.95.86 with SMTP id t83mr11694958pgb.0.1479324208515; Wed, 16 Nov 2016 11:23:28 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d5si33136794pgj.17.2016.11.16.11.23.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Nov 2016 11:23:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441712-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-441712-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441712-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=gAOjxJiSt5CXI1l3PGHwQL8Z7M49dNCg+IYkUW/k8J7 OQgOrXZiqG/2tZ/EKdyjFiTGnkJJRSXrIKJ7JZQU3SrVE2YlmY9gcBxaHPEOWBjZ tjIviVRMwzWos8aYEkdQzTcmwaqTA2NXG68J2HWrH5rhSL+V/XIUM3U+JdH9N/9k = 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=2hvyg9VCgN9IU8qcOPVXjZ/XyIM=; b=UjPH2pVAMuKq9w1SP sJrE7URqd8BLQXw/BiacWOMgwnXgz5Z1Y3LODmkXjdJ8Wr8LREsvuMu2pLdRY7A0 zRd0wa/5hpinGvlB2SxZjqzlSii4pJZXktbTUDr/PPkO7DyQZrTKO4iDokIulS/7 h4iX0jMfr13hU4XTM7RU++MKoE= Received: (qmail 45520 invoked by alias); 16 Nov 2016 19:22:46 -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 45444 invoked by uid 89); 16 Nov 2016 19:22:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 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, Hx-languages-length:2281, Technology, technology 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; Wed, 16 Nov 2016 19:22:35 +0000 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAGJIjn6044595 for ; Wed, 16 Nov 2016 14:22:33 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 26rt7f3mk2-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Nov 2016 14:22:32 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Nov 2016 12:22:32 -0700 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 16 Nov 2016 12:22:28 -0700 Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id DEE331FF0026; Wed, 16 Nov 2016 12:22:06 -0700 (MST) Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAGJMR3244171394; Wed, 16 Nov 2016 12:22:27 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C5636E048; Wed, 16 Nov 2016 12:22:27 -0700 (MST) Received: from ragesh3a (unknown [9.85.128.170]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 055126E035; Wed, 16 Nov 2016 12:22:25 -0700 (MST) Subject: [PATCH v2 1/2, i386] cmpstrnsi needs string length From: Aaron Sawdey To: "gcc-patches@gcc.gnu.org" Cc: Richard Biener , Kaz Kojima , olegendo@gcc.gnu.org, Nick Clifton , Jeff Law , Uros Bizjak , DavidEdelsohn Date: Wed, 16 Nov 2016 13:22:20 -0600 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111619-0004-0000-0000-000010DE7F7C 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:31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111619-0005-0000-0000-00007AA3DB53 Message-Id: <1479324140.6279.30.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 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. I've also changed the pattern to indicate that operand 3 may be clobbered (if it happens to be in cx already). 2016-11-16  Aaron Sawdey   * config/i386/i386.md (cmpstrnsi): New test to bail out if neither string input is a string constant.  Clobber length argument. -- 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/config/i386/i386.md =================================================================== --- gcc/config/i386/i386.md (revision 242428) +++ gcc/config/i386/i386.md (working copy) @@ -16898,7 +16898,7 @@ [(set (match_operand:SI 0 "register_operand") (compare:SI (match_operand:BLK 1 "general_operand") (match_operand:BLK 2 "general_operand"))) - (use (match_operand 3 "general_operand")) + (clobber (match_operand 3 "general_operand")) (use (match_operand 4 "immediate_operand"))] "" { @@ -16911,6 +16911,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);