From patchwork Thu Jan 18 07:31:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 189022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp180493dyb; Wed, 17 Jan 2024 23:37:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEx5JziKEFaFca13pXq7Em/g4gC47JDXaRox9fOVzHiZnFxjBywD2UiD7pyzDkih7BrjvZd X-Received: by 2002:a05:620a:2453:b0:783:4cd7:ffd5 with SMTP id h19-20020a05620a245300b007834cd7ffd5mr382538qkn.78.1705563426233; Wed, 17 Jan 2024 23:37:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705563426; cv=pass; d=google.com; s=arc-20160816; b=abskLAlVjpCJ8eyXyu/p4H9awv6XUhfoMM8to7Ybdg2OjdBYOP0dYxVO4TKveAPSJx cmo+C1IDJH/ofr9KT0a5VZTQ5JoywpRPBt4NYXYj74tOM93qUCRC8n/a5YeoGO9p2XK8 ac2nEEziCF0mL2lHQZ2cAIR1R4o3TY7TZ0Mt4ZKQJk2Kg0jW9JBZA5lXp007+QnMBlT3 oQTEJ7DLIOKSJdX8ZPXI/j4lzMfC+QuqYxkfqQk/0g3R/ujK0tZqEWYDwEYLZ5HCyo4x 2vtKp7lHhUqYgVM2hI7nfDmdApjoKn+uwyTOMagWxVdEFnpfnYC8y0WMm2OLv6RS0PlD CDRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :subject:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=qpxAtIYvNJRcefu2muxX4UpRMOYnjRFDMQ3XvGheVc4=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=yzy+QIpa5qKnHS/gIP+yTQ4R6NwNzIF+qaSyEDQP3Stv5LPU7bhzT0a2jF63RYKAki I6QwQGubYGzquvn/ewjCFtVmZ/X6uiH48jfs1EH9HyKLGBfCyQUWvi1sx7bWxtn1k/vL VyDNMdcVibnjSqiJcngaAgSuOr1lZ37JpK5ia5v9QDXU1AbWPnnWr62yJL4RFWivhHs5 NeBaOHxbeaeI/Bgg942fGacH23cPcVigGAZ3HvpjU4dtr5kAYE7t248ulz5PqCLtgKd8 Wf3tAaNxs0ek06DOISrGY81OLH4H3LZWgcW/YvtEpyQmNc6LURofJ4bUMVSlHz+FK9Un 4kpA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=gEWcBDw0; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=bXwfGhqr; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h15-20020a05620a21cf00b007831a560be0si13275647qka.280.2024.01.17.23.37.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 23:37:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=gEWcBDw0; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=bXwfGhqr; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E43433858289 for ; Thu, 18 Jan 2024 07:37:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id F33C13858C29 for ; Thu, 18 Jan 2024 07:36:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F33C13858C29 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 F33C13858C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705563377; cv=none; b=bLfWPBb2I49A19prM2jGDJliaP5VB0RGjTRqx4/tPBVMIRq1grWUlJvgQZ4fhbwL7j7jxhN0rOuethTSZ5tn0L7mICXt6Xa0fPvtcc6xXbh2eCLxkKGO569yMilbc0XCuFP0dJOThPd4ByhjYDT3fjpMqPcey0l/wok6enD59Hk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705563377; c=relaxed/simple; bh=rqLtMH50s4ilYaPWFgQ2yf0UECXNy4ussCOOVK8NNlY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=STwjO4yxSac2/ACDyfW+nBJNuNcmHj0f9qMKUOBazUIhTAxQzGhAGCUYUwMBIeA303rU9anxZmg8w5vWk72S0peu443dBdw7Kf+R7FDrO3qWUYr64c3fL5PXNEU+ANZNRoS9/cxpyGVwiXNWppkVazkfv1yo+m/p+prao0cHing= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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-out2.suse.de (Postfix) with ESMTPS id E75051F769 for ; Thu, 18 Jan 2024 07:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705563374; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=qpxAtIYvNJRcefu2muxX4UpRMOYnjRFDMQ3XvGheVc4=; b=gEWcBDw0x41lXUgB2IHxPo6SaenO2NWrn6XTZ79f9zHQeVP9247guFqVAQgjnQzN7ctaub 9dZ4gymBN9eaa8Izs25/5EMn2AJiz57dL15qIeFfe8FZtVbbC65C13COx7BKqNPCmwIrFY ABTRJgKKL3wcE0OToSv13MHz0tz5Ymw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705563374; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=qpxAtIYvNJRcefu2muxX4UpRMOYnjRFDMQ3XvGheVc4=; b=SwIImN5gX2Hzq0cX2FQxVQkHvQZZGZdblcIWcmTm9I31sMBc9TZiwIch8nQCSwn+T0F1UX RrsXEh4GE7SYm7CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705563372; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=qpxAtIYvNJRcefu2muxX4UpRMOYnjRFDMQ3XvGheVc4=; b=bXwfGhqrwJRHQjrH21ZRDs7Q77a4ueD4vlgcfCNXEKkbKktWC/1sSDN/M9bQW8ifYSNRDo XfQVNrbOGUjB01BQiGXqGPYcAllHmgbo575QvZJEOVAXjTmseEHkWCgYrlMljeWNsU3AZe yGkTE3hjhM9FtmLjHE6kp6ZnrP9+eK8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705563372; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=qpxAtIYvNJRcefu2muxX4UpRMOYnjRFDMQ3XvGheVc4=; b=xmoHEYewNleNWuJyvlXkaSp1AsuTkklGOYOw6W0zVfXdutJiZfkaY1rwejXqlSDBTR8OJq CW2Bo0ZedFer00DQ== Date: Thu, 18 Jan 2024 08:31:04 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/113431 - wrong dependence with invariant load MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -1.42 X-Spamd-Result: default: False [-1.42 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.63)[-0.635]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.19)[-0.946]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-vect-data-refs.cc:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20240118073705.E43433858289@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788412875176925316 X-GMAIL-MSGID: 1788412875176925316 The vectorizer dependence analysis is confused with invariant loads when figuring whether the circumstances are so that we preserve scalar stmt execution order. The following rectifies this. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/113431 * tree-vect-data-refs.cc (vect_preserves_scalar_order_p): When there is an invariant load we might not preserve scalar order. * gcc.dg/vect/pr113431.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr113431.c | 18 ++++++++++++++++++ gcc/tree-vect-data-refs.cc | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/pr113431.c diff --git a/gcc/testsuite/gcc.dg/vect/pr113431.c b/gcc/testsuite/gcc.dg/vect/pr113431.c new file mode 100644 index 00000000000..04448d9dd81 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr113431.c @@ -0,0 +1,18 @@ +/* { dg-additional-options "-O3 -fdump-tree-slp1-details" } */ + +#include "tree-vect.h" + +int a[2][9]; +int b; +int main() +{ + check_vect (); + for (b = 0; b < 2; b++) + for (long e = 8; e > 0; e--) + a[b][e] = a[0][1] == 0; + if (a[1][1] != 0) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "optimized: basic block part vectorized" 2 "slp1" { target vect_int } } } */ diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 0495842b350..f592aeb8028 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -282,6 +282,12 @@ vect_preserves_scalar_order_p (dr_vec_info *dr_info_a, dr_vec_info *dr_info_b) && !STMT_VINFO_GROUPED_ACCESS (stmtinfo_b)) return true; + /* If there is a loop invariant read involved we might vectorize it in + the prologue, breaking scalar oder with respect to the in-loop store. */ + if ((DR_IS_READ (dr_info_a->dr) && integer_zerop (DR_STEP (dr_info_a->dr))) + || (DR_IS_READ (dr_info_b->dr) && integer_zerop (DR_STEP (dr_info_b->dr)))) + return false; + /* STMT_A and STMT_B belong to overlapping groups. All loads are emitted at the position of the first scalar load. Stores in a group are emitted at the position of the last scalar store.