From patchwork Tue Jan 16 21:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 84216 X-Patchwork-Delegate: juzhe.zhong@rivai.ai 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 7789F3857B99 for ; Tue, 16 Jan 2024 21:41:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 2466B3858C52 for ; Tue, 16 Jan 2024 21:41:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2466B3858C52 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 2466B3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705441270; cv=none; b=Gc23l/VO0saMy+g/YmLTAuEbAtRFsJj+Snn68JDlokiSZxJVKBMv0aw3bsLa+mTPWZR9Q/CtGlFgAI9CpiyfeCE6bokwQKc39NO66NpMeTuRrkJcmPRRD2hgTbZ+uS+7Pok8gEz+KjMgBZ1JjAoEe2Eigo0umEsx8QlboHbsnJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705441270; c=relaxed/simple; bh=ZYHgxvbI7DBajQtsjJBYTSompy/v02WpxAJg1i4bZlw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JWWCotyuVPq1RojIos0zJZ4sucszDIkMjEO2/BvceIbgJDLWM2Ljd61WmgPzPFa1d2YcuIdq8IgdfQlR7YjYnQQu84zC2XUedMW3UA0oNxGC1g4+FzlUVSHhoJtCHGjtv/IzXmCrTj6xe0ON+VxPeN4vGjbo3vPP0e0/YcKp19A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6db79e11596so1926326b3a.0 for ; Tue, 16 Jan 2024 13:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705441266; x=1706046066; 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=DQgn8VV8tGM1zQTxxWJF11w21QTwpxKkkX15nYyXggU=; b=QhPyCx/Sjq+hSxwSbFmI4SJTXWbVs2K0xwiyjsdwZxVXseethbSYIl/Gt8HC7xkHyJ 3jsYnkeviHnbFctkF1GrDvF5WpeG4Tk5eeA89OuE1ecb4fwKSZ+QCfKwFHZpNhjudOEL 3LWupOykmZGoey/YorTx9Bwy29cSBVY5WWe1OGW+RWWTy7PAWhxCBhmTm8oPH2CMhCDJ qEedMpBxOtcjTvMRNa6D2V8OChsxsOfzDaoIxKYP93IEqjKzhBC6E5cWpny7wqejM4/T rrr4Wu1qpzkkV6K+yXuhOzUvDpME3GwCmRXUwKNqI/jqn+r1BDX6N789tow0l/V8s9OX l0/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705441266; x=1706046066; 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=DQgn8VV8tGM1zQTxxWJF11w21QTwpxKkkX15nYyXggU=; b=C6VSGq/7nUbiUOQWkWIPadS7/UvlQAIJ33XdkNP7ht0wIEFFVTDz8DPfVAR2aPEQni bGKz+fVZMsWUEasz3viI2tKDlwCBJAw/uxBMlqg148Z7bYKtgfqyBiXpeST39Co/LdPQ booEpIfVt2/hR0g564yk3PXxkWrKItLd3uxrExdD/fs4bIatwm+uH1G3/zsT0N/bxTf1 hFgR2k0DfU5+cxvzyaR64uP/tsU/PblmV2cBgIobX6IPkE1q+/J/Mv3EYfTED31hkg+g CySLnpNgtWa02m3rN85klqsDIWvA3huH4UIcRlUcCqfq4+lxiipKNRht9uBoyXqvY4jd ByEw== X-Gm-Message-State: AOJu0Yw4AVm47Bj78M/Tu4baw4z8VuxMkoh43KVlVndwF/ErEce1kBs6 XloQE4jvflLLn9g9ZVyq/08cplnM+NdMsyz7FwTwGJaSVZQ= X-Google-Smtp-Source: AGHT+IF7EaxqJaDsXF2E288GPlvweD0m1ca/Zv+rKZQliBkV54bH28CWagG+L8WXJj7zCJ+MZkp25g== X-Received: by 2002:a05:6a00:939d:b0:6db:f61:6a41 with SMTP id ka29-20020a056a00939d00b006db0f616a41mr9522165pfb.22.1705441265833; Tue, 16 Jan 2024 13:41:05 -0800 (PST) Received: from vineet-framework.hq.rivosinc.com ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id s6-20020a056a00178600b006d9879ba6besm49436pfg.170.2024.01.16.13.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 13:41:05 -0800 (PST) From: Vineet Gupta To: gcc-patches@gcc.gnu.org, Robin Dapp , "juzhe . zhong @ rivai . ai" Cc: Jeff Law , kito.cheng@gmail.com, gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [PATCH v2] RISC-V: RVV: add toggle to control vsetvl pass behavior Date: Tue, 16 Jan 2024 13:41:03 -0800 Message-Id: <20240116214103.22931-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 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 Signed-off-by: Vineet Gupta --- Changes since v1: - Dropped OPTIM_NO_DEL --- 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=: