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 C31C83858400 for ; Thu, 22 Sep 2022 13:17:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C31C83858400 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 082441595; Thu, 22 Sep 2022 06:17:12 -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 F380C3F73B; Thu, 22 Sep 2022 06:17:04 -0700 (PDT) From: Richard Sandiford To: William Tambe via Gcc-help Mail-Followup-To: William Tambe via Gcc-help ,William Tambe , richard.sandiford@arm.com Cc: William Tambe Subject: Re: help removing unnecessary zero-extension References: Date: Thu, 22 Sep 2022 14:17:03 +0100 In-Reply-To: (William Tambe via Gcc-help's message of "Wed, 21 Sep 2022 16:57:39 -0500") 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=-41.6 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: William Tambe via Gcc-help writes: > Given following program: > > unsigned char var; > int main() { > return var; > } > > And compiled using: > pu32-elf-gcc -O3 -c -save-temps test.c > > Unnecessary zero-extension gets generated after a memory byte load > which already zero-extend. > > LOAD_EXTEND_OP has been defined as follow: > #define LOAD_EXTEND_OP(M) ZERO_EXTEND > > Find complete port at: > https://github.com/fontamsoc/gcc/commit/45840063 > And machine description at: > https://github.com/fontamsoc/gcc/blob/45840063/gcc/config/pu32/pu32.md > > Any idea what else can be tried to prevent the unnecessary zero-extension ? (Thanks for sharing the links. Unfortunately I can't look at unsubmitted code for copyright reasons, so the below is just a guess.) If you define LOAD_EXTEND_OP, it's still better to have a define_insn that can zero_extend a memory source operand to a wider register destination operand. Ideally there should be one instruction that handles both registers and memory -- rather than than two separate instructions -- since that helps the register allocator to produce better results. E.g. the aarch64 pattern for this operation is: (define_insn "*zero_extend2_aarch64" [(set (match_operand:GPI 0 "register_operand" "=r,r,w,r") (zero_extend:GPI (match_operand:SHORT 1 "nonimmediate_operand" "r,m,m,w")))] "" "@ and\t%0, %1, ldr\t%w0, %1 ldr\t%0, %1 umov\t%w0, %1.[0]" [(set_attr "type" "logic_imm,load_4,f_loads,neon_to_gp") (set_attr "arch" "*,*,fp,fp")] ) which is quite complicated, but it's the first two alternatives that matter here. Thanks, Richard