From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53835 invoked by alias); 11 Nov 2016 11:10:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 53816 invoked by uid 89); 11 Nov 2016 11:10:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 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=const0_rtx, ciao, UINTVAL, uintval 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; Fri, 11 Nov 2016 11:10:37 +0000 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uABB3nkE105399 for ; Fri, 11 Nov 2016 06:10:36 -0500 Received: from e06smtp06.uk.ibm.com (e06smtp06.uk.ibm.com [195.75.94.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 26nc3t2nmg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 11 Nov 2016 06:10:35 -0500 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 Nov 2016 11:10:33 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp06.uk.ibm.com (192.168.101.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 11 Nov 2016 11:10:32 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id A95D317D805A for ; Fri, 11 Nov 2016 11:12:53 +0000 (GMT) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uABBAVBl7012676 for ; Fri, 11 Nov 2016 11:10:31 GMT Received: from d06av07.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uABBAVYC032547 for ; Fri, 11 Nov 2016 06:10:31 -0500 Received: from oc5510024614.ibm.com (sig-9-145-7-56.uk.ibm.com [9.145.7.56]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uABBAUKx032540; Fri, 11 Nov 2016 06:10:31 -0500 Received: by oc5510024614.ibm.com (Postfix, from userid 500) id C1ACE17DD0; Fri, 11 Nov 2016 12:10:28 +0100 (CET) Date: Fri, 11 Nov 2016 11:10:00 -0000 From: Dominik Vogt To: Bernd Schmidt Cc: gcc-patches@gcc.gnu.org, Andreas Krebbel , Ulrich Weigand Subject: Re: [PATCH] Do not simplify "(and (reg) (const bit))" to if_then_else. Reply-To: vogt@linux.vnet.ibm.com Mail-Followup-To: vogt@linux.vnet.ibm.com, Bernd Schmidt , gcc-patches@gcc.gnu.org, Andreas Krebbel , Ulrich Weigand References: <20161031195610.GA3558@linux.vnet.ibm.com> <4c9dd4a4-9f4f-048c-67d5-8ace6bd6eb8c@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c9dd4a4-9f4f-048c-67d5-8ace6bd6eb8c@redhat.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111111-0024-0000-0000-0000024A90ED X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111111-0025-0000-0000-00002128E79C Message-Id: <20161111111028.GA30873@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-11-11_02:,, 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-1611110202 X-SW-Source: 2016-11/txt/msg01064.txt.bz2 On Mon, Nov 07, 2016 at 09:29:26PM +0100, Bernd Schmidt wrote: > On 10/31/2016 08:56 PM, Dominik Vogt wrote: > > >combine_simplify_rtx() tries to replace rtx expressions with just two > >possible values with an experession that uses if_then_else: > > > > (if_then_else (condition) (value1) (value2)) > > > >If the original expression is e.g. > > > > (and (reg) (const_int 2)) > > I'm not convinced that if_then_else_cond is the right place to do > this. That function is designed to answer the question of whether an > rtx has exactly one of two values and under which condition; I feel > it should continue to work this way. > > Maybe simplify_ternary_expression needs to be taught to deal with this case? But simplify_ternary_expression isn't called with the following test program (only tried it on s390x): void bar(int, int); int foo(int a, int *b) { if (a) bar(0, *b & 2); return *b; } combine_simplify_rtx() is called with (sign_extend:DI (and:SI (reg:SI 61) (const_int 2))) In the switch it calls simplify_unary_operation(), which return NULL. The next thing it does is call if_then_else_cond(), and that calls itself with the sign_extend peeled off: (and:SI (reg:SI 61) (const_int 2)) takes the "BINARY_P (x)" path and returns false. The problem exists only if the (and ...) is wrapped in ..._extend, i.e. the ondition dealing with (and ...) directly can be removed from the patch. So, all recursive calls to if_then_els_cond() return false, and finally the condition in else if (HWI_COMPUTABLE_MODE_P (mode) && pow2p_hwi (nz = nonzero_bits (x, mode)) is true. Thus, if if_then_else_cond should remain unchanged, the only place to fix this would be after the call to if_then_else_cond() in combine_simplify_rtx(). Actually, there already is some special case handling to override the return code of if_then_else_cond(): cond = if_then_else_cond (x, &true_rtx, &false_rtx); if (cond != 0 /* If everything is a comparison, what we have is highly unlikely to be simpler, so don't use it. */ ---> && ! (COMPARISON_P (x) && (COMPARISON_P (true_rtx) || COMPARISON_P (false_rtx)))) { rtx cop1 = const0_rtx; enum rtx_code cond_code = simplify_comparison (NE, &cond, &cop1); ---> if (cond_code == NE && COMPARISON_P (cond)) return x; ... Should be easy to duplicate the test in the if-body, if that is what you prefer: ... if (HWI_COMPUTABLE_MODE_P (GET_MODE (x)) && pow2p_hwi (nz = nonzero_bits (x, GET_MODE (x))) && ! ((code == SIGN_EXTEND || code == ZERO_EXTEND) && GET_CODE (XEXP (x, 0)) == AND && CONST_INT_P (XEXP (XEXP (x, 0), 0)) && UINTVAL (XEXP (XEXP (x, 0), 0)) == nz)) return x; (untested) Ciao Dominik ^_^ ^_^ -- Dominik Vogt IBM Germany