From patchwork Tue Feb 13 13:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 200428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp542993dyb; Tue, 13 Feb 2024 05:43:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsonsCuKOR2Kvtsr5lQp5VWbZxIl9IzIc8FDsQMPYc8Fc9Dx7XaA+SpzLTST8ilIZtYdzzouXXXqpMcmwXbunVb59gEw== X-Google-Smtp-Source: AGHT+IHogCVDsMfENmh55mpGccfjKLQqHrFR3KP1esfXEn7+iVQdY3IzoktveUyI917ieXXCK14y X-Received: by 2002:a05:6214:410e:b0:68c:5a4d:35ac with SMTP id kc14-20020a056214410e00b0068c5a4d35acmr12480913qvb.1.1707831816266; Tue, 13 Feb 2024 05:43:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707831816; cv=pass; d=google.com; s=arc-20160816; b=Srm/9hqiE/FAz2nrkequ1qvJPfhbNjvRKq6WG3P0HctmqzyXzVhtw1lqhCM9YjpWzB 9gj7PWnli2Hsi0jtgbnYPxWPRO3M8uOB6HkfDMfmsBxL/7IWv93lSN43TtMrvKkdeVgt Ve2ncdG+myWARZl5X8KLXxbxMxhVeISEubge1+ZaA3zy94bCKNzg+o15dKmrgyC7wg3q 1vvu4Ef3VarsdARhDdCwdsf3Icm1T56HYmAgkdLtIsii7cxmj2O0n+kf70kXeQowVBKS xUVmqgDVNO/9PRNp7iOdUwZb5S50VzdxygXtyN4IFX+wH343lyMyhNahHD8FGTYcEdW5 UgKg== 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:content-transfer-encoding :subject:from:to:content-language:cc:user-agent:mime-version:date :message-id:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=qfP9hvqpebZo12QTTVy24/pUoYUNzPjOtG0OnFFlDz0=; fh=Rv4mS9P3TiJUt2bxAn0GrRmwKSkbj6IOKZEb8KK2lAo=; b=slQOa65Q1X6TQN2DKfbuuGJdYGyCNsLA4nD2ScvI+gaza4niTCg8RSSNAIEAqi5pXT ES69U80eT/UwHDNdsZvQdJA/xWxTc/Ei8HS8vmiHgTRVUE4oXH9X6rHj3mNGnCtSSsTy NgRGtT33TqZ1CueIMk88Yo4Li7l/5uHrDwUAtK7gcOncdt7ww1zOix60aws0rd4xK/GF 2QPXn14B5kDr2sE20AWJ3T9kCLhSexP0nHHI8Mj8ZhQnAwN/zuhlX3HWMnxdixvOUiVV csKOQF2RnLzV5qNbd5x489aN7g/A/bHkokMb9o3Qe52ZqAjwPDl6Y7RMQwb9N7DgeMcE 777g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AXeedWxX; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCVWxqo7zP/NI4rHxoXVClQ7ouNyi5LrViijSAqpGtTWPu14sujn+dxk14ONC4p4ZLZFxtNQ5KjmI8cMpBrCB2gxfU73PQ== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 14-20020a05621420ce00b0068cc2604333si2918450qve.314.2024.02.13.05.43.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 05:43:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AXeedWxX; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9BB03858401 for ; Tue, 13 Feb 2024 13:43:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 14CCC3858C52 for ; Tue, 13 Feb 2024 13:42:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14CCC3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14CCC3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707831777; cv=none; b=AytBnWbwBKJyMclnq3uPH0s1s8tORsSXXqAecvqppyQuE8KAXrWyx40+bRnV4Uj2AUnIJMbbtw+swlcBCTlk0Unxxr87M1tgP4p/Oq18vX8qOo51FBTCfl3Kt3C9MSWnkpAHsgRAKe1nX/p5srGVGUZzr3pb+u+hv6ivqM71mIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707831777; c=relaxed/simple; bh=SD2yxIW+JwgGOy+qWS3mj2s0k/nIjFgKXCrilZ8bvu0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=UjQaDXRtksjQ+TKOxv/pFsj+yi/lpQY2GFSxD9tyP3gObCn7d+I8xllFpugRaYllpdBYXZxfRh7Qlh8OL2KApEq8TQ3bbESO6s9od8a4YdlmEBQAQBctTea+NK5L0AHTEzSh/NMRIMWK3AmnWyDx2xFR4gmGkfkq66zLmfBxqcw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5116bf4dcf4so5224696e87.0 for ; Tue, 13 Feb 2024 05:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707831772; x=1708436572; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=qfP9hvqpebZo12QTTVy24/pUoYUNzPjOtG0OnFFlDz0=; b=AXeedWxXr5W4kJdoaQCEWEi5/AkNaL/3TmS9u4MBFORRNy/YY46K0/pbwbQ4zNgRel elw3JBcR7/UnciC2kmR4ZaaLqoodpHIl/kOXV0B9k9rtOZMnJ3yaWm6vQBrfRLOQWQdD 6v6NHwJmvU3WEEsUZTf2BwYBG4Fgv/IfCRPxM2P3SDSdT5FQIIDING5SKv2mL/lF6Pza 2fjOK87u+A+udoWSe/sbt1+CqvLTXHJU9oAmKVdx3afoafi3t6GJsy5dzmvJV4KkhLmQ 9mjEhjbwhPiQmXZ1uPHwmar1ZPjLBbZw8Rc+f75u9NY2jvoim9X6etLDDPUmgqQE2W5s mndQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707831772; x=1708436572; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=qfP9hvqpebZo12QTTVy24/pUoYUNzPjOtG0OnFFlDz0=; b=QuvVB0qtU+sOgIKg0IHRkTVNnU/MoH/vLzRhVLrj6KK8tdtR+TRy1xPJMZKTqL3eCA NUCZR9h2+MY6DgsJKJjnZMnrzSBY7CFiqBHj9HU7nktjd/7ZdsuhCvk9YTMNDzGIRby7 oOmhg+Q7XkQ3hOQkts4M1RKBgYAB33FkOzMPhgtSsSRlNiad85Crk0AUPqmyf6LGK5Af N2x0sNFxVI0mr29Zp78aLCu2EmkXDQ/Psi9xs+zvw3gEhdU69zbwKZrdSvPKxfPhDbN9 Jsb5clQAxAHhAflB+umaDjcOTT9YDtVqfU7JUL+l/yS4eCohPMxJHUkuJFnVKp91NGTk VvDg== X-Gm-Message-State: AOJu0Yy4aUBQVV3Nl3C3dfk1z1cs6ovJWM7wZRLGXp6/xUeopmiyUECw bhuhC6Eou6VoAyW1dmzqAK8bM7ucxZ0xmoqOpmfgv0/U1mHeXshVh+2seWbL X-Received: by 2002:a05:6512:51c:b0:511:54f2:df07 with SMTP id o28-20020a056512051c00b0051154f2df07mr5992740lfb.11.1707831772127; Tue, 13 Feb 2024 05:42:52 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWElV55dVxlTAF4zW0xa1Ho9aZvaeKl4DV5dSUbdsYiDEJOwuzw8UcJfrhSSoDH23JRaiydjwUCrc4k4up+eiKMEELT46S1TFaInPAkwckDurfiC29vZiuIfzwySNc1UWRQBfkRN27wDRMugZpV87Lub0wE86Jbj/LDKSPdNdolPC27rciC Received: from [192.168.1.23] (ip-149-172-150-237.um42.pools.vodafone-ip.de. [149.172.150.237]) by smtp.gmail.com with ESMTPSA id w11-20020a170906130b00b00a389d911606sm1305159ejb.88.2024.02.13.05.42.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Feb 2024 05:42:51 -0800 (PST) Message-ID: Date: Tue, 13 Feb 2024 14:42:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com Content-Language: en-US To: gcc-patches , palmer , Kito Cheng , jeffreyalaw , "juzhe.zhong@rivai.ai" From: Robin Dapp Subject: [PATCH] RISC-V: Adjust vec unit-stride load/store costs. X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790791454647194407 X-GMAIL-MSGID: 1790791454647194407 Hi, scalar loads provide offset addressing while unit-stride vector instructions cannot. The offset must be loaded into a general-purpose register before it can be used. In order to account for this, this patch adds an address arithmetic heuristic that keeps track of data reference operands. If we haven't seen the operand before we add the cost of a scalar statement. This helps to get rid of an lbm regression when vectorizing (roughly 0.5% fewer dynamic instructions). gcc5 improves by 0.2% and deepsjeng by 0.25%. wrf and nab degrade by 0.1%. This is because before we now adjust the cost of SLP as well as loop-vectorized instructions whereas we would only adjust loop-vectorized instructions before. Considering higher scalar_to_vec costs (3 vs 1) for all vectorization types causes some snippets not to get vectorized anymore. Given these costs the decisions look correct but appear worse when just counting dynamic instructions. In total SPECint 2017 has 4 bn dynamic instructions less and SPECfp 0.7 bn less so not a whole lot. Regtested on riscv64. Regards Robin gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc (adjust_stmt_cost): Move... (costs::adjust_stmt_cost): ... to here and add vec_load/vec_store offset handling. (costs::add_stmt_cost): Also adjust cost for statements without stmt_info. * config/riscv/riscv-vector-costs.h: Define zero constant. gcc/testsuite/ChangeLog: * gcc.dg/vect/costmodel/riscv/rvv/vse-slp-1.c: New test. * gcc.dg/vect/costmodel/riscv/rvv/vse-slp-2.c: New test. --- gcc/config/riscv/riscv-vector-costs.cc | 86 ++++++++++++++++--- gcc/config/riscv/riscv-vector-costs.h | 10 +++ .../vect/costmodel/riscv/rvv/vse-slp-1.c | 51 +++++++++++ .../vect/costmodel/riscv/rvv/vse-slp-2.c | 53 ++++++++++++ 4 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-1.c create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-2.c diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index 7c9840df4e9..adf9c197df5 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see #include "backend.h" #include "tree-data-ref.h" #include "tree-ssa-loop-niter.h" +#include "tree-hash-traits.h" /* This file should be included last. */ #include "riscv-vector-costs.h" @@ -1047,18 +1048,81 @@ costs::better_main_loop_than_p (const vector_costs *uncast_other) const top of riscv_builtin_vectorization_cost handling which doesn't have any information on statement operation codes etc. */ -static unsigned -adjust_stmt_cost (enum vect_cost_for_stmt kind, tree vectype, int stmt_cost) +unsigned +costs::adjust_stmt_cost (enum vect_cost_for_stmt kind, loop_vec_info loop, + stmt_vec_info stmt_info, + slp_tree, tree vectype, int stmt_cost) { const cpu_vector_cost *costs = get_vector_costs (); switch (kind) { case scalar_to_vec: - return stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->FR2VR - : costs->regmove->GR2VR); + stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->FR2VR + : costs->regmove->GR2VR); + break; case vec_to_scalar: - return stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->VR2FR - : costs->regmove->VR2GR); + stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->VR2FR + : costs->regmove->VR2GR); + break; + case vector_load: + case vector_store: + { + /* Unit-stride vector loads and stores do not have offset addressing + as opposed to scalar loads and stores. + If the address depends on a variable we need an additional + add/sub for each load/store in the worst case. */ + if (stmt_info && stmt_info->stmt) + { + data_reference *dr = STMT_VINFO_DATA_REF (stmt_info); + class loop *father = stmt_info->stmt->bb->loop_father; + if (!loop && father && !father->inner && father->superloops) + { + tree ref; + if (TREE_CODE (dr->ref) != MEM_REF + || !(ref = TREE_OPERAND (dr->ref, 0)) + || TREE_CODE (ref) != SSA_NAME) + break; + + if (SSA_NAME_IS_DEFAULT_DEF (ref)) + break; + + if (memrefs.contains ({ref, cst0})) + break; + + memrefs.add ({ref, cst0}); + + /* In case we have not seen REF before and the base address + is a pointer operation try a bit harder. */ + tree base = DR_BASE_ADDRESS (dr); + if (TREE_CODE (base) == POINTER_PLUS_EXPR + || TREE_CODE (base) == POINTER_DIFF_EXPR) + { + /* Deconstruct BASE's first operand. If it is a binary + operation, i.e. a base and an "offset" store this + pair. Only increase the stmt_cost if we haven't seen + it before. */ + tree argp = TREE_OPERAND (base, 1); + typedef std::pair addr_pair; + addr_pair pair; + if (TREE_CODE_CLASS (TREE_CODE (argp)) == tcc_binary) + { + tree argp0 = tree_strip_nop_conversions + (TREE_OPERAND (argp, 0)); + tree argp1 = TREE_OPERAND (argp, 1); + pair = addr_pair (argp0, argp1); + if (memrefs.contains (pair)) + break; + + memrefs.add (pair); + stmt_cost += builtin_vectorization_cost (scalar_stmt, + NULL_TREE, 0); + } + } + } + } + break; + } + default: break; } @@ -1067,7 +1131,7 @@ adjust_stmt_cost (enum vect_cost_for_stmt kind, tree vectype, int stmt_cost) unsigned costs::add_stmt_cost (int count, vect_cost_for_stmt kind, - stmt_vec_info stmt_info, slp_tree, tree vectype, + stmt_vec_info stmt_info, slp_tree node, tree vectype, int misalign, vect_cost_model_location where) { int stmt_cost @@ -1080,6 +1144,7 @@ costs::add_stmt_cost (int count, vect_cost_for_stmt kind, if (loop_vinfo) analyze_loop_vinfo (loop_vinfo); + memrefs.empty (); m_analyzed_vinfo = true; } @@ -1092,11 +1157,12 @@ costs::add_stmt_cost (int count, vect_cost_for_stmt kind, as one iteration of the VLA loop. */ if (where == vect_body && m_unrolled_vls_niters) m_unrolled_vls_stmts += count * m_unrolled_vls_niters; - - if (vectype) - stmt_cost = adjust_stmt_cost (kind, vectype, stmt_cost); } + if (vectype) + stmt_cost = adjust_stmt_cost (kind, loop_vinfo, stmt_info, node, vectype, + stmt_cost); + return record_stmt_cost (stmt_info, where, count * stmt_cost); } diff --git a/gcc/config/riscv/riscv-vector-costs.h b/gcc/config/riscv/riscv-vector-costs.h index 4e2bbfd5ca9..ca0ef1199b2 100644 --- a/gcc/config/riscv/riscv-vector-costs.h +++ b/gcc/config/riscv/riscv-vector-costs.h @@ -85,6 +85,12 @@ private: unsigned HOST_WIDE_INT m_unrolled_vls_niters = 0; unsigned HOST_WIDE_INT m_unrolled_vls_stmts = 0; + tree cst0 = build_int_cst (integer_type_node, 0); + + /* Store the memory references already processed. */ + typedef pair_hash tree_pair_hash; + hash_set memrefs; + void analyze_loop_vinfo (loop_vec_info); void record_potential_vls_unrolling (loop_vec_info); bool prefer_unrolled_loop () const; @@ -98,6 +104,10 @@ private: void record_potential_unexpected_spills (loop_vec_info); void adjust_vect_cost_per_loop (loop_vec_info); + unsigned adjust_stmt_cost (enum vect_cost_for_stmt kind, + loop_vec_info, + stmt_vec_info stmt_info, slp_tree, + tree vectype, int stmt_cost); }; } // namespace riscv_vector diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-1.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-1.c new file mode 100644 index 00000000000..d1c6b35015f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-1.c @@ -0,0 +1,51 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -O3 -fdump-tree-slp1-details" } */ + +#define f1 (1.0 / 3.0) +#define f2 (1.0 / 18.0) +#define f3 (1.0 / 36.0) + +#define SIZE_X 10 +#define SIZE_Y 10 +#define SIZE_Z 10 + +typedef enum {C = 0, + N, S, E, W, T, B, + NE, NW, SE, SW, + NT, NB, ST, SB, + ET, EB, WT, WB, + FLAGS, N_CELL_ENTRIES} CELL_ENTRIES; + +#define CALC_INDEX(x,y,z,e) ((e)+N_CELL_ENTRIES*((x)+ \ + (y)*SIZE_X+(z)*SIZE_X*SIZE_Y)) +#define GRID_ENTRY_SWEEP(g,dx,dy,dz,e) ((g)[CALC_INDEX(dx, dy, dz, e)+(i)]) +#define LOCAL(g,e) (GRID_ENTRY_SWEEP (g, 0, 0, 0, e)) + +void foo (double *grid) +{ + for( int i = CALC_INDEX(0, 0, -2, 0); \ + i < CALC_INDEX(0, 0, SIZE_Z + 2, 0); \ + i += N_CELL_ENTRIES ) { + LOCAL (grid, C ) = f1; + LOCAL (grid, N ) = f2; + LOCAL (grid, S ) = f2; + LOCAL (grid, E ) = f2; + LOCAL (grid, W ) = f2; + LOCAL (grid, T ) = f2; + LOCAL (grid, B ) = f2; + LOCAL (grid, NE) = f3; + LOCAL (grid, NW) = f3; + LOCAL (grid, SE) = f3; + LOCAL (grid, SW) = f3; + LOCAL (grid, NT) = f3; + LOCAL (grid, NB) = f3; + LOCAL (grid, ST) = f3; + LOCAL (grid, SB) = f3; + LOCAL (grid, ET) = f3; + LOCAL (grid, EB) = f3; + LOCAL (grid, WT) = f3; + LOCAL (grid, WB) = f3; + } +} + +/* { dg-final { scan-tree-dump-times "vectorized using SLP" 0 "slp1" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-2.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-2.c new file mode 100644 index 00000000000..278fada485c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/vse-slp-2.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -O3 -fdump-tree-slp1-details" } */ + +#include + +#define f1 3 +#define f2 4 +#define f3 5 + +#define SIZE_X 10 +#define SIZE_Y 10 +#define SIZE_Z 10 + +typedef enum {C = 0, + N, S, E, W, T, B, + NE, NW, SE, SW, + NT, NB, ST, SB, + ET, EB, WT, WB, + FLAGS, N_CELL_ENTRIES} CELL_ENTRIES; + +#define CALC_INDEX(x,y,z,e) ((e)+N_CELL_ENTRIES*((x)+ \ + (y)*SIZE_X+(z)*SIZE_X*SIZE_Y)) +#define GRID_ENTRY_SWEEP(g,dx,dy,dz,e) ((g)[CALC_INDEX(dx, dy, dz, e)+(i)]) +#define LOCAL(g,e) (GRID_ENTRY_SWEEP (g, 0, 0, 0, e)) + +void foo (uint64_t *grid) +{ + for( int i = CALC_INDEX(0, 0, -2, 0); \ + i < CALC_INDEX(0, 0, SIZE_Z + 2, 0); \ + i += N_CELL_ENTRIES ) { + LOCAL (grid, C ) = f1; + LOCAL (grid, N ) = f2; + LOCAL (grid, S ) = f2; + LOCAL (grid, E ) = f2; + LOCAL (grid, W ) = f2; + LOCAL (grid, T ) = f2; + LOCAL (grid, B ) = f2; + LOCAL (grid, NE) = f3; + LOCAL (grid, NW) = f3; + LOCAL (grid, SE) = f3; + LOCAL (grid, SW) = f3; + LOCAL (grid, NT) = f3; + LOCAL (grid, NB) = f3; + LOCAL (grid, ST) = f3; + LOCAL (grid, SB) = f3; + LOCAL (grid, ET) = f3; + LOCAL (grid, EB) = f3; + LOCAL (grid, WT) = f3; + LOCAL (grid, WB) = f3; + } +} + +/* { dg-final { scan-tree-dump-times "vectorized using SLP" 0 "slp1" } } */