From patchwork Fri Aug 30 10:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manolis Tsamis X-Patchwork-Id: 1978902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=BtLOw/d+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WwFFd24VHz1yfX for ; Fri, 30 Aug 2024 20:46:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D459385B503 for ; Fri, 30 Aug 2024 10:46:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 242973858C50 for ; Fri, 30 Aug 2024 10:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 242973858C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 242973858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725014779; cv=none; b=KOdHxcqWKjXSD9V0rFZSqo4dxf1/UjkxDv3/JkwRqte9388kILNwvdo8SjVXINLyqX8MXCCXUMqoc3DeECjWgXxRTCQWgrCb3gy9c5DMxEH+wZfg/KZAYWC1RBCyNXg/EUGhgPAJ/0Nb7G7t75OxM/JNOV5Tgi0E50RWkUl5IC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725014779; c=relaxed/simple; bh=a+38IltPKwugOOijjOEMD3+EpLP8WsjEzMI0IJM8VmQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=c2xvPtEgsdFu9Kij93MzZQhYbKWGVgL0QqT68ECOGGDLq2HLYAw90Dk8eqGY6nwkxqMf+EpMEgLXYOGHnZ5tCcLZPTpVdAnfo/3Yy/eVNaDXCD30mkT2ZURDgpaXVEm1978jzlXz7O3BREfjXed8BHDVbrVUz4jVF3FmdhELaLc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-53349ee42a9so2280241e87.3 for ; Fri, 30 Aug 2024 03:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1725014775; x=1725619575; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mL51TR1uaFBGYZ7X+v9ZwA/iq6b3kU3oGuzrJ7a3BlE=; b=BtLOw/d+9ldAbLtsijv6DILqZaPTK28LVHVbO8JiyeO2XdNQp7r4KrpFhbnt3FiJjC 4g1k38pMv3KuF1QXL7/9B4NLrC+vS1/Gt0fH7hZ0EAGvOkViem6OqqdM+Z1DlA6HgN/u pGPuhmpD+711ixr/OaNqljHxiKRnATDSFgdo9Qwp/vOFN/VD+VqsOBF99nh0YBXKSJgx AvePDsQec13TNzfyYdTsdwdfvrVMbvKX5LNz0UfEV5DaOOqPwIuXxYXhD9tF5Ej1Rqvg dbuPwfOuIshMcAKtQnjUfiHJNNU1cYnEjKrQvQq83Ufpr4xICB01F2enUPTbyi2UGZpc 1ehA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725014775; x=1725619575; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mL51TR1uaFBGYZ7X+v9ZwA/iq6b3kU3oGuzrJ7a3BlE=; b=Z2pPUXIkZmfXj22+9FOIi/rpE6YYAo6HZcg60NF13MK1ZaE4VSp8PEIxGOouSEoFQs ACMRDdIwj9rAMG9I4ZFAAUhsK9zgzTnZzP9X9UE0+genlx3yaKoJs8bN/Cl+MhRm7j8c /d57yvVJ4V+ozQJbi11sIzMpsipw8eL3v5VzmXm+BzqrLt0kJECl+p8top9f68V6khYn lW56dr6HLusKjfJ2bbQWKOu6LRSlR9XFcEwsPVWHdtqUPD2v3sluyjhZ/qyEIfjIh6z6 PKawBN4ucDaR0sAwsggUsa+H6MF8KVeNvzKjpnnOooIDIVOe3ynp4/lgeiyJ0i4w5uYe DufQ== X-Gm-Message-State: AOJu0YzCCf9+AAEJT4l8KSCyMY8MKkLsQtanwiTFnGIHXD5sgEXwFwyY w2agM0HmRtOWGX2V8uxE+9gB+v1VTuMaPv+Fnek51iky5VjBJ7G3/bfo+/e9v17lbW+yUPanLT4 x X-Google-Smtp-Source: AGHT+IFDcKhEm/5uyFVnEkfccB+03j1MofV3tnzM0SS26oz/LfdVEJBPHaZUSY1rMq28PjVaX//pEw== X-Received: by 2002:a05:6512:b98:b0:52f:2adf:d445 with SMTP id 2adb3069b0e04-53546baacdbmr1311083e87.41.1725014773862; Fri, 30 Aug 2024 03:46:13 -0700 (PDT) Received: from helsinki-03.engr ([2a01:4f9:6b:2a47::2]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5354084d7afsm540152e87.248.2024.08.30.03.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 03:46:13 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Sam James , Richard Biener , Konstantinos Eleftheriou , =?utf-8?q?Chr?= =?utf-8?q?istoph_M=C3=BCllner?= , Philipp Tomsich , Manolis Tsamis Subject: [RFC PATCH] Do not cache SLP trees across SLP instances [PR116352] Date: Fri, 30 Aug 2024 12:46:11 +0200 Message-Id: <20240830104611.131000-1-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 Currently we do SLP CSE after permute optimization using a single map across all SLP instances. These SLP instances can affect many different basic blocks and the cache may replace a statement in one block with one from another block. Because there are no further limitations and the blocks may be visited in an arbitrary order, this may lead to a statement being used in paths that may not be defined. This patch creates one map per SLP instance to address that. PR tree-optimization/116352 gcc/ChangeLog: * tree-vect-slp.cc (vect_optimize_slp): Use one scalar stmts to tree map per SLP instance. gcc/testsuite/ChangeLog: * gcc.dg/pr116352.c: New test. Signed-off-by: Manolis Tsamis --- gcc/testsuite/gcc.dg/pr116352.c | 18 ++++++++++++++++++ gcc/tree-vect-slp.cc | 12 +++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr116352.c diff --git a/gcc/testsuite/gcc.dg/pr116352.c b/gcc/testsuite/gcc.dg/pr116352.c new file mode 100644 index 00000000000..c427eff3c08 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr116352.c @@ -0,0 +1,18 @@ +/* PR tree-optimization/116352 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fchecking" } */ + +int a; +float b, c; +void l(int h, int f, int g, float *e) +{ + for (int m = 0; m < h; m++) + { + float i = 2 * b, j = 2 * c; + if (a) { + e[m*4 + 0] = e[m*4 + 1] = (j - g * 0.5f); + e[m*4 + 2] = e[m*4 + 3] = (i + f * 0.5f); + } else + e[m*4 + 0] = f * 0.5f + g * 0.5f; + } +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index cfdf59ad386..a8836c2fb04 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -6356,13 +6356,15 @@ vect_optimize_slp (vec_info *vinfo) vect_optimize_slp_pass (vinfo).run (); /* Apply CSE again to nodes after permute optimization. */ - scalar_stmts_to_slp_tree_map_t *bst_map - = new scalar_stmts_to_slp_tree_map_t (); - for (auto inst : vinfo->slp_instances) - vect_cse_slp_nodes (bst_map, SLP_INSTANCE_TREE (inst)); + { + scalar_stmts_to_slp_tree_map_t *bst_map + = new scalar_stmts_to_slp_tree_map_t (); - release_scalar_stmts_to_slp_tree_map (bst_map); + vect_cse_slp_nodes (bst_map, SLP_INSTANCE_TREE (inst)); + + release_scalar_stmts_to_slp_tree_map (bst_map); + } } /* Gather loads reachable from the individual SLP graph entries. */