From patchwork Wed Nov 15 15:40:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 838229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466875-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YarEsZDb"; dkim-atps=neutral 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 3ycT9S5MZ1z9s7C for ; Thu, 16 Nov 2017 02:40:44 +1100 (AEDT) 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=epmhE0gJ6aq5N+5fK7K408g2nvMvKfGdCJ7iU+4Ktbs zmHpHNZwsdfs+o0GWXj9ktg3FiqITP773cggCqXWveqZT8rDUpS8Lh7+Jsz9OcuX bSvJD644H2j9picK3CulRnMrcOM/HTWR7DqF9sXTfGJYVH2mlSd+W+Y+8/KDGkVY = 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=bYqmVbUP5VrH4V6CXbnVtiuSyPE=; b=YarEsZDbhvUXyv/L7 DrqFyfEj2SmX5Nbtw3bNNSlr6Ebx/sdgsnFu9/ShGyDFdezPs889uOMx0q0r4NGR c3eaIMqKFbP2HMws+/iOR34OcLp5IbRCUSJSaPi3nUfYods7n8vQP5Xv5/3WWuok y2YATHAmOQ1k2iQYkIJJwOKgxQ= Received: (qmail 33476 invoked by alias); 15 Nov 2017 15:40: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 32376 invoked by uid 89); 15 Nov 2017 15:40:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=promised, aaron, Aaron, rr 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, 15 Nov 2017 15:40:28 +0000 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAFFYxUt052701 for ; Wed, 15 Nov 2017 10:40:24 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e8qqhjnx0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 15 Nov 2017 10:40:23 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 15 Nov 2017 10:40:22 -0500 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 15 Nov 2017 10:40:20 -0500 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAFFeK1l47382622; Wed, 15 Nov 2017 15:40:20 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 304EC112051; Wed, 15 Nov 2017 10:39:45 -0500 (EST) Received: from ragesh3a (unknown [9.80.223.153]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id C8B5E112040; Wed, 15 Nov 2017 10:39:44 -0500 (EST) Subject: [PATCH] make canonicalize_condition keep its promise From: Aaron Sawdey To: gcc-patches@gcc.gnu.org Cc: ebotcazou@adacore.com, richard.sandiford@linaro.org, Segher Boessenkool Date: Wed, 15 Nov 2017 09:40:19 -0600 Mime-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17111515-0008-0000-0000-000002A1571F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008067; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00946270; UDB=6.00477638; IPR=6.00726567; BA=6.00005691; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018030; XFM=3.00000015; UTC=2017-11-15 15:40:22 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111515-0009-0000-0000-000037515E75 Message-Id: <1510760419.6005.3.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-15_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711150211 X-IsSubscribed: yes So, the story of this very small patch starts with me adding patterns for ppc instructions bdz[tf] and bdnz[tf] such as this: [(set (pc) (if_then_else (and (ne (match_operand:P 1 "register_operand" "c,*b,*b,*b") (const_int 1)) (match_operator 3 "branch_comparison_operator" [(match_operand 4 "cc_reg_operand" "y,y,y,y") (const_int 0)])) (label_ref (match_operand 0)) (pc))) (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*d*wi*c*l") (plus:P (match_dup 1) (const_int -1))) (clobber (match_scratch:P 5 "=X,X,&r,r")) (clobber (match_scratch:CC 6 "=X,&y,&y,&y")) (clobber (match_scratch:CCEQ 7 "=X,&y,&y,&y"))] However when this gets to the loop_doloop pass, we get an assert fail in iv_number_of_iterations():   gcc_assert (COMPARISON_P (condition)); This is happening because this branch insn tests two things ANDed together so the and is at the top of the expression, not a comparison. This condition is extracted from the insn by get_condition() which is pretty straightforward, and which calls canonicalize_condition() before returning it. Now, one could put a test for a jump condition that is not a conditional test in here but the comment for canonicalize_condition() says:    (1) The code will always be a comparison operation (EQ, NE, GT, etc.). So, this patch adds a test at the end that just returns 0 if the return rtx is not a comparison. As it happens, doloop conversion is not needed here because I'm already generating rtl for a branch-decrement counter based loop. If there is a better way to go about this please let me know and I'll revise/retest. Bootstrap and regtest pass on ppc64le and x86_64. Ok for trunk? Thanks, Aaron 2017-11-15  Aaron Sawdey   * rtlanal.c (canonicalize_condition): Return 0 if final rtx does not have a conditional at the top. Index: gcc/rtlanal.c =================================================================== --- gcc/rtlanal.c (revision 254553) +++ gcc/rtlanal.c (working copy) @@ -5623,7 +5623,11 @@ if (CC0_P (op0)) return 0; - return gen_rtx_fmt_ee (code, VOIDmode, op0, op1); + /* We promised to return a comparison. */ + rtx ret = gen_rtx_fmt_ee (code, VOIDmode, op0, op1); + if (COMPARISON_P (ret)) + return ret; + return 0; } /* Given a jump insn JUMP, return the condition that will cause it to branch