From patchwork Fri Jun 14 12:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1947920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=dO8sbUQ8; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=pWNjExci; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=dO8sbUQ8; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=pWNjExci; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0zkP2VfRz20Pb for ; Fri, 14 Jun 2024 22:54:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31F2F388267A for ; Fri, 14 Jun 2024 12:54:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id B62D3388216F for ; Fri, 14 Jun 2024 12:53:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B62D3388216F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B62D3388216F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718369632; cv=none; b=xzVqiTc5TCH2JYi1Q7JK3LgKP+bzSfTmfOf8ftZYqnvnhCRVwdHbpw2yl1JAD+MakWfHtRFwQ7mgKKobE0N4qM/1c95ZYICFFwftwMXHES44kkcSjZalFkKujnYzOGr/Zcy50R8tOil94P53cgxfhFCgBb9ELyp/AetbQuv9F1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718369632; c=relaxed/simple; bh=VlqxGZNtqPGT9LEXtnC9DYRryajMyX2rCwU5M9axY54=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=F5p5VT95zwdwZTpmE1J52Wj/9BqG47roAPIa7SEoy0uSnqbiDG/2DNWYke6on3QN+6cYtbX/hBg18TZA4SIVfdFx6aw9v5rBGNll/rpHui8LLAf9kpRL7AMPnz/nsvuzY2ZDfitqw2J+UIy1/KtdHzc5oZmY8v1c8XSxoqyxPRs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AA886225DC; Fri, 14 Jun 2024 12:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718369628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BgSsj9dhbFQK4Sy5w+EgtMVgzZzAYs1H5Xwzg4A+NSc=; b=dO8sbUQ8ckapIm2SnxoT2DHCzUyw7YoLJ7JtP+9HKXwnD8QBkH/GzcsgRQzDc1Mk7JTB+r QPiUjHldFesOqn8B3LGLaYqmJYASBCJwML5M1fUH8Y4KjC1rj6zv4CZwBTL1+eQfYOtEWE alShEt/5xXeff450bQA+kgNzCMfPDZA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718369628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BgSsj9dhbFQK4Sy5w+EgtMVgzZzAYs1H5Xwzg4A+NSc=; b=pWNjExciEgIRMkWn9v2FRB2ad5LlVaqNTSf0yR+HeCpVm0HeqmJ6CqCu5zUZGbCA8848Xw JcDE7enS0Q+4A0Aw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=dO8sbUQ8; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=pWNjExci DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718369628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BgSsj9dhbFQK4Sy5w+EgtMVgzZzAYs1H5Xwzg4A+NSc=; b=dO8sbUQ8ckapIm2SnxoT2DHCzUyw7YoLJ7JtP+9HKXwnD8QBkH/GzcsgRQzDc1Mk7JTB+r QPiUjHldFesOqn8B3LGLaYqmJYASBCJwML5M1fUH8Y4KjC1rj6zv4CZwBTL1+eQfYOtEWE alShEt/5xXeff450bQA+kgNzCMfPDZA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718369628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BgSsj9dhbFQK4Sy5w+EgtMVgzZzAYs1H5Xwzg4A+NSc=; b=pWNjExciEgIRMkWn9v2FRB2ad5LlVaqNTSf0yR+HeCpVm0HeqmJ6CqCu5zUZGbCA8848Xw JcDE7enS0Q+4A0Aw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 82C1F13AB1; Fri, 14 Jun 2024 12:53:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id b1FEHlw9bGYwMgAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 12:53:48 +0000 Date: Fri, 14 Jun 2024 14:53:48 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: richard.sandiford@arm.com, Jakub Jelinek Subject: [PATCH] Enhance if-conversion for automatic arrays MIME-Version: 1.0 Message-Id: <20240614125348.82C1F13AB1@imap1.dmz-prg2.suse.org> X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: AA886225DC X-Spam-Score: -4.51 X-Spam-Level: X-Spam-Status: No, score=-11.7 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Automatic arrays that are not address-taken should not be subject to store data races. This applies to OMP SIMD in-branch lowered functions result array which for the testcase otherwise prevents vectorization with SSE and for AVX and AVX512 ends up with spurious .MASK_STORE to the stack surviving. This inefficiency was noted in PR111793. Bootstrap and regtest running on x86_64-unknown-linux-gnu. Is my idea of store data races correct? At least phiopt uses the same check but for example LIM doesn't special-case locals. PR tree-optimization/111793 * tree-if-conv.cc (ifcvt_memrefs_wont_trap): For stores that do not trap only consider -fstore-data-races when the underlying object is not automatic or has its address taken. * gcc.dg/vect/vect-simd-clone-21.c: New testcase. --- gcc/testsuite/gcc.dg/vect/vect-simd-clone-21.c | 16 ++++++++++++++++ gcc/tree-if-conv.cc | 13 +++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/vect-simd-clone-21.c diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-21.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-21.c new file mode 100644 index 00000000000..49c52fb59bd --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-21.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_simd_clones } */ +/* { dg-additional-options "-fopenmp-simd" } */ + +#pragma omp declare simd simdlen(4) inbranch +__attribute__((noinline)) int +foo (int a, int b) +{ + return a + b; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 4 "vect" { target i?86-*-* x86_64-*-* } } } */ +/* if-conversion shouldn't need to resort to masked stores for the result + array created by OMP lowering since that's automatic and does not have + its address taken. */ +/* { dg-final { scan-tree-dump-not "MASK_STORE" "vect" } } */ diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index c4c3ed41a44..974c614edf3 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -934,14 +934,23 @@ ifcvt_memrefs_wont_trap (gimple *stmt, vec drs) if (DR_IS_READ (a)) return true; + bool ok = flag_store_data_races; + base = get_base_address (base); + if (DECL_P (base) + && auto_var_in_fn_p (base, cfun->decl) + && ! may_be_aliased (base)) + /* Automatic variables not aliased are not subject to + data races. */ + ok = true; + /* an unconditionaly write won't trap if the base is written to unconditionally. */ if (base_master_dr && DR_BASE_W_UNCONDITIONALLY (*base_master_dr)) - return flag_store_data_races; + return ok; /* or the base is known to be not readonly. */ else if (base_object_writable (DR_REF (a))) - return flag_store_data_races; + return ok; } return false;