From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id C56C73AA9012 for ; Thu, 17 Nov 2022 15:13:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C56C73AA9012 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-x133.google.com with SMTP id j16so3239652lfe.12 for ; Thu, 17 Nov 2022 07:13:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7MY5tXKIeP/pc9cdN6mbreRNzX+ejIfQqappK5rd2w0=; b=GhGNmTMD5Xzi+goPZq6GxsshwUAH1EmFtRvFYkTFx3fmYK4faxu5vT7RDRXifPgtHQ BaSlgSTL5byj/a2fpwzxmlD8sy1l7qtfNc7Salg8Lchs57iOwQKj/TdOh3m8tpmBOkS/ s3Swj3eobrV/PVhmtYD4KV0OMmP+qVUGxonEXYGo36BU/De5vrx4ddadrzggWdbbMCTh nlWvgqJuoa5daEskBwT2c3QzjLDBLEMNVWi8SOwFDu9unEKni+7OKGW5TcZW6vpdR7Z6 2qreUWS7Dqz4qFcZM5TD7mC2qvnLjfj9PTgnqv7rCC285Lt+ujjKMqSyNmKgKYID7oM8 prEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7MY5tXKIeP/pc9cdN6mbreRNzX+ejIfQqappK5rd2w0=; b=ty5ijIJO3fQgh86f0KykQdMJz8q9Qd2rukRLI5/GxCp7b+zL9nYoLsbEgAoqWeU0vD 1U5EKGdE2wh461lYISZRnFnk/fLV7AHW4b6f0cvd7RM71ZodySHfL6by6MUP6ah/5G3C m5/NKNKnl+t6WNg0csrgnFr3EmYBlKNhlKJV5T4LKtsyTm3QDGjkHy7mUzLm9iykTDtX ZnewWHGf9TbXH2YFONF+CBhmC0v38vFX3InC6bnKzh7Ty8p9O/BOXMcE6/DqU5wFl2pP 6n+iuoDiM2GBARERx9nu0ivGc8FRYgCw62siafUKdzt9bpaZG77OfObT5KO8d93GPQ+W 84fg== X-Gm-Message-State: ANoB5pkcHDd8ZJdUryT33wNZ16cXbB71mSdwIYS5gkJhhvjitajkGl/7 j3P+6xxdAfSjzMpzBm3scbirmgaoKFlQtVk8T88VQw== X-Google-Smtp-Source: AA0mqf4Yj+ftNvXs18Xd0XiGiHpgRCibg/oDoE3lAwtMqDUNRQzDw69/b2938HTLu4QNJ9iH2GMvxnjGSWyu0HY3CQc= X-Received: by 2002:a05:6512:3b85:b0:4b1:753b:e671 with SMTP id g5-20020a0565123b8500b004b1753be671mr991511lfv.441.1668697982293; Thu, 17 Nov 2022 07:13:02 -0800 (PST) MIME-Version: 1.0 References: <20221113204858.4062163-1-philipp.tomsich@vrull.eu> <71d8d0ca-c249-28fd-7327-5a3b932dad94@gmail.com> In-Reply-To: <71d8d0ca-c249-28fd-7327-5a3b932dad94@gmail.com> From: Philipp Tomsich Date: Thu, 17 Nov 2022 16:12:49 +0100 Message-ID: Subject: Re: [PATCH] RISC-V: Handle "(a & twobits) == singlebit" in branches using Zbs To: Jeff Law Cc: gcc-patches@gcc.gnu.org, Christoph Muellner , Kito Cheng , Vineet Gupta , Jeff Law , Palmer Dabbelt Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_SHORT,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: On Thu, 17 Nov 2022 at 15:58, Jeff Law wrote: > > > On 11/13/22 13:48, Philipp Tomsich wrote: > > Use Zbs when generating a sequence for "if ((a & twobits) == singlebit) ..." > > that can be expressed as bexti + bexti + andn. > > > > gcc/ChangeLog: > > > > * config/riscv/bitmanip.md (*branch_mask_twobits_equals_singlebit): > > Handle "if ((a & T) == C)" using Zbs, when T has 2 bits set and C has one > > of these tow bits set. > > * config/riscv/predicates.md (const_twobits_operand): New predicate. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/riscv/zbs-if_then_else-01.c: New test. > > s/tow/two/ in the ChangeLog. > > > > > > > > > Signed-off-by: Philipp Tomsich > > --- > > > > gcc/config/riscv/bitmanip.md | 42 +++++++++++++++++++ > > gcc/config/riscv/predicates.md | 5 +++ > > .../gcc.target/riscv/zbs-if_then_else-01.c | 20 +++++++++ > > 3 files changed, 67 insertions(+) > > create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-if_then_else-01.c > > > > diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md > > index 7a8f4e35880..2cea394671f 100644 > > --- a/gcc/config/riscv/bitmanip.md > > +++ b/gcc/config/riscv/bitmanip.md > > @@ -690,3 +690,45 @@ > > "TARGET_ZBS" > > [(set (match_dup 0) (zero_extract:X (match_dup 1) (const_int 1) (match_dup 2))) > > (set (match_dup 0) (xor:X (match_dup 0) (const_int 1)))]) > > + > > +;; IF_THEN_ELSE: test for 2 bits of opposite polarity > > +(define_insn_and_split "*branch_mask_twobits_equals_singlebit" > > + [(set (pc) > > + (if_then_else (match_operator 1 "equality_operator" > > + [(and:X (match_operand:X 2 "register_operand" "r") > > + (match_operand:X 3 "const_twobits_operand" "i")) > > + (match_operand:X 4 "single_bit_mask_operand" "i")]) > > + (label_ref (match_operand 0 "" "")) > > + (pc))) > > + (clobber (match_scratch:X 5 "=&r")) > > + (clobber (match_scratch:X 6 "=&r"))] > > + "TARGET_ZBS && TARGET_ZBB && !SMALL_OPERAND (INTVAL (operands[3]))" > > + "#" > > + "&& reload_completed" > > + [(set (match_dup 5) (zero_extract:X (match_dup 2) > > + (const_int 1) > > + (match_dup 8))) > > + (set (match_dup 6) (zero_extract:X (match_dup 2) > > + (const_int 1) > > + (match_dup 9))) > > + (set (match_dup 6) (and:X (not:X (match_dup 6)) (match_dup 5))) > > + (set (pc) (if_then_else (match_op_dup 1 [(match_dup 6) (const_int 0)]) > > + (label_ref (match_dup 0)) > > + (pc)))] > > +{ > > + unsigned HOST_WIDE_INT twobits_mask = UINTVAL (operands[3]); > > + unsigned HOST_WIDE_INT singlebit_mask = UINTVAL (operands[4]); > > + > > + /* Make sure that the reference value has one of the bits of the mask set */ > > + if ((twobits_mask & singlebit_mask) == 0) > > + FAIL; > > This fails the split, but in the event this scenario occurs we still > would up with an ICE as the output template requires splitting. Don't > we need to have this be part of the pattern's condition instead so that > it never matches in that case? This serves as an assertion only, as that case is non-sensical and will be optimized away by earlier passes (as "a & C == T" with C and T sharing no bits will always be false). IFAIK the preceding transforms should always clean such a check up, but we can't exclude the possibility that with enough command line overrides and params we might see such a non-sensical test making it all the way to the backend. What would you recommend? Adding this to the pattern's condition feels a bit redundant. In fact, I am leaning towards hiding the !SMALL_OPERAND check in yet another predicate that combines const_twobits_operand with a match_test for !SMALL_OPERAND. > ISTM we should probably have a test to cover this scenario. > > > > jeff > >