From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 127E23857C72 for ; Tue, 30 Aug 2022 10:18:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 127E23857C72 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3203923A; Tue, 30 Aug 2022 03:18:44 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 551243F766; Tue, 30 Aug 2022 03:18:37 -0700 (PDT) From: Richard Sandiford To: Richard Biener via Gcc-patches Mail-Followup-To: Richard Biener via Gcc-patches ,Tamar Christina , Richard Biener , nd@arm.com, richard.sandiford@arm.com Cc: Tamar Christina , Richard Biener , nd@arm.com Subject: Re: [PATCH][committed]middle-end intialize regnum in store_bit_field_1 References: Date: Tue, 30 Aug 2022 11:18:36 +0100 In-Reply-To: (Richard Biener via Gcc-patches's message of "Tue, 30 Aug 2022 06:46:16 +0000 (UTC)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-49.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,KAM_NUMSUBJECT,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Richard Biener via Gcc-patches writes: > On Tue, 30 Aug 2022, Tamar Christina wrote: > >> Hi All, >> >> This initializes regnum to 0 for when undefined_p. >> 0 is the right default as it's supposed to get the lowpart >> when undefined. >> >> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. >> >> Ok for master? > > OK. I'm not sure this is the right fix. We were still supposed to use the correct byte offset in the undefined case. Is the attached OK? Tested on aarch64-linux-gnu. Thanks, Richard ---------------------- store_bit_field_1 tries to convert a field assignment into a subreg assignment. Normally it must check that the field occupies a full word (or more specifically, a full REGMODE_NATURAL_SIZE chunk), so that writing to the subreg doesn't clobber any other fields. But it can skip that check if the structure is known to be in an undefined state. The idea was that, in the undefined case, we could rely on simplify_gen_subreg to do the check for a valid subreg, rather than having to repeat the required endianness logic in the caller. Before the addition of the undefined case, the code could use regnum * regsize to get the byte offset, where regnum came from checking that the start was word-aligned. In the undefined case we need to calculate the byte offset explicitly. gcc/ * expmed.cc (store_bit_field_1): Fix byte offset calculation for undefined structures. --- gcc/expmed.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/expmed.cc b/gcc/expmed.cc index 8d7418be418..6c02c3bb850 100644 --- a/gcc/expmed.cc +++ b/gcc/expmed.cc @@ -794,7 +794,7 @@ store_bit_field_1 (rtx str_rtx, poly_uint64 bitsize, poly_uint64 bitnum, words or to cope with mode punning between equal-sized modes. In the latter case, use subreg on the rhs side, not lhs. */ rtx sub; - HOST_WIDE_INT regnum; + poly_uint64 bytenum; poly_uint64 regsize = REGMODE_NATURAL_SIZE (GET_MODE (op0)); if (known_eq (bitnum, 0U) && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (op0)))) @@ -808,13 +808,13 @@ store_bit_field_1 (rtx str_rtx, poly_uint64 bitsize, poly_uint64 bitnum, return true; } } - else if (((constant_multiple_p (bitnum, regsize * BITS_PER_UNIT, ®num) - && multiple_p (bitsize, regsize * BITS_PER_UNIT)) - || undefined_p) + else if (multiple_p (bitnum, BITS_PER_UNIT, &bytenum) + && (undefined_p + || (multiple_p (bitnum, regsize * BITS_PER_UNIT) + && multiple_p (bitsize, regsize * BITS_PER_UNIT))) && known_ge (GET_MODE_BITSIZE (GET_MODE (op0)), bitsize)) { - sub = simplify_gen_subreg (fieldmode, op0, GET_MODE (op0), - regnum * regsize); + sub = simplify_gen_subreg (fieldmode, op0, GET_MODE (op0), bytenum); if (sub) { if (reverse) -- 2.25.1