From patchwork Sat Feb 24 10:05:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 205803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1073909dyb; Sat, 24 Feb 2024 02:06:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVj7IFENROrp9CHo+EaKpEK4G+nVnKmMTpq4SxVXs6a20JV2mWmen8sWmDGxd9Q3/X+kmp4wqCPEk02YfSmWW4Y8W7sQg== X-Google-Smtp-Source: AGHT+IFtyl55tJWLRSRvvwm1XsOmQ4TgfFLOxnSwgZQFduBhObK6RLTxyFe7UTWq+FQpMPpOoRGN X-Received: by 2002:a05:6214:5292:b0:68f:3df6:cd6f with SMTP id kj18-20020a056214529200b0068f3df6cd6fmr2346996qvb.23.1708769212904; Sat, 24 Feb 2024 02:06:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708769212; cv=pass; d=google.com; s=arc-20160816; b=G0kAxg7oSbyjLhJkqWgoJ9oSB5NCBqR1GbLmwLtaRPQCQpVQzWoJPG+s1m8fmQ6UPI u1Vr8wdLOUVsKtfAPbRPN7+5dbT13BAOM+Wr1HDoyEf7+MfDOM4LAhFTwbRje6RkCeMP GX0feK+rJTYmsa5p1OzrpPnneeiHadsDBQDglqu5JGX63Msn4sJ+yQzbC1Q0/K4Lri15 c25l7K2vzKaHucjHcPlvhx28PB+FyXil5b4fWSCMLXZ2PSGhM7oWrBJbsvUIcl0uPkPa PYByJ6ISc90huvyTp/qnks8OiI8kEDup75wd61D4BNslJ2P8L91puWLfAM0xPTPVjuRg 6z0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:subject:cc:mail-followup-to:to:from:arc-filter :dmarc-filter:delivered-to; bh=0I6UEN4t1AQYhw1E6jC6t+5vih3iGlkrXc7ZbXHVWMw=; fh=X+xkd0okx06TFUPE5Yq1cGjYlcsgcg5NFV0UKbobafs=; b=HmSY91Piwl++YC/VoluIYMBi6/L73HLCPofFhASoFpBJEmbrZfrgA5CWQsKeOukidp qUmhAQq+Ks8XCN/lpamZdDFelJ9gvsiByoHSk92eIjbUXoWJZ/IRINM9g3bUiH/sJ7n0 ze10n8kTIPiyVxM8cxTo8RmUL6a3nu2aSDlaTNVtZFKCs0oZ4L/Y0+uh547iL5MJr46/ vp2A4m7THl0aRpJjE06+zqACPqLpRzUUVyOUe3DL1OEr/tkSbp8G2LIsjlBCkNTZASAS jMWZpXEAzbP1xZg6vu4l+6mKZ+4uUzxPOIrVpc4t8IL1Y1VHPbLZ98YQEVExBssjcLsQ vnTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t12-20020a05621421ac00b0068c8b401467si726401qvc.597.2024.02.24.02.06.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 02:06:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9640B385828C for ; Sat, 24 Feb 2024 10:06:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 43738385841A for ; Sat, 24 Feb 2024 10:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43738385841A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 43738385841A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708769166; cv=none; b=V4owANaX1FFrDjUa6uIZm/6B6t0zTAkqBEGAJenEsE7nJTj1PVX5HVVp2f6QnpXkOSHQ7bTqE7x3SKrmWJ71cmeV5uTHYhXX3AivfF6UFGrfP4SR5M9sRGzoLfv1PTAgCO2UtbHII6OVGs6iR2LmYWZ0uHgd2x+k/Id5667TgQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708769166; c=relaxed/simple; bh=39QnbVqlrzSu7Hz8eVaOu+WqQw+xn/QtLp8zzmtpZOQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GYemSX95K5rZWgsSFUsPjSvu60iQo5LLOtK0Jwwn2GbV1RXJ+vHIb+MoyVW3kRCl8MrxDa2j+l0eLqOWf3FXGsKTVTTAieVsEfcvGlUyG7w+sBhlzjm8sRQyQ8eIXf2x5jdiHZgUIkwWkhLmd9HzrAWinEnLVSC83ISLp6rjZec= ARC-Authentication-Results: i=1; server2.sourceware.org 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 8198A1063; Sat, 24 Feb 2024 02:06:34 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0874D3F766; Sat, 24 Feb 2024 02:05:54 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rguenther@suse.de, richard.sandiford@arm.com Cc: rguenther@suse.de Subject: [PATCH] vect: Tighten check for impossible SLP layouts [PR113205] Date: Sat, 24 Feb 2024 10:05:53 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-20.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791774385920967560 X-GMAIL-MSGID: 1791774385920967560 During its forward pass, the SLP layout code tries to calculate the cost of a layout change on an incoming edge. This is taken as the minimum of two costs: one in which the source partition keeps its current layout (chosen earlier during the pass) and one in which the source partition switches to the new layout. The latter can sometimes be arranged by the backward pass. If only one of the costs is valid, the other cost was ignored. But the PR shows that this is not safe. If the source partition has layout 0 (the normal layout), we have to be prepared to handle the case in which that ends up being the only valid layout. Other code already accounts for this restriction, e.g. see the code starting with: /* Reject the layout if it would make layout 0 impossible for later partitions. This amounts to testing that the target supports reversing the layout change on edges to later partitions. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ PR tree-optimization/113205 * tree-vect-slp.cc (vect_optimize_slp_pass::forward_cost): Reject the proposed layout if it does not allow a source partition with layout 2 to keep that layout. gcc/testsuite/ PR tree-optimization/113205 * gcc.dg/torture/pr113205.c: New test. --- gcc/testsuite/gcc.dg/torture/pr113205.c | 19 +++++++++++++++++++ gcc/tree-vect-slp.cc | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr113205.c diff --git a/gcc/testsuite/gcc.dg/torture/pr113205.c b/gcc/testsuite/gcc.dg/torture/pr113205.c new file mode 100644 index 00000000000..edfba7fcd0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr113205.c @@ -0,0 +1,19 @@ +char a; +char *b, *c; +int d, e, f, g, h; +int *i; + +void +foo (void) +{ + unsigned p; + d = i[0]; + e = i[1]; + f = i[2]; + g = i[3]; + p = d * b[0]; + p += f * c[h]; + p += e * b[h]; + p += g * c[h]; + a = (p + 8000) >> (__SIZEOF_INT__ * __CHAR_BIT__ / 2); +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 7cf9504398c..895f4f7fb6b 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -5034,6 +5034,10 @@ vect_optimize_slp_pass::forward_cost (graph_edge *ud, unsigned int from_node_i, cost.split (from_partition.out_degree); cost.add_serial_cost (edge_cost); } + else if (from_partition.layout == 0) + /* We must allow the source partition to have layout 0 as a fallback, + in case all other options turn out to be impossible. */ + return cost; /* Take the minimum of that cost and the cost that applies if FROM_PARTITION instead switches to TO_LAYOUT_I. */