From patchwork Mon Mar 23 13:22:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1260025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=I7U47Q8Z; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48mFRd6QLGz9sR4 for ; Tue, 24 Mar 2020 00:22:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C0FA63940CE9; Mon, 23 Mar 2020 13:22:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0FA63940CE9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584969755; bh=00kLNWe95CknwJDzvhU1QRzvteJ2yu+efjk8FqimXPo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=I7U47Q8Zdp4UejbUxF94lP5PrH3STc2DknNMxdzhtLbii3hYHfWYlMpjgpa7zwCwu 1EW/u17J51YeL6Tu7F1sgvG489mpqOcArHleAo1kvPnZCIHCisT43bCqP3Yz3+WhFg +qInvboZsW88Asc0qGBaTaP0zmzPwj7JnXhJTV9k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 914F2382EAC2 for ; Mon, 23 Mar 2020 13:22:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 914F2382EAC2 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02NDEX6D066600 for ; Mon, 23 Mar 2020 09:22:31 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ywf0mrgpd-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 23 Mar 2020 09:22:31 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Mar 2020 13:22:28 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 23 Mar 2020 13:22:27 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02NDMR5p59768878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 23 Mar 2020 13:22:27 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43F434C044 for ; Mon, 23 Mar 2020 13:22:27 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 11F454C046 for ; Mon, 23 Mar 2020 13:22:27 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.89.4]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS for ; Mon, 23 Mar 2020 13:22:26 +0000 (GMT) Date: Mon, 23 Mar 2020 14:22:25 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: recognize a signed rotate MIME-Version: 1.0 Content-Disposition: inline X-TM-AS-GCONF: 00 x-cbid: 20032313-0016-0000-0000-000002F63C8A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20032313-0017-0000-0000-00003359D550 Message-Id: <20200323132225.GA22674@localhost.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-23_04:2020-03-21, 2020-03-23 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 impostorscore=0 malwarescore=0 mlxlogscore=963 spamscore=0 clxscore=1015 lowpriorityscore=0 adultscore=0 suspectscore=3 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003230073 X-Spam-Status: No, score=-26.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Stefan Schulze Frielinghaus via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Stefan Schulze Frielinghaus Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi all, A rotate of a signed integer is not recognized so far. int32_t f (int32_t x) { return (x << 5) | (int32_t)((uint32_t)x >> 27); } The code above is unoptimized in contrast to a version consisting only of unsigned integers. I'm wondering if this is intended or not. Since GCC has well defined behavior for shifts where the first operand is signed, I assumed that this also holds for rotates. The attached patch adds a pattern to match.pd for such signed rotates. Any comments about this? Note, for the sake of simplicity the attached patch does not handle the case where the input is a signed integer and the result is an unsigned, i.e., the following case is not covered: uint32_t f (int32_t x) { return (x << 5) | ((uint32_t)x >> 27); } My gut feeling was that it's not worth it to have another pattern for such an impure rotate. Maybe I'm wrong? Cheers, Stefan diff --git a/gcc/match.pd b/gcc/match.pd index 9cb37740f1e..0297f8c9c89 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2986,6 +2986,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) { tree rotate_type = TREE_TYPE (@0); } (convert (rotate (convert:rotate_type @1) @2)))))) +/* Recognize a signed rotate: assume that X is signed and C1+C2=width(X) holds, + then (X << C1) | (s)((u)X >> C2) -> X r>> C2 where (s) and (u) denote the + signed and unsigned types of X, respectively. */ +(simplify + (bit_ior + (lshift @0 INTEGER_CST@1) + (convert (rshift@3 (convert @0) INTEGER_CST@2))) + (if (wi::eq_p (wi::add (wi::to_wide (@1), wi::to_wide (@2)), + TYPE_PRECISION (TREE_TYPE (@0))) + && TYPE_UNSIGNED (TREE_TYPE (@3))) + (rrotate @0 @2))) + /* Simplifications of conversions. */ /* Basic strip-useless-type-conversions / strip_nops. */