From patchwork Thu Jul 13 09:02:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107652 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1944358qge; Thu, 13 Jul 2017 02:04:17 -0700 (PDT) X-Received: by 10.84.133.38 with SMTP id 35mr8889438plf.141.1499936656802; Thu, 13 Jul 2017 02:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499936656; cv=none; d=google.com; s=arc-20160816; b=EvwzBvIotNvaYh/wix3J45qlNHhNwRshnqIs0tiKLrNjUTWqYSYy2A23tQShRTRGoL Rl8J6J0s9P0fX7oackK1uON2ZNEuvk8f6nSCvEL7OyJw3Io/dGTpVE/Kgm8aaA0V54t5 zKThZhODqzduyrAI4ZNL9ei/RNBngcze+p1wC4yiV/LtOSh/G/C8daHnsGkIVgBRgw6F KdDfMU7zMdzirV5Xxhn/icnTKU4/xtmxCrZXrMoPAQRqc9INO5+X2oMfZtdbI6qiANtG prSG7rlSpq5LlgRpa0bZSUBFsrPrVcwOy+Dz8RXuBkjNvvF7cSH0qH0qy7bOxsUlI6CU vNKg== 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=CRFdFxjIMkjbwvn0pQINXDnxVgrg0G62ZCclN89c2oc=; b=lTVgrrkvbgqFlTP518OZabIiNUEQB1BdTL9hlIRwXmjgofOUs16r5Vc/8v+9Bj+M46 mceCdVdexLZ90obJX/n/RlLCpfw3y0Dl8L47X7lywbBVYdOLH3W1macKCd8Xtc5xraJg y6mkuPl1Bh5cIUjZ8KMvdjo4hBQYcXO5B2sV7vU5ealwB0UogUB4j8+Qm3KbdjR1uqrF /BsSju4hd2ivBt8E+5F1eCSjWCHdFgtA1Fem/JtZFrDDoe4E8eKMo6mtmadqibY9hvRm 4s2wo68w8M6lKGzIZPtmkjPQrSgIvkBAKDvLGO9jM6wvArkzIM351VwCRoX6Fubayv9V u3DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=llBBS3Yj; spf=pass (google.com: domain of gcc-patches-return-458057-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458057-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 e39si3856426plg.499.2017.07.13.02.04.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 02:04:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458057-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=llBBS3Yj; spf=pass (google.com: domain of gcc-patches-return-458057-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458057-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=ZrypCVjs0nX8cik7RcaiPKE06L50A P4wvp2XWj0ZdyZ8ri5JCxei+PFix5l305NiNa8Dxon78oO+AckGQixiLR80aisy3 VgeTmQhByGpvBeewaa+VMBKqqB1tTrmlsTGCQkLfudgX9Kth5/PWRGnLtnxvdP2C 9R1CmDO02QddWo= 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=SQmT86BL6rMU9IkWVR46SU3r95s=; b=llB BS3YjjJKYc4jAfjm6pub5pT4NA3MwfRXHn2htyAnANq9v6uP59tgBAVuQ8yFiQut uxnJHaewTblnpxUBppMKjHtbIs84O1SinBH8Zuw03PF5u/nyBYmxoNp0pVWj4QZy EBSAd6MXBCOAvP8LvzOjMUTmO4iBqy2uYrzKRn+c= Received: (qmail 97611 invoked by alias); 13 Jul 2017 09:02:17 -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 96909 invoked by uid 89); 13 Jul 2017 09:02:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=plenty, fitted X-HELO: mail-wr0-f180.google.com Received: from mail-wr0-f180.google.com (HELO mail-wr0-f180.google.com) (209.85.128.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 09:02:12 +0000 Received: by mail-wr0-f180.google.com with SMTP id k67so49520631wrc.2 for ; Thu, 13 Jul 2017 02:02:10 -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=CRFdFxjIMkjbwvn0pQINXDnxVgrg0G62ZCclN89c2oc=; b=rc+xgF/Svk88V9BWVdGOzq/PP0qyGCKccsRUE/fcLKt7rGvX3CbunmzGukjNHGAVjc AFPLoDAAgDV1OQf8GX6Czi6Xqua2CLxwrEBmTKutix7e49rVvqSmTLLAmQyEBlqFacS5 EhYt7iYaOTx2oF3dR4cY7XNOPsY8ykZYynSkME3IM2NLIW5mPl5MA7Of80Mb0DK/apuC zwRVP3jZcGg7iz50oKYvvd5FS2xEMM5gI4zcqN/1Cg0fX0dj7dQpPVQqifo6qdPUhKbj 5+D5oLOjrSscxUynApMve2uw3EMNcE6+CyrYjNxJoXZrLjDu2xb4vFmI4q/sS1vlFrhh f7pQ== X-Gm-Message-State: AIVw111bYV9JXzXZ7tIayEKdT5Z56URIGGR24jo1bjTx11Kt3YVzR9uB gfZn0RseJgwixx5O/+ATrw== X-Received: by 10.223.149.99 with SMTP id 90mr970713wrs.46.1499936528500; Thu, 13 Jul 2017 02:02:08 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id y76sm1590010wmh.2.2017.07.13.02.02.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 02:02:07 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [66/77] Use scalar_mode for constant integers References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 10:02:05 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <878tjsd81e.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch treats the mode associated with an integer constant as a scalar_mode. We can't use the more natural-sounding scalar_int_mode because we also use (const_int 0) for bounds-checking modes. (It might be worth adding a bounds-specific code instead, but that's for another day.) This exposes a latent bug in simplify_immed_subreg, which for vectors of CONST_WIDE_INTs would pass the vector mode rather than the element mode to rtx_mode_t. I think the: /* We can get a 0 for an error mark. */ || GET_MODE_CLASS (mode) == MODE_VECTOR_INT || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT in immed_double_const is dead. trunc_int_mode (via gen_int_mode) would go on to ICE if the mode fitted in a HWI, and surely plenty of other code would be confused to see a const_int be interpreted as a vector. We should instead be using CONST0_RTX (mode) if we need a safe constant for a particular mode. We didn't try to make these functions take scalar_mode arguments because in many cases that would be too invasive at this stage. Maybe it would become feasible in future. Also, the long-term direction should probably be to add modes to constant integers rather than have then as VOIDmode odd-ones-out. That would remove the need for rtx_mode_t and thus remove the question whether they should use scalar_int_mode, scalar_mode or machine_mode. The patch also uses scalar_mode for the CONST_DOUBLE handling in loc_descriptor. In that case the mode can legitimately be either floating-point or integral. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * emit-rtl.c (immed_double_const): Use is_a instead of separate mode class checks. Do not allow vector modes here. (immed_wide_int_const): Use as_a . * explow.c (trunc_int_for_mode): Likewise. * rtl.h (wi::int_traits::get_precision): Likewise. (wi::shwi): Likewise. (wi::min_value): Likewise. (wi::max_value): Likewise. * dwarf2out.c (loc_descriptor): Likewise. * simplify-rtx.c (simplify_immed_subreg): Fix rtx_mode_t argument for CONST_WIDE_INT. Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c 2017-07-13 09:18:51.646771977 +0100 +++ gcc/emit-rtl.c 2017-07-13 09:18:54.682546579 +0100 @@ -599,7 +599,8 @@ lookup_const_wide_int (rtx wint) immed_wide_int_const (const wide_int_ref &v, machine_mode mode) { unsigned int len = v.get_len (); - unsigned int prec = GET_MODE_PRECISION (mode); + /* Not scalar_int_mode because we also allow pointer bound modes. */ + unsigned int prec = GET_MODE_PRECISION (as_a (mode)); /* Allow truncation but not extension since we do not know if the number is signed or unsigned. */ @@ -659,18 +660,10 @@ immed_double_const (HOST_WIDE_INT i0, HO (i.e., i1 consists only from copies of the sign bit, and sign of i0 and i1 are the same), then we return a CONST_INT for i0. 3) Otherwise, we create a CONST_DOUBLE for i0 and i1. */ - if (mode != VOIDmode) - { - gcc_assert (GET_MODE_CLASS (mode) == MODE_INT - || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT - /* We can get a 0 for an error mark. */ - || GET_MODE_CLASS (mode) == MODE_VECTOR_INT - || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT - || GET_MODE_CLASS (mode) == MODE_POINTER_BOUNDS); - - if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) - return gen_int_mode (i0, mode); - } + scalar_mode smode; + if (is_a (mode, &smode) + && GET_MODE_BITSIZE (smode) <= HOST_BITS_PER_WIDE_INT) + return gen_int_mode (i0, mode); /* If this integer fits in one word, return a CONST_INT. */ if ((i1 == 0 && i0 >= 0) || (i1 == ~0 && i0 < 0)) Index: gcc/explow.c =================================================================== --- gcc/explow.c 2017-07-13 09:18:51.647771901 +0100 +++ gcc/explow.c 2017-07-13 09:18:54.682546579 +0100 @@ -49,14 +49,16 @@ static rtx break_out_memory_refs (rtx); HOST_WIDE_INT trunc_int_for_mode (HOST_WIDE_INT c, machine_mode mode) { - int width = GET_MODE_PRECISION (mode); + /* Not scalar_int_mode because we also allow pointer bound modes. */ + scalar_mode smode = as_a (mode); + int width = GET_MODE_PRECISION (smode); /* You want to truncate to a _what_? */ gcc_assert (SCALAR_INT_MODE_P (mode) || POINTER_BOUNDS_MODE_P (mode)); /* Canonicalize BImode to 0 and STORE_FLAG_VALUE. */ - if (mode == BImode) + if (smode == BImode) return c & 1 ? STORE_FLAG_VALUE : 0; /* Sign-extend for the requested mode. */ Index: gcc/rtl.h =================================================================== --- gcc/rtl.h 2017-07-13 09:18:51.662770770 +0100 +++ gcc/rtl.h 2017-07-13 09:18:54.682546579 +0100 @@ -2120,8 +2120,7 @@ typedef std::pair rt inline unsigned int wi::int_traits ::get_precision (const rtx_mode_t &x) { - gcc_checking_assert (x.second != BLKmode && x.second != VOIDmode); - return GET_MODE_PRECISION (x.second); + return GET_MODE_PRECISION (as_a (x.second)); } inline wi::storage_ref @@ -2166,7 +2165,7 @@ wi::int_traits ::decompose ( inline wi::hwi_with_prec wi::shwi (HOST_WIDE_INT val, machine_mode mode) { - return shwi (val, GET_MODE_PRECISION (mode)); + return shwi (val, GET_MODE_PRECISION (as_a (mode))); } /* Produce the smallest number that is represented in MODE. The precision @@ -2174,7 +2173,7 @@ wi::shwi (HOST_WIDE_INT val, machine_mod inline wide_int wi::min_value (machine_mode mode, signop sgn) { - return min_value (GET_MODE_PRECISION (mode), sgn); + return min_value (GET_MODE_PRECISION (as_a (mode)), sgn); } /* Produce the largest number that is represented in MODE. The precision @@ -2182,7 +2181,7 @@ wi::min_value (machine_mode mode, signop inline wide_int wi::max_value (machine_mode mode, signop sgn) { - return max_value (GET_MODE_PRECISION (mode), sgn); + return max_value (GET_MODE_PRECISION (as_a (mode)), sgn); } extern void init_rtlanal (void); Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c 2017-07-13 09:18:51.644772127 +0100 +++ gcc/dwarf2out.c 2017-07-13 09:18:54.681546653 +0100 @@ -15781,10 +15781,11 @@ loc_descriptor (rtx rtl, machine_mode mo or a floating-point constant. A CONST_DOUBLE is used whenever the constant requires more than one word in order to be adequately represented. We output CONST_DOUBLEs as blocks. */ + scalar_mode smode = as_a (mode); loc_result = new_loc_descr (DW_OP_implicit_value, - GET_MODE_SIZE (mode), 0); + GET_MODE_SIZE (smode), 0); #if TARGET_SUPPORTS_WIDE_INT == 0 - if (!SCALAR_FLOAT_MODE_P (mode)) + if (!SCALAR_FLOAT_MODE_P (smode)) { loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double; loc_result->dw_loc_oprnd2.v.val_double @@ -15793,7 +15794,7 @@ loc_descriptor (rtx rtl, machine_mode mo else #endif { - unsigned int length = GET_MODE_SIZE (mode); + unsigned int length = GET_MODE_SIZE (smode); unsigned char *array = ggc_vec_alloc (length); insert_float (rtl, array); Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2017-07-13 09:18:53.276650175 +0100 +++ gcc/simplify-rtx.c 2017-07-13 09:18:54.683546506 +0100 @@ -5785,7 +5785,7 @@ simplify_immed_subreg (machine_mode oute case CONST_WIDE_INT: { - rtx_mode_t val = rtx_mode_t (el, innermode); + rtx_mode_t val = rtx_mode_t (el, GET_MODE_INNER (innermode)); unsigned char extend = wi::sign_mask (val); int prec = wi::get_precision (val);