From patchwork Wed Jan 17 19:02:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 84298 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EE0C3858408 for ; Wed, 17 Jan 2024 19:02:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id C1B663858C53 for ; Wed, 17 Jan 2024 19:02:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1B663858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C1B663858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705518133; cv=none; b=WL54v31rwCeKbUkLbk8KM6ikF6egcwc4zIp/JUI+GC1s3pTvYC+oh/nSdOesr7tRtdjmycW4EsN3o+rYWSVcflzMNTjg9PqrrMHxfsziy0h5lSFGRUJE3XWhN8NHrtzriGfWlSQ1/AX/7+rQNsOZeg8PdZtn+H1Ct6zdNMT5z6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705518133; c=relaxed/simple; bh=fc2djwJ3Wb2igG6Et1vRPa8UASsGKj3wCxJpqLML/l4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=uC0Y1frz7e4uhcUKE4Z5O4d/HNCXiQt7JyoizMh3FY1nG+I670Or17eTj1+lndIb53ak8wfORuK/vDf2Saz/owMSL+8fAbFcQuXoTZ76AOVC3xme6l1aicXS+TwwrodgBYh2R/BldRn52sB4n+nFTujg7cbU4xF2T8VHCkY5yF0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6da9c834646so10044395b3a.3 for ; Wed, 17 Jan 2024 11:02:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705518130; x=1706122930; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NfxYP645RBNqQ9XYNS8oSp6y0KP4k3c5zEnoHQ6DCAg=; b=TXc3O5D2JDyv2Bc5I0h+SHfWsZL5qeIIYgEkHxm+ycbeVHArduyVAKx0aDPNNSMTd8 s4dC/YT39pP6WN2/9Zgrs80CjogmwXyYGMP44mNly7Juj5l5WpHVSXq3PmZgdpYF2+lq JHmOcT8d4yO5JSGUtMknJRDKMF9VRV6K3axIvVXtHS4uPlC4cIXGZ2OsaieaAHk6TQIa 71N8kvnuUUTnpvxmcmGGO+Nhqx64GbUPKn8V27ZsCEFdcfKlsDs5JCIxZBx0RChBzCO6 x6rA/iOyUmtEWf61R+ZbzS7JY5yQ22cMEIDNHOure8nrnGcwgky43zGr6uQ8C+YnqjHd nSSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705518130; x=1706122930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NfxYP645RBNqQ9XYNS8oSp6y0KP4k3c5zEnoHQ6DCAg=; b=NxtD9aIAlbD831LvmKJ2jKLzVOM7hk81gEWX8aB5cawjrxz1z70wZsZuFz6Lejf+mr Z5JHGupA95cglLZzBeYZdRPveZ9Pf0E9EwWCTrsrCCYH2d1/fQYOQOaTrp8EGST5vf2z /beDIjO0eJOjxHVWLNI5qBSpQIylWB2htPO760Dj6putSCtCohq9goZKPYkFIZXmPlOX vRGWylv5UBq5t1wJvh1CeGHTdYAg/4YaJXyNsKzLeblSfKs5GyzW+xVHSaRW7MwwBhrr Pfgsepwq2tNmqgBQM+5fetL8oBlVuZJaKgBdNwjAMBUCIpsGQk/KgMbXMH1VaC6Tdh0z 3cbA== X-Gm-Message-State: AOJu0YyGA3uu59QPlELbqP9jD6MD+xstV+Ax39xu4Bl2RNfNiqcYPGoN 89Y130vbuxFT0LHJzl4QOwLEWPFBOIUbfp77NfbjlyKhs2A= X-Google-Smtp-Source: AGHT+IHe47V908XtW+urD/pnPtQrdnX5rW7rFXnqZB3I+VVPxs59z6j3AxDI2XqZJm7mx/VtP2wieQ== X-Received: by 2002:a05:6a20:8c23:b0:197:91d8:3095 with SMTP id j35-20020a056a208c2300b0019791d83095mr8318590pzh.17.1705518129597; Wed, 17 Jan 2024 11:02:09 -0800 (PST) Received: from vineet-framework.ba.rivosinc.com ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id fi35-20020a056a0039a300b006d94291679asm1790868pfb.78.2024.01.17.11.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 11:02:09 -0800 (PST) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [COMITTED 1/2] RISC-V: RVV: add toggle to control vsetvl pass behavior Date: Wed, 17 Jan 2024 11:02:07 -0800 Message-Id: <20240117190207.450120-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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+patchwork=sourceware.org@gcc.gnu.org RVV requires VSET?VL? instructions to dynamically configure VLEN at runtime. There's a custom pass to do that which has a simple mode which generates a VSETVL for each V insn and a lazy/optimal mode which uses LCM dataflow to move VSETVL around, identify/delete the redundant ones. Currently simple mode is default for !optimize invocations while lazy mode being the default. This patch allows simple mode to be forced via a toggle independent of the optimization level. A lot of gcc developers are currently doing this in some form in their local setups, as in the initial phase of autovec development issues are expected. It makes sense to provide this facility upstream. It could potentially also be used by distro builder for any quick workarounds in autovec bugs of future. gcc/ChangeLog: * config/riscv/riscv.opt: New -param=vsetvl-strategy. * config/riscv/riscv-opts.h: New enum vsetvl_strategy_enum. * config/riscv/riscv-vsetvl.cc (pre_vsetvl::pre_global_vsetvl_info): Use vsetvl_strategy. (pass_vsetvl::execute): Use vsetvl_strategy. Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv-opts.h | 9 +++++++++ gcc/config/riscv/riscv-vsetvl.cc | 2 +- gcc/config/riscv/riscv.opt | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index ff4406ab8eaf..ca57dddf1d9a 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -116,6 +116,15 @@ enum stringop_strategy_enum { STRATEGY_AUTO = STRATEGY_SCALAR | STRATEGY_VECTOR }; +/* Behavior of VSETVL Pass. */ +enum vsetvl_strategy_enum { + /* Simple: Insert a vsetvl* instruction for each Vector instruction. */ + VSETVL_SIMPLE = 1, + /* Optimized: Run LCM dataflow analysis to reduce vsetvl* insns and + delete any redundant ones generated in the process. */ + VSETVL_OPT = 2 +}; + #define TARGET_ZICOND_LIKE (TARGET_ZICOND || (TARGET_XVENTANACONDOPS && TARGET_64BIT)) /* Bit of riscv_zvl_flags will set contintuly, N-1 bit will set if N-bit is diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index df7ed149388a..78a2f7b38faf 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -3671,7 +3671,7 @@ pass_vsetvl::execute (function *) if (!has_vector_insn (cfun)) return 0; - if (!optimize) + if (!optimize || vsetvl_strategy & VSETVL_SIMPLE) simple_vsetvl (); else lazy_vsetvl (); diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 44ed6d69da29..fd4f1a4df206 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -546,6 +546,20 @@ Target Undocumented Bool Var(riscv_vector_abi) Init(0) Enable the use of vector registers for function arguments and return value. This is an experimental switch and may be subject to change in the future. +Enum +Name(vsetvl_strategy) Type(enum vsetvl_strategy_enum) +Valid arguments to -param=vsetvl-strategy=: + +EnumValue +Enum(vsetvl_strategy) String(simple) Value(VSETVL_SIMPLE) + +EnumValue +Enum(vsetvl_strategy) String(optim) Value(VSETVL_OPT) + +-param=vsetvl-strategy= +Target Undocumented RejectNegative Joined Enum(vsetvl_strategy) Var(vsetvl_strategy) Init(VSETVL_OPT) +-param=vsetvl-strategy= Set the optimization level of VSETVL insert pass. + Enum Name(stringop_strategy) Type(enum stringop_strategy_enum) Valid arguments to -mstringop-strategy=: From patchwork Wed Jan 17 19:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 84297 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BE643858427 for ; Wed, 17 Jan 2024 19:02:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 77BFB3858C52 for ; Wed, 17 Jan 2024 19:01:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77BFB3858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 77BFB3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705518100; cv=none; b=f2YkDvUd3/70ukZSsXaAYPjF2dMdxE/fHLH2nzLA+0uejLebrwYQ4qWkZEKtiPM1L9Hzrv2wTTlCKLAyDJsVj/Ydo/itotXbnu9WK3iEMRkRMhGRN7kKWrPwPxSM4PDh+bsyn8ek41KWQp6vp/hmQZw0SjoXHenoY524Ly8ohW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705518100; c=relaxed/simple; bh=CkACz2hVcQQyb6GC200Z+R8EgEfe7BwYEX5Q+ktN6Uk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=uNFESCE9DKo9hUhyIdbXINya3B5vSnwOTBgtROPQvXySNz2Ke0z8Fz5oCFCWcSC05Wu8lAdOnggcKbr2Tdr9McCChDkR2SMTSR7NdqcGgIe2UxN+lE9qwnCB6ncv2dMJnkXaPG5M6WsoVOPLHJEz2hd0PDPDAOSLnam1kKgE86c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6d9344f30caso7676938b3a.1 for ; Wed, 17 Jan 2024 11:01:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705518096; x=1706122896; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/KHGCI3KAcdjI/hhQbuv5BwcNuneGTJ9pJQvlFufXR4=; b=Ox4V05RgZKfZX65LUTSZZK3i9niYGc+vQB4eSpowVouiim46UgpJIlZg/QNSj1Rq/b dv9BfKTHR6Zk1SRu4/pS5OgcQl7ESCvTKsCjAguqdOJ1zEnds+GQ7KQxiTOlpBgADfe1 zOEfFCZM5P7F9CAqw364Rv7Bb4XnvyiRyW2mTJUT52NdKIg45HlzFpt1SPnWuEfJjjor DE47fOMCiUSaiXk2ZlB5RJZ7AuUSL9g2JvnDufq3P16etLPZ4jLSihcBiTAEq943Lui+ ydGcG4pM7/IGHcxsgZRVwl1uJmaj4s7Idk4NKSwEl4nqT+2H9rgx9XwMttFYLUEtEF2Z WFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705518096; x=1706122896; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/KHGCI3KAcdjI/hhQbuv5BwcNuneGTJ9pJQvlFufXR4=; b=IaywHPv1cxlBA+jtNe8jWxXoEvAXapaJeINfEAotKU7Bp5W+v7yQasjeV7B3bchnww b/X53GxENwKndTjV1wfqXij36BThQwYIvmWkmTLxozTtPBzyOveCz/X0gck1xVOyR2zT lgvuc8AdB8FDvs3WeYeBd2RPdkX4/2sP/d0kdw8LpUP67IVoMYmtf/yfcGqAfdv+UZ0R AQzRB3vCp4L/XH6DAGtnEuZfH9Y45hFwH7kWE/Vt7SsRvbx/BQi5DhCfHRLBZDq03FSV lnsHKJ1bPbjTd4ZsDMLWqrGgf9Bp52Dui2pDtrobo2j4BHL+cu8ZgpzQEp+hjOK1qcVJ UX/w== X-Gm-Message-State: AOJu0YzSWuTFXnQdIRTPgR9f7LIg2RaEfhZj/qqame8A7cV9Jv52UCIE 0QzjhMpmt0wXfr8CcekL0jl7v+jW5Pflgz1fqSZwVx26L2Fyx5lyA5TFgUHYy3JP1kNflKMVP+w i X-Google-Smtp-Source: AGHT+IFAP2wYpMk0pvc3y8PDsa4L1lQ+if3MbGNch37aOCD7swav0hamYO9GGbnTRMEG/CYcJ8F6Ng== X-Received: by 2002:a05:6a00:1306:b0:6d9:be60:9b93 with SMTP id j6-20020a056a00130600b006d9be609b93mr1818752pfu.12.1705518096087; Wed, 17 Jan 2024 11:01:36 -0800 (PST) Received: from vineet-framework.ba.rivosinc.com ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id z2-20020aa785c2000000b006d99d986624sm1786542pfn.151.2024.01.17.11.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 11:01:35 -0800 (PST) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [COMITTED 2/2] RISC-V: fix some vsetvl debug info in pass's Phase 2 code [NFC] Date: Wed, 17 Jan 2024 11:01:32 -0800 Message-Id: <20240117190132.450071-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <33D9750FAAB8AC40+2024011706320068727626@rivai.ai> References: <33D9750FAAB8AC40+2024011706320068727626@rivai.ai> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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+patchwork=sourceware.org@gcc.gnu.org When staring at VSETVL pass for PR/113429, spotted some minor improvements. 1. For readablity, remove some redundant condition check in Phase 2 function earliest_fuse_vsetvl_info (). 2. Add iteration count in debug prints in same function. gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (earliest_fuse_vsetvl_info): Remove redundant checks in else condition for readablity. (earliest_fuse_vsetvl_info) Print iteration count in debug prints. (earliest_fuse_vsetvl_info) Fix misleading vsetvl info dump details in certain cases. Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv-vsetvl.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 78a2f7b38faf..41d4b80648f6 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -2343,7 +2343,7 @@ public: void compute_lcm_local_properties (); void fuse_local_vsetvl_info (); - bool earliest_fuse_vsetvl_info (); + bool earliest_fuse_vsetvl_info (int iter); void pre_global_vsetvl_info (); void emit_vsetvl (); void cleaup (); @@ -2961,7 +2961,7 @@ pre_vsetvl::fuse_local_vsetvl_info () bool -pre_vsetvl::earliest_fuse_vsetvl_info () +pre_vsetvl::earliest_fuse_vsetvl_info (int iter) { compute_avl_def_data (); compute_vsetvl_def_data (); @@ -2984,7 +2984,8 @@ pre_vsetvl::earliest_fuse_vsetvl_info () if (dump_file && (dump_flags & TDF_DETAILS)) { - fprintf (dump_file, "\n Compute LCM earliest insert data:\n\n"); + fprintf (dump_file, "\n Compute LCM earliest insert data (lift %d):\n\n", + iter); fprintf (dump_file, " Expression List (%u):\n", num_exprs); for (unsigned i = 0; i < num_exprs; i++) { @@ -3032,7 +3033,7 @@ pre_vsetvl::earliest_fuse_vsetvl_info () if (dump_file && (dump_flags & TDF_DETAILS)) { - fprintf (dump_file, " Fused global info result:\n"); + fprintf (dump_file, " Fused global info result (lift %d):\n", iter); } bool changed = false; @@ -3142,8 +3143,7 @@ pre_vsetvl::earliest_fuse_vsetvl_info () if (src_block_info.has_info ()) src_block_info.probability += dest_block_info.probability; } - else if (src_block_info.has_info () - && !m_dem.compatible_p (prev_info, curr_info)) + else { /* Cancel lift up if probabilities are equal. */ if (successors_probability_equal_p (eg->src)) @@ -3151,11 +3151,11 @@ pre_vsetvl::earliest_fuse_vsetvl_info () if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, - " Change empty bb %u to from:", + " Reset bb %u:", eg->src->index); prev_info.dump (dump_file, " "); fprintf (dump_file, - " to (higher probability):"); + " due to (same probability):"); curr_info.dump (dump_file, " "); } src_block_info.set_empty_info (); @@ -3170,7 +3170,7 @@ pre_vsetvl::earliest_fuse_vsetvl_info () if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, - " Change empty bb %u to from:", + " Change bb %u from:", eg->src->index); prev_info.dump (dump_file, " "); fprintf (dump_file, @@ -3627,7 +3627,7 @@ pass_vsetvl::lazy_vsetvl () { if (dump_file) fprintf (dump_file, " Try lift up %d.\n\n", fused_count); - changed = pre.earliest_fuse_vsetvl_info (); + changed = pre.earliest_fuse_vsetvl_info (fused_count); fused_count += 1; } while (changed);