From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AA0mqf6+272mbH3o73aEuntZIuMrnXmyFw5Hr98N3CGUIACZMOlYtYypW1f7kuiaUSwCjifFHce2RA== 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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])); +}) + -- 2.34.1