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=: