From patchwork Thu May 4 17:08:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Moreira Zinsly X-Patchwork-Id: 90153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp478242vqo; Thu, 4 May 2023 10:08:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5k4RGxdZebouRV787R7FrFUcgprUT44lE+rNs5Mt7Q7DnCUcqA3Wj/c5hMEeiPLyaeCkYY X-Received: by 2002:a17:906:da8c:b0:94d:cebe:691 with SMTP id xh12-20020a170906da8c00b0094dcebe0691mr6304805ejb.69.1683220129270; Thu, 04 May 2023 10:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683220129; cv=none; d=google.com; s=arc-20160816; b=Gg1s7tiR7QnaqhB8UyKZZW4oBaylLlqp3A2mTxnaH5X3Sif1zZKSRU7A57MSzv8YCC bpywCHNMICn/hJtNBAB7YZMBtRAw1mWSNuudJWRAm5OqJwZ8tEwXSfbhIn3Cylxtm3cl 4MUFDJMAx/FqKRoiHFO+xA+NHitU9O3+jAo8uyp9VJlzcCe7lt1cpQLpEHguuPlpp2C6 1Oa8YvvVljZSAw0jQGcPi/JLS0MsRTaxc/BQDSfu9EBRAFgpsSa6Ekw/CJtMkkI3UxX7 LyaBwQWF3kc/dPhAbKikgWRx6U+f4qsXGJ2Uq//8vT9FDTA+yZ+Vcb2iJkEnX9Qu88Xg 71Uw== 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:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=AaJTiioywAQps25oevyyr4U0R++HmqgpZsZugwvW6SQ=; b=ohKaGtGBPw8aDpypyuL3wNK3dzeyfjX9x03kadVl8uYmEj4BdGrbd0prZMtvbilbFx 3POs/vo3F6U6XAqFrEiNtYsxEmPR/r0/GjYuu76xbJqTKjEiSImdt+sFAsasR5GMcyoU 8HuSu2gtnHN/Hbq7huJpvX2VmXBoz+DzqYuSG+O1jun3smpa3RjB2A71rQru2g4QDC4f 8b0SgALT/LOMYhACl4Ps/nwBmZ67iAoommRYm0Tzr6ZiF3JHS2d7BCP081tYETJg1luY I4Q2MkBtEoGe5VGxcoB+Mly+TrholngWHVzYkRf9+VVFJ6ygblSbeqkDFkbv/t/5iKdC puOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JIE7PRPk; 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 sd4-20020a1709076e0400b0096593aa87dasi2650274ejc.309.2023.05.04.10.08.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 10:08:49 -0700 (PDT) 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=@ventanamicro.com header.s=google header.b=JIE7PRPk; 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 CF1EA385695C for ; Thu, 4 May 2023 17:08:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 273363858439 for ; Thu, 4 May 2023 17:08:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 273363858439 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6a60630574aso471612a34.1 for ; Thu, 04 May 2023 10:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1683220095; x=1685812095; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AaJTiioywAQps25oevyyr4U0R++HmqgpZsZugwvW6SQ=; b=JIE7PRPkXvsnUzdBhdqb6qY/bp0OapAqWiPkWmqTDFegxrioz2CWtXTEsz1AZkWro8 dFbdRM3+nMLIcBD9Co29V1H19Sbthfbbw0fTxV5uOcz4IQhBxb2aoF5M4BrQ37FQSBh4 64yD58pYEvv7stVtP8x++o5uVR9V/zK7JvsvWLPCll+EP2hcJTFk+FhVDSqcGl4TCRyW hlINbOglKtxgjXz5yqn9FgMtsQjMZQZvi4iJVztEzLzNVh64Ht3vG8nACtxZbCN78ojo AXo9FnA2LhNdYvEZXWQ5/qboex0SsskI+XT8IjIcNDfsVy3VUuWSGgWOeuvttF4TaV64 YbVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683220095; x=1685812095; 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=AaJTiioywAQps25oevyyr4U0R++HmqgpZsZugwvW6SQ=; b=Ji3oNUyqKKrLwcvEdadOfSsMzAysfeEXLnMdRyU58b/b3mUyugT4Y6fBhKZYFPYDEo CoNP8F4/C92IBkZTnk3957CXr8J70NQxELshNT2uobnw9HBuDHFndmr+4C6ag/ETVet5 Xdm13BkclGxzviYkpZ/ypnmiPx7qHX6m1x13pexQcFt8BfLcpjoheSXyspn3MAM6wm4j gmeiMttLsiRF8ruU9BYC7LvXpDmoFqIP9GxdOTeORA7qYXbIheGQTnIOplWajfKgimy/ pAWf8PAA8BKqLUz07c0rMMg/9ttH8uLGHYGdb+1ozwcoLHzeRkVcaeM1smkhR9/JjJF5 TtJg== X-Gm-Message-State: AC+VfDwjAjO0Hbr08XzyG1De/DiuzSM0eWVCnxcyr5s7cBw1yWz+k7S5 MsMfq0mel/Uxn+HjQkgDqVrFLzwB3rcBggEK7bA= X-Received: by 2002:a9d:63c4:0:b0:6a6:505b:3d6c with SMTP id e4-20020a9d63c4000000b006a6505b3d6cmr263487otl.26.1683220094897; Thu, 04 May 2023 10:08:14 -0700 (PDT) Received: from marvin.. ([2804:14d:bac2:9b0b::1000]) by smtp.gmail.com with ESMTPSA id dm13-20020a0568303b8d00b006a5e22458e9sm1858909otb.80.2023.05.04.10.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 10:08:14 -0700 (PDT) From: Raphael Moreira Zinsly To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, Raphael Moreira Zinsly Subject: [PATCH] RISC-V: Add bext pattern for ZBS Date: Thu, 4 May 2023 14:08:08 -0300 Message-Id: <20230504170808.1829411-1-rzinsly@ventanamicro.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.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?1764984229779944578?= X-GMAIL-MSGID: =?utf-8?q?1764984229779944578?= When (a & (1 << bit_no)) is tested inside an IF we can use a bit extract. gcc/ChangeLog: * config/riscv/bitmanip.md (bext): Rename one to avoid name clash. (branch_bext): New split pattern. gcc/testsuite/ChangeLog: * gcc.target/riscv/zbs-bext-02.c: New test. --- gcc/config/riscv/bitmanip.md | 24 +++++++++++++++++++- gcc/testsuite/gcc.target/riscv/zbs-bext-02.c | 18 +++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-bext-02.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index a27fc3e34a1..e29e2d1fa53 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -595,7 +595,7 @@ ;; When performing `(a & (1UL << bitno)) ? 0 : -1` the combiner ;; usually has the `bitno` typed as X-mode (i.e. no further ;; zero-extension is performed around the bitno). -(define_insn "*bext" +(define_insn "*bext_2" [(set (match_operand:X 0 "register_operand" "=r") (zero_extract:X (match_operand:X 1 "register_operand" "r") (const_int 1) @@ -720,6 +720,28 @@ operands[9] = GEN_INT (clearbit); }) +;; IF_THEN_ELSE: test for (a & (1 << BIT_NO)) +(define_insn_and_split "*branch_bext" + [(set (pc) + (if_then_else + (match_operator 1 "equality_operator" + [(zero_extract:X (match_operand:X 2 "register_operand" "r") + (const_int 1) + (zero_extend:X (match_operand:QI 3 "register_operand" "r"))) + (const_int 0)]) + (label_ref (match_operand 0 "" "")) + (pc))) + (clobber (match_scratch:X 4 "=&r"))] + "TARGET_ZBS" + "#" + "&& reload_completed" + [(set (match_dup 4) (zero_extract:X (match_dup 2) + (const_int 1) + (zero_extend:X (match_dup 3)))) + (set (pc) (if_then_else (match_op_dup 1 [(match_dup 4) (const_int 0)]) + (label_ref (match_dup 0)) + (pc)))]) + ;; ZBKC or ZBC extension (define_insn "riscv_clmul_" [(set (match_operand:X 0 "register_operand" "=r") diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bext-02.c b/gcc/testsuite/gcc.target/riscv/zbs-bext-02.c new file mode 100644 index 00000000000..3f3b8404eca --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-bext-02.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-funroll-loops" } } */ + +int +foo(const long long B, int a) +{ + long long b = 1; + for (int sq = 0; sq < 64; sq++) + if (B & (b << sq)) + a++; + + return a; +} + +/* { dg-final { scan-assembler-times "bext\t" 1 } } */ +/* { dg-final { scan-assembler-not "bset" } } */ +/* { dg-final { scan-assembler-not "and" } } */