From patchwork Sun Nov 13 21:20:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 19455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1836500wru; Sun, 13 Nov 2022 13:22:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7TJV/SToQ+Cp1BYDAZ9IXts9q2aiIR+UyV+9o8QS5I6BIesYU2u+5on/CXCIbcIC+dENCh X-Received: by 2002:a17:907:9145:b0:78d:9f02:5458 with SMTP id l5-20020a170907914500b0078d9f025458mr8339949ejs.753.1668374536888; Sun, 13 Nov 2022 13:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668374536; cv=none; d=google.com; s=arc-20160816; b=C2U5qPtxrd+x0PsQUZpE4vioM5b9qoTuKC+5+jUy2uBku/IUONffsR4jZWG3sppl5A YJ5vIO7fh2LE+acW2hk+UyH1yCZiYhe1whb3KvrNr2A96jBpadVEEPXuZlXcKxsRvUmD BtEyq8MhPRPYDMApktK1DFQnz5AmxhS+zswY3jfwFRCNu4OEBiKgKw1AhA79y8czhpQB 8TJLmrYCYNffmN72Nh9u+TCB1FbsQ+yXvdHL/HFulY5FnvRJz9PbZxXYS66Oa8uearCW xEAufoAVnM4RzLa7whD0rOPtZbaucKcaLMOoxrAkaDjwXScH9V/irx4gnj8RzcGi5I/x kfug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=i1CiygP7lqZttrGh8t0+Mw1ON8fR+7WJernWguWy5uk=; b=jFKOGnQrOhD4L7b5YfQlYM3y52oj9Gjxo8yegUtweFG1nhbkTjFIHynINeg7gj9qn9 DtivHiRDIBEfZYhv6Zf2/MsNV+hEJ/OvRGovoU65VuKo2PHLG0RNBL5rRf3QgkS4K/JT RnbhYYpW3K/UU63iRNg5w7HaYWXgv6pcggy+zEhJrMOSNw1f/JvI6QwwNUpV5S0C6f0b q5P9o5W/0JMr0IZR9UqwYD9szVqlGQ9xkx4PhDlNmkjdhV6yx4be3SD+ayUmKdDECZt4 +TNXob+fBDDP5+NeLxHXoEITCFzYdbUOGUR9+LU9KOJtBUT5gK8Mh0KIsRzC398mYYf0 GHOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b="UdPN/si7"; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qk11-20020a1709077f8b00b007adeb7f8e5bsi8732751ejc.913.2022.11.13.13.22.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Nov 2022 13:22:16 -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=@vrull.eu header.s=google header.b="UdPN/si7"; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19396389EC63 for ; Sun, 13 Nov 2022 21:21:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 21BD13885535 for ; Sun, 13 Nov 2022 21:20:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21BD13885535 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-lf1-x12c.google.com with SMTP id b3so16358720lfv.2 for ; Sun, 13 Nov 2022 13:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; 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=i1CiygP7lqZttrGh8t0+Mw1ON8fR+7WJernWguWy5uk=; b=UdPN/si7OabzXQqhQZNmHN4QLIW/kuqlkYwazfWJMkC08pkJcMEWhM3z41w/LJSM1I 70Yj3emQ9Va+8NzDduYHzOhIYa2/3yuE4gmCCpdKU4JoR+1wGzWNF+Tfy28eZnorOy9g 7imo2cMH8AlLO8uw5kVzvRwJQn5jvHfPlGDpz4n86/EpCJuVl47qasxfb3s0eqAmCMcH 1WqRgQwgC4JU9bQdBnbStlXdkjiqEjnieRv4zaBNBHR8uec2bXbiTquWKc1ScFDLGNtt i0BnRoV1qt6hdcJ7+1gTEtWwyGjbGpTtpWLNuMz8/hwFKQLXl/J+8aDPMUVMqqT0Mc54 R7Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=i1CiygP7lqZttrGh8t0+Mw1ON8fR+7WJernWguWy5uk=; b=VZve8ANnPIX50sb+Oc/UGrs9O9eWv8ryjto7BY73RZb0cclRCCLvo5Q0LuLC3h8c+n bJOywUDFdVHoTIGOUodjC8Oe3TNtV8Ix9o2t0V2341KN1BdGeZ2pyi2WadRWwgGRB3kv wBqD55WHKCvW3DCDGvxNMT9GSiDxo9PBqxOfs14BnuGG2Ja/lQJtpI01rGZiQX+B9TKh tRDP1njFHqfBeKGaDcilSsATlTHqqJAgvfYffAgF9jX52X6yt7YCIAOWXLxlZg7QXR38 tKV3ztK0O8QMy2IV+A+YaYHYCbV8MPJWcqQ4nx3ddLOD9eTjB56GHp9KZHXLuH+TPzom VLFQ== X-Gm-Message-State: ANoB5plteXDO36ZukvErGX/fViqfZoDNfebuYUNzLAjF1NvCNkqqUO0r bOQOVANO6C/+kP900zXYRKvOClWrOpHZgT+8 X-Received: by 2002:a05:6512:462:b0:4a2:4290:fc20 with SMTP id x2-20020a056512046200b004a24290fc20mr3215787lfd.563.1668374438216; Sun, 13 Nov 2022 13:20:38 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id d5-20020a0565123d0500b004948ddb4e4dsm1529079lfv.301.2022.11.13.13.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Nov 2022 13:20:37 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Jeff Law , Vineet Gupta , Kito Cheng , Christoph Muellner , Palmer Dabbelt , Philipp Tomsich Subject: [PATCH v2 4/8] RISC-V: Recognize sign-extract + and cases for XVentanaCondOps Date: Sun, 13 Nov 2022 22:20:25 +0100 Message-Id: <20221113212030.4078815-5-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221113212030.4078815-1-philipp.tomsich@vrull.eu> References: <20221113212030.4078815-1-philipp.tomsich@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749417498381148206?= X-GMAIL-MSGID: =?utf-8?q?1749417498381148206?= Users might use explicit arithmetic operations to create a mask and then and it, in a sequence like cond = (bits >> SHIFT) & 1; mask = ~(cond - 1); val &= mask; which will present as a single-bit sign-extract. Dependening on what combination of XVentanaCondOps and Zbs are available, this will map to the following sequences: - bexti + vt.maskc, if both Zbs and XVentanaCondOps are present - andi + vt.maskc, if only XVentanaCondOps is available and the sign-extract is operating on bits 10:0 (bit 11 can't be reached, as the immediate is sign-extended) - slli + srli + and, otherwise. gcc/ChangeLog: * config/riscv/xventanacondops.md: Recognize SIGN_EXTRACT of a single-bit followed by AND for XVentanaCondOps. Signed-off-by: Philipp Tomsich --- (no changes since v1) gcc/config/riscv/xventanacondops.md | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gcc/config/riscv/xventanacondops.md b/gcc/config/riscv/xventanacondops.md index f23058b95b2..a4068e53c13 100644 --- a/gcc/config/riscv/xventanacondops.md +++ b/gcc/config/riscv/xventanacondops.md @@ -74,3 +74,48 @@ [(set (match_dup 5) (match_dup 1)) (set (match_dup 0) (and:X (neg:X (ne:X (match_dup 5) (const_int 0))) (match_dup 4)))]) + +;; Users might use explicit arithmetic operations to create a mask and +;; then and it, in a sequence like +;; cond = (bits >> SHIFT) & 1; +;; mask = ~(cond - 1); +;; val &= mask; +;; which will present as a single-bit sign-extract in the combiner. +;; +;; This will give rise to any of the following cases: +;; - with Zbs and XVentanaCondOps: bexti + vt.maskc +;; - with XVentanaCondOps (but w/o Zbs): +;; - andi + vt.maskc, if the mask is representable in the immediate +;; (which requires extra care due to the immediate +;; being sign-extended) +;; - slli + srli + and +;; - otherwise: slli + srli + and + +;; With Zbb, we have bexti for all possible bits... +(define_split + [(set (match_operand:X 0 "register_operand") + (and:X (sign_extract:X (match_operand:X 1 "register_operand") + (const_int 1) + (match_operand 2 "immediate_operand")) + (match_operand:X 3 "register_operand"))) + (clobber (match_operand:X 4 "register_operand"))] + "TARGET_XVENTANACONDOPS && TARGET_ZBS" + [(set (match_dup 4) (zero_extract:X (match_dup 1) (const_int 1) (match_dup 2))) + (set (match_dup 0) (and:X (neg:X (ne:X (match_dup 4) (const_int 0))) + (match_dup 3)))]) + +;; ...whereas RV64I only allows us access to bits 0..10 in a single andi. +(define_split + [(set (match_operand:X 0 "register_operand") + (and:X (sign_extract:X (match_operand:X 1 "register_operand") + (const_int 1) + (match_operand 2 "immediate_operand")) + (match_operand:X 3 "register_operand"))) + (clobber (match_operand:X 4 "register_operand"))] + "TARGET_XVENTANACONDOPS && !TARGET_ZBS && (UINTVAL (operands[2]) < 11)" + [(set (match_dup 4) (and:X (match_dup 1) (match_dup 2))) + (set (match_dup 0) (and:X (neg:X (ne:X (match_dup 4) (const_int 0))) + (match_dup 3)))] +{ + operands[2] = GEN_INT(1 << UINTVAL(operands[2])); +})