From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id D55703858C50 for ; Wed, 23 Mar 2022 14:57:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D55703858C50 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B26271F387; Wed, 23 Mar 2022 14:57:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 98F2F13302; Wed, 23 Mar 2022 14:57:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BSxZJFY1O2LWWgAAMHmgww (envelope-from ); Wed, 23 Mar 2022 14:57:26 +0000 Date: Wed, 23 Mar 2022 15:57:26 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: richard.earnshaw@arm.com Subject: [PATCH] target/102125 - alternative memcpy folding improvement MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20220323145726.98F2F13302@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2022 14:57:29 -0000 The following extends the heuristical memcpy folding path with the ability to use misaligned accesses on strict-alignment targets just like the size-based path does. That avoids regressing the following testcase on arm uint64_t bar64(const uint8_t *rData1) { uint64_t buffer; memcpy(&buffer, rData1, sizeof(buffer)); return buffer; } when r12-3482-g5f6a6c91d7c592 is reverted. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk. OK to revert r12-3482-g5f6a6c91d7c592? Thanks, Richard. 2022-03-23 Richard Biener PR target/102125 * gimple-fold.cc (gimple_fold_builtin_memory_op): Allow the use of movmisalign when either the source or destination decl is properly aligned. --- gcc/gimple-fold.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index c9179abb27e..5eff7d68ac1 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -1254,7 +1254,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, srcvar = fold_build2 (MEM_REF, desttype, src, off0); else { - if (STRICT_ALIGNMENT) + enum machine_mode mode = TYPE_MODE (desttype); + if ((mode == BLKmode && STRICT_ALIGNMENT) + || (targetm.slow_unaligned_access (mode, src_align) + && (optab_handler (movmisalign_optab, mode) + == CODE_FOR_nothing))) return false; srctype = build_aligned_type (TYPE_MAIN_VARIANT (desttype), src_align); @@ -1267,7 +1271,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, destvar = fold_build2 (MEM_REF, srctype, dest, off0); else { - if (STRICT_ALIGNMENT) + enum machine_mode mode = TYPE_MODE (srctype); + if ((mode == BLKmode && STRICT_ALIGNMENT) + || (targetm.slow_unaligned_access (mode, dest_align) + && (optab_handler (movmisalign_optab, mode) + == CODE_FOR_nothing))) return false; desttype = build_aligned_type (TYPE_MAIN_VARIANT (srctype), dest_align); -- 2.34.1