From patchwork Wed Aug 23 10:53:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 110733 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp3943432qge; Wed, 23 Aug 2017 03:54:04 -0700 (PDT) X-Received: by 10.98.202.214 with SMTP id y83mr2394053pfk.2.1503485644027; Wed, 23 Aug 2017 03:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503485644; cv=none; d=google.com; s=arc-20160816; b=ST2N+4SrYiLONsvOhr03IiN8wjC+Zwvkt8BOTt7rd8OpnUxNfhKjPdHc20sZ4svSfV +HnZbyYBYNiBGaH5uEELZ/tjQF4ZyTaDiydrlHB3+yYGCF3k25qwjuaXjkN7mi58IuKe J9rFSRvBQM7C2iNyqLoNRh8sfrne/kBC3bwseihjHLZpP6INtMUKpIU49kQEorchowAp /TYbTUWTwK85ANrkfcmrj1R4/y9ngJVYObgdWwhSn0FfuzSTAwnp4UOOchFwjftTjs1D Csv9zgjtN19d6HfIkDRv9EJyhz/KlLlmzkjykjxkE7v+O/H1TaWHDyVahyrztxSIY1WJ r9OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date: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=7vyFn4tntdJTwSNu7I1RcUUuEG/IDPACIxNlJgPnPQY=; b=hfuScG7L3obw9GjZckT71GoIm95WnhWTRi+Kya9xkjJYhYdEfyiGQp5mcttkx6JaXI BEIUMk1NgWkhvJE90xA+jBRWdkCzSx0yhjgC5MIms/OKwUzu6ldc2JtoZBuTb1RrHQdN B2hlj4Pbvz9aKEV0uemWS0KZ+J13qhLCuSeRfVn0p75orKpowPkaVbAOQ4O/ZiuCOU+3 D7Ro/G0pOczIADwXVgPGI+GrwAvh4B92f4IXBh/01+QU7GhLDaFEBeCP6JVrhGSaVivp cK+O3OJxLAZEr+Eq0Fp0BFECOI7UdK8cYZ2dmt8uqJq25a0nbCRQloAmWD3KfjGBVpyB H55w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bmMU+mWw; spf=pass (google.com: domain of gcc-patches-return-460786-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-460786-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 r81si868569pfb.189.2017.08.23.03.54.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 03:54:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-460786-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.s=default header.b=bmMU+mWw; spf=pass (google.com: domain of gcc-patches-return-460786-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-460786-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:date:message-id:mime-version:content-type; q=dns; s= default; b=XEr+McVCWt+1PB6wV7U+6B9Cq9uRG+TVSxIrswHbFlK7mhyTaUqsI BnMa/7va5HuNAeg2PAGrPHOMHGuIFtN3o5Z4icKiQsQQf9W79NyETd6YUepo4XO0 T3AmiFDv0fzn9lAcv1+5e6okL+Wj+la4MsLWiOV9tN2LbXGVZfL8X4= 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:date:message-id:mime-version:content-type; s= default; bh=r+jUFyuL430eWDlPDwvULP9ZhTM=; b=bmMU+mWwcpZmUJE1E7J0 ROdeVfZKAMJhQP0RyDtVSOIEMTB/S2y4DUDidGhjmpvtCWigIcLuIsrZ6uqzaJIt zsEuNB+trSpP+eOQGYRM6Z3dmwKDgZKFf70WtDlj+A0t+CGbKP/stnqDAe7Q4km7 FiVVuLoqjt00Vt5T/xDPoD8= Received: (qmail 7687 invoked by alias); 23 Aug 2017 10:53:52 -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 7671 invoked by uid 89); 23 Aug 2017 10:53:51 -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=refuse, 1218 X-HELO: mail-wm0-f42.google.com Received: from mail-wm0-f42.google.com (HELO mail-wm0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Aug 2017 10:53:49 +0000 Received: by mail-wm0-f42.google.com with SMTP id i17so691698wmb.0 for ; Wed, 23 Aug 2017 03:53:49 -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:date:message-id :user-agent:mime-version; bh=7vyFn4tntdJTwSNu7I1RcUUuEG/IDPACIxNlJgPnPQY=; b=im+FqmOTrRPys714s1HXYP8Sqo5jMNt1X/KCRPkTpGXAipQZsgKDlNZdecuJR9O6CT baLHrOK+NN1H5O9f9MvexJ+z3kYIniKNRtevFUklTnLbZfTxwtmjVrpA0kEBNrXHISOf d0+r3nRMenoPagROdh3/dF/wm2e9ZcAgS9D+WJgFjx1emLCdbvc+7uBuoHaal+MZ+NFn pMyZFPyRVA3IfdgmXeqioL9FAbs3rZ2uGi1YM8pxf+N/eRam10ULqiMudyhsb1do4sYz x74Z9rOjesb103rWIMUqKdZ49OrGaHMWGXQWsGi4hzDZYYY1oGFLkDyXaopax7nS0u75 Kz9A== X-Gm-Message-State: AHYfb5i7mhzpI8FxIvoHBzG4w1CqzhmGxr4abKhoqZnsq0MPhg17t7pY rouTfvgkR+p89OCQWlxAyQ== X-Received: by 10.28.88.143 with SMTP id m137mr1386730wmb.71.1503485627428; Wed, 23 Aug 2017 03:53:47 -0700 (PDT) Received: from localhost (92.40.249.210.threembb.co.uk. [92.40.249.210]) by smtp.gmail.com with ESMTPSA id w16sm2523265wrc.84.2017.08.23.03.53.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2017 03:53:46 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Make more use of byte_lowpart_offset Date: Wed, 23 Aug 2017 11:53:45 +0100 Message-ID: <87shgitv0m.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch uses byte_lowpart_offset in places that open-coded the calculation. Tested on aarch64-linux-gnu and x86_64-linux-gnu, and by making sure that there were no differences in testsuite assembly output for one target per CPU. OK to install? Richard 2017-08-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * caller-save.c (replace_reg_with_saved_mem): Use byte_lowpart_offset. * combine.c (gen_lowpart_for_combine): Likewise. * dwarf2out.c (rtl_for_decl_location): Likewise. * final.c (alter_subreg): Likewise. * rtlhooks.c (gen_lowpart_general): Likewise. (gen_lowpart_if_possible): Likewise. Index: gcc/caller-save.c =================================================================== --- gcc/caller-save.c 2017-08-23 10:44:56.292488492 +0100 +++ gcc/caller-save.c 2017-08-23 10:47:17.536760752 +0100 @@ -1129,17 +1129,7 @@ replace_reg_with_saved_mem (rtx *loc, { /* This is gen_lowpart_if_possible(), but without validating the newly-formed address. */ - int offset = 0; - - if (WORDS_BIG_ENDIAN) - offset = (MAX (GET_MODE_SIZE (GET_MODE (mem)), UNITS_PER_WORD) - - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); - if (BYTES_BIG_ENDIAN) - /* Adjust the address so that the address-after-the-data is - unchanged. */ - offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)) - - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (mem)))); - + HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (mem)); mem = adjust_address_nv (mem, mode, offset); } } Index: gcc/combine.c =================================================================== --- gcc/combine.c 2017-08-23 10:45:34.493718192 +0100 +++ gcc/combine.c 2017-08-23 10:47:17.537756580 +0100 @@ -11458,8 +11458,6 @@ gen_lowpart_for_combine (machine_mode om if (MEM_P (x)) { - int offset = 0; - /* Refuse to work on a volatile memory ref or one with a mode-dependent address. */ if (MEM_VOLATILE_P (x) @@ -11472,14 +11470,7 @@ gen_lowpart_for_combine (machine_mode om if (paradoxical_subreg_p (omode, imode)) return gen_rtx_SUBREG (omode, x, 0); - if (WORDS_BIG_ENDIAN) - offset = MAX (isize, UNITS_PER_WORD) - MAX (osize, UNITS_PER_WORD); - - /* Adjust the address so that the address-after-the-data is - unchanged. */ - if (BYTES_BIG_ENDIAN) - offset -= MIN (UNITS_PER_WORD, osize) - MIN (UNITS_PER_WORD, isize); - + HOST_WIDE_INT offset = byte_lowpart_offset (omode, imode); return adjust_address_nv (x, omode, offset); } Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c 2017-08-22 10:15:11.279742253 +0100 +++ gcc/dwarf2out.c 2017-08-23 10:47:17.539748235 +0100 @@ -19064,12 +19064,11 @@ rtl_for_decl_location (tree decl) else if (VAR_P (decl) && rtl && MEM_P (rtl) - && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)) - && BYTES_BIG_ENDIAN) + && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))) { machine_mode addr_mode = get_address_mode (rtl); - int rsize = GET_MODE_SIZE (GET_MODE (rtl)); - int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))); + HOST_WIDE_INT offset = byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl)), + GET_MODE (rtl)); /* If a variable is declared "register" yet is smaller than a register, then if we store the variable to memory, it @@ -19077,10 +19076,9 @@ rtl_for_decl_location (tree decl) fact we are not. We need to adjust the offset of the storage location to reflect the actual value's bytes, else gdb will not be able to display it. */ - if (rsize > dsize) + if (offset != 0) rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), - plus_constant (addr_mode, XEXP (rtl, 0), - rsize - dsize)); + plus_constant (addr_mode, XEXP (rtl, 0), offset)); } /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, Index: gcc/final.c =================================================================== --- gcc/final.c 2017-08-22 17:14:30.336881519 +0100 +++ gcc/final.c 2017-08-23 10:47:17.540744062 +0100 @@ -3205,14 +3205,7 @@ alter_subreg (rtx *xp, bool final_p) /* For paradoxical subregs on big-endian machines, SUBREG_BYTE contains 0 instead of the proper offset. See simplify_subreg. */ if (paradoxical_subreg_p (x)) - { - int difference = GET_MODE_SIZE (GET_MODE (y)) - - GET_MODE_SIZE (GET_MODE (x)); - if (WORDS_BIG_ENDIAN) - offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD; - if (BYTES_BIG_ENDIAN) - offset += difference % UNITS_PER_WORD; - } + offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y)); if (final_p) *xp = adjust_address (y, GET_MODE (x), offset); Index: gcc/rtlhooks.c =================================================================== --- gcc/rtlhooks.c 2017-07-13 09:25:12.420277223 +0100 +++ gcc/rtlhooks.c 2017-08-23 10:47:17.540744062 +0100 @@ -58,8 +58,6 @@ gen_lowpart_general (machine_mode mode, } else { - int offset = 0; - /* The only additional case we can do is MEM. */ gcc_assert (MEM_P (x)); @@ -70,16 +68,7 @@ gen_lowpart_general (machine_mode mode, && !reload_completed) return gen_lowpart_general (mode, force_reg (GET_MODE (x), x)); - if (WORDS_BIG_ENDIAN) - offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD) - - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); - - if (BYTES_BIG_ENDIAN) - /* Adjust the address so that the address-after-the-data - is unchanged. */ - offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)) - - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))); - + HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (x)); return adjust_address (x, mode, offset); } } @@ -132,19 +121,8 @@ gen_lowpart_if_possible (machine_mode mo else if (MEM_P (x)) { /* This is the only other case we handle. */ - int offset = 0; - rtx new_rtx; - - if (WORDS_BIG_ENDIAN) - offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD) - - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); - if (BYTES_BIG_ENDIAN) - /* Adjust the address so that the address-after-the-data is - unchanged. */ - offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)) - - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))); - - new_rtx = adjust_address_nv (x, mode, offset); + HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (x)); + rtx new_rtx = adjust_address_nv (x, mode, offset); if (! memory_address_addr_space_p (mode, XEXP (new_rtx, 0), MEM_ADDR_SPACE (x))) return 0;