From patchwork Sat Nov 12 21:29:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 19262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1434949wru; Sat, 12 Nov 2022 13:32:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf6XU9HoulkrAbmgHMtjjqjLLEkXj9H7Wmsywm8N+xaV8Lcma+5vomvuK06BlWrUoy6uQvCY X-Received: by 2002:a05:6402:457:b0:462:750b:bced with SMTP id p23-20020a056402045700b00462750bbcedmr6170875edw.313.1668288771022; Sat, 12 Nov 2022 13:32:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668288771; cv=none; d=google.com; s=arc-20160816; b=JZI4hUQl3DqvB20LssMRtmmxQqRgGIhTCkXVKOi6kTRmJov/osiw15Om73By0QGXAz urgk8yXxVCD/cBmUvYRqUN3zyML0vYOWuPjaPHkTAly6jgnoYEKnO1veqnQLDUeTHwP0 +N0sgPjtmxxx9MkNvmQkPNsQ9E7NKgXlzkfi0os7pgQxS/owi52vy/z8tNsSjd0D/WVg iNSAipLnIVIVrmmpXLsc/+b57izOEFJ+SV6xxChlXv0YksxRBArkurLooYwoBoBWxSQe vpUoWVY41753OZgOaBEPDExfQK8tjt0M5sDyQhL+5wRpzqMAUd2LG/1wmVJUzPsoWr+f DT6g== 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=av3HGlKmOdZJOiz5VlCudPOVhItgnhX1h3QcFeonyS8=; b=XUfIOaiH3VJafD7R1YAdteO+xorvwI9RI+0ICao24MxapqH/vNulsIDZ5c3gxKJHrZ hMxfpg75BnGLClLX9595XSZvitNgVacfg6k4VIKdm+EZLlZ6Ok/G9Zoi1NXmG3lh8clX AeE5wa8U/dvub96/wUzjJMqR8ob3D65Dy7Un2rbwKxHXn8q3MW7rFBeHMZ17Zjw14HdW q92M367ppPBLU6oHxM8jK32kJ9uJXSjWJeDqnzAe6JDDs4T3uW3bXDY9HYueE7iUv84K qkXWPUNjPPwTCrH1lQHGA+n1ScSJCAZa05RnRIp5x2tWbz9jv9ERKTIEhlIGO+97Yh9F mo0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=fSiWUQky; 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 m15-20020a50998f000000b0046311e80ebcsi5274591edb.151.2022.11.12.13.32.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 13:32:51 -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=fSiWUQky; 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 770243895FF4 for ; Sat, 12 Nov 2022 21:30:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 4A7EB38418AB for ; Sat, 12 Nov 2022 21:29:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A7EB38418AB 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-x132.google.com with SMTP id p8so13372065lfu.11 for ; Sat, 12 Nov 2022 13:29:54 -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=av3HGlKmOdZJOiz5VlCudPOVhItgnhX1h3QcFeonyS8=; b=fSiWUQkysYr7KLewlD0getM9FgYNKwlK1Jk8TyTrQ8fof0nHbeV3+T08SsfkS780bW NVrxoj2aQa48WlcdcsJgWcdg26FrhOk1gkN6cbn8BsZEmaCRDknG7qUpWzWvdfvjEHV0 +4pdtg1dzUFB9WAeaohTkmKhkLnKEk5s0uqV6Sywg9mwff2lx1bC14QsdFEoVosSgsyp 5w7dB0JFmzJm/USaZc+J0eROuV8y2D3r1SnFITBtLDsW2pC5lh/kqhg4tlC8f81uJ9EQ B8uF7XowQczx/EFW2oRd9iwBWYg/HPBDr6ewucTtnjL1jPUHlKIc6HeZaYCcschfA9QO tAaA== 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=av3HGlKmOdZJOiz5VlCudPOVhItgnhX1h3QcFeonyS8=; b=N8gIZNgb8ja4o4Nfa27XEJ+I7esv2AMLZJshZE/yIXNV47sL7CaWlxMtt2lo5Xcr0O uEtO9RYxRFvqSJC7W6L1qVEj052pGnElqnoRbYSgfnQqmJFo1axPH01Ec6gubkHdC/WR trW7yoIWCsI/x8MQtlnqshlQhNgHE4nvGg73xhvIODh81/4tV5Jt49X598E5BBranIDr ixTtd/SAxbncRaHJa1AZIaHccRlgY6/n05sHODD+bY8eb03M8OJwff7BUXxLui/5Gk6j /HkdqP68DZ9MeYeVmHSRHPgudmiiQ6EkKNX5a+hE+O9NBPkiRBzHYd9z6mydcI1AARqk 3Lgw== X-Gm-Message-State: ANoB5pkZ36IKWf+YdVqSxi6CplzlPHTTIhObEjcpm6hGI7wAiRJ0clP6 78Dg6rZGZ06bUy/3rTfW26BwhpHU3K9FjLm7 X-Received: by 2002:a05:6512:34c1:b0:4b1:5a96:983f with SMTP id w1-20020a05651234c100b004b15a96983fmr2750222lfr.535.1668288592442; Sat, 12 Nov 2022 13:29:52 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id b9-20020a0565120b8900b004a4251c7f75sm1042967lfv.202.2022.11.12.13.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 13:29:51 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Vineet Gupta , Palmer Dabbelt , Christoph Muellner , Kito Cheng , Jeff Law , Philipp Tomsich Subject: [PATCH 4/7] RISC-V: Recognize sign-extract + and cases for XVentanaCondOps Date: Sat, 12 Nov 2022 22:29:40 +0100 Message-Id: <20221112212943.3068249-5-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221112212943.3068249-1-philipp.tomsich@vrull.eu> References: <20221112212943.3068249-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?1749327565894527491?= X-GMAIL-MSGID: =?utf-8?q?1749327565894527491?= 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 --- gcc/config/riscv/xventanacondops.md | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gcc/config/riscv/xventanacondops.md b/gcc/config/riscv/xventanacondops.md index 7930ef1d837..3e9d5833a4b 100644 --- a/gcc/config/riscv/xventanacondops.md +++ b/gcc/config/riscv/xventanacondops.md @@ -73,3 +73,49 @@ "TARGET_XVENTANACONDOPS" [(set (match_dup 5) (match_dup 1)) (set (match_dup 0) (and:X (neg:X (ne:X (match_dup 5) (const_int 0))) + +;; 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])); +}) +