From patchwork Thu Jul 13 08:58:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107641 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1939755qge; Thu, 13 Jul 2017 01:59:59 -0700 (PDT) X-Received: by 10.98.245.207 with SMTP id b76mr60998279pfm.113.1499936399303; Thu, 13 Jul 2017 01:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499936399; cv=none; d=google.com; s=arc-20160816; b=Tqot0OMC0HxLlBMsI71BjXljQ3PusJV8jpY5j7+ru0lieSgxg/r0BYAEOYFLwcRtrI /8kqtsKyKc6Sn/GUpuYQYJiyVGu4Mr+N+aPIGNynL7N8r2gQTKn+dpeSD0vG32RnrEfg YWlNrvHVbpyWEw3AMOGkvOJ6l48dWt0arHtE5pkrGkO2ktQIKPWazFPRZr0vsgEd3KN6 ImvI9RDVa6tT5JE9DKqSkGq9nz9XUfezC7EeHBgWvj5K4sjo3s3HPh3sj6WAlrSV0e7w j59UtpLWAxnzZgpS5pOaB+qQX+3+JDYBxua8q7qtzsuYfR/ZnvcncoPedfV/cRnMZtb7 4gEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=RCvh/H+IhPk+WI2jpQSuJ0+OsqxcgfYaVKAfPfLEyoc=; b=NnLwJnKegYAIRPC3j1UPHm1X71+VERQYD4PzBfh/zHPQ+4yFSdKKB7NTUDwaBenVKH opamjrGNWO/PkctQOrodmVWV7b5458JUsLpzXPKgJ/3WkgJCd7LlczWhgdIZy1d/qB1c M8shPCfX+8hYIwGhg5iAAnHreSC83I5VQ3l86V5VwDdOcGWQzQxRAHY1JYWnV09qLZkE whOYtABuKBf6vpAXALmbRJcXZB4cFSs2PXg2OudCIBqvd7SYTaqg1ST2MK75ujoEvPsd q0uTY9+XFUCTZLbS0CaZLFepPHZsOkp/q6qhywgeV31x9Diml+2u5hZLwmJBc72MVwfd nEwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=NJ3yQqCT; spf=pass (google.com: domain of gcc-patches-return-458046-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458046-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id u19si3819734pgj.527.2017.07.13.01.59.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:59:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458046-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 header.b=NJ3yQqCT; spf=pass (google.com: domain of gcc-patches-return-458046-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458046-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=A5CsHTPko8XxLxltx2ol80uzbE5vh 4oRdr0xod65eQyIAM3P0tLlRd+IRvUS6WHm3c5Y9Y1J/SBO40UEEvGeB01vs976+ ORcmA3sCkPynl2wRmOvFz/dh2mGMtA2rE9jgyyb17f6rVgCKzUSeKoUZZh4qMIP+ K8oG5jUqjoXehA= 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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=kI1DDk7R8cbpYmP/ACvYQd4I34A=; b=NJ3 yQqCT9hbv2EZoUILTbV44Y566xdZnvZpnys+PJHQ0trSftumbFhKr+7SlnihaWHd F7bk7wq+SycEDkT8n4ka2i3I8eUgz1Pnc/DPtFpWCCGauxksI15Ka+S0yS8v33X1 Ultkc92en8MsBjKWDX6WqRWJyNNWEeiWJNIv4qAo= Received: (qmail 106614 invoked by alias); 13 Jul 2017 08:58:12 -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 105867 invoked by uid 89); 13 Jul 2017 08:58:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=16857 X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:58:09 +0000 Received: by mail-wm0-f54.google.com with SMTP id 62so16829907wmw.1 for ; Thu, 13 Jul 2017 01:58:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=RCvh/H+IhPk+WI2jpQSuJ0+OsqxcgfYaVKAfPfLEyoc=; b=I47lnnZ3yTXP6+hi7PNvxb5qxzzZZ/dOG/ShEGBs48Ay/gOn1u+2vv/njkH5kEdYyc aXfIXQ52APAxwXHonJW2/DQJNWJD7aT2OXZmnyfMe9uEhXblBq0lLskVCbm1CwriiOBv Z4NOl5bWbs68W4C5Gq4jYlY9KsPLjzUQS1ZPJ9cKX7ntykdRa+4da1xyJYvAvB1JUMwN CS3EY3lCOmRtY45hJodWDS7jnlbw6ncdjeF5v+eDCFgK393/Vh7cOGLVLbkwZchcTuoH bzUJgFB+rK0jhHMEGz6wtf5kRE9k34qNrDJ6wwj13bPBec2452HwiIs6Kw3DVGIAbo4E pdnA== X-Gm-Message-State: AIVw11182RaMq9rvWXzmNpVh6lat6vMalnp9mItGHs5xOcZ2xCL8lT5m 9qV5miR2ay1PpuTdsjbdYg== X-Received: by 10.28.12.66 with SMTP id 63mr1072000wmm.130.1499936286939; Thu, 13 Jul 2017 01:58:06 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id l186sm6374336wma.10.2017.07.13.01.58.05 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:58:06 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [55/77] Use scalar_int_mode in simplify_const_unary_operation References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:58:04 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87k23cemsj.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 The main scalar integer block in simplify_const_unary_operation had the condition: if (CONST_SCALAR_INT_P (op) && width > 0) where "width > 0" was a roundabout way of testing != VOIDmode. This patch replaces it with a check for a scalar_int_mode instead. It also uses the number of bits in the input rather than the output mode to determine the result of a "count ... bits in zero" operation. (At the momemnt these modes have to be the same, but it still seems conceptually wrong to use the number of bits in the output mode.) The handling of float->integer ops also checked "width > 0", but this was redundant with the earlier check for MODE_INT. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * simplify-rtx.c (simplify_const_unary_operation): Use is_a instead of checking for a nonzero precision. Forcibly convert op_mode to a scalar_int_mode in that case. More clearly differentiate the operand and result modes and use the former when deciding what the value of a count-bits operation should be. Use is_int_mode instead of checking for a MODE_INT. Remove redundant check for whether this mode has a zero precision. Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2017-07-13 09:18:39.593733475 +0100 +++ gcc/simplify-rtx.c 2017-07-13 09:18:48.356023575 +0100 @@ -1685,7 +1685,7 @@ simplify_unary_operation_1 (enum rtx_cod simplify_const_unary_operation (enum rtx_code code, machine_mode mode, rtx op, machine_mode op_mode) { - unsigned int width = GET_MODE_PRECISION (mode); + scalar_int_mode result_mode; if (code == VEC_DUPLICATE) { @@ -1800,10 +1800,13 @@ simplify_const_unary_operation (enum rtx return const_double_from_real_value (d, mode); } - if (CONST_SCALAR_INT_P (op) && width > 0) + if (CONST_SCALAR_INT_P (op) && is_a (mode, &result_mode)) { + unsigned int width = GET_MODE_PRECISION (result_mode); wide_int result; - machine_mode imode = op_mode == VOIDmode ? mode : op_mode; + scalar_int_mode imode = (op_mode == VOIDmode + ? result_mode + : as_a (op_mode)); rtx_mode_t op0 = rtx_mode_t (op, imode); int int_value; @@ -1832,35 +1835,35 @@ simplify_const_unary_operation (enum rtx break; case FFS: - result = wi::shwi (wi::ffs (op0), mode); + result = wi::shwi (wi::ffs (op0), result_mode); break; case CLZ: if (wi::ne_p (op0, 0)) int_value = wi::clz (op0); - else if (! CLZ_DEFINED_VALUE_AT_ZERO (mode, int_value)) - int_value = GET_MODE_PRECISION (mode); - result = wi::shwi (int_value, mode); + else if (! CLZ_DEFINED_VALUE_AT_ZERO (imode, int_value)) + int_value = GET_MODE_PRECISION (imode); + result = wi::shwi (int_value, result_mode); break; case CLRSB: - result = wi::shwi (wi::clrsb (op0), mode); + result = wi::shwi (wi::clrsb (op0), result_mode); break; case CTZ: if (wi::ne_p (op0, 0)) int_value = wi::ctz (op0); - else if (! CTZ_DEFINED_VALUE_AT_ZERO (mode, int_value)) - int_value = GET_MODE_PRECISION (mode); - result = wi::shwi (int_value, mode); + else if (! CTZ_DEFINED_VALUE_AT_ZERO (imode, int_value)) + int_value = GET_MODE_PRECISION (imode); + result = wi::shwi (int_value, result_mode); break; case POPCOUNT: - result = wi::shwi (wi::popcount (op0), mode); + result = wi::shwi (wi::popcount (op0), result_mode); break; case PARITY: - result = wi::shwi (wi::parity (op0), mode); + result = wi::shwi (wi::parity (op0), result_mode); break; case BSWAP: @@ -1881,7 +1884,7 @@ simplify_const_unary_operation (enum rtx return 0; } - return immed_wide_int_const (result, mode); + return immed_wide_int_const (result, result_mode); } else if (CONST_DOUBLE_AS_FLOAT_P (op) @@ -1941,9 +1944,9 @@ simplify_const_unary_operation (enum rtx } else if (CONST_DOUBLE_AS_FLOAT_P (op) && SCALAR_FLOAT_MODE_P (GET_MODE (op)) - && GET_MODE_CLASS (mode) == MODE_INT - && width > 0) + && is_int_mode (mode, &result_mode)) { + unsigned int width = GET_MODE_PRECISION (result_mode); /* Although the overflow semantics of RTL's FIX and UNSIGNED_FIX operators are intentionally left unspecified (to ease implementation by target backends), for consistency, this routine implements the