public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Philipp Tomsich <philipp.tomsich@vrull.eu>, gcc-patches@gcc.gnu.org
Cc: Christoph Muellner <christoph.muellner@vrull.eu>,
	Kito Cheng <kito.cheng@gmail.com>,
	Vineet Gupta <vineetg@rivosinc.com>,
	Jeff Law <jlaw@ventanamicro.com>,
	Palmer Dabbelt <palmer@rivosinc.com>
Subject: Re: [PATCH] RISC-V: Handle "(a & twobits) == singlebit" in branches using Zbs
Date: Thu, 17 Nov 2022 07:58:51 -0700	[thread overview]
Message-ID: <71d8d0ca-c249-28fd-7327-5a3b932dad94@gmail.com> (raw)
In-Reply-To: <20221113204858.4062163-1-philipp.tomsich@vrull.eu>


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<X:mode>_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 <philipp.tomsich@vrull.eu>
> ---
>
>   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<X:mode>_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?


ISTM we should probably have a test to cover this scenario.



jeff



  reply	other threads:[~2022-11-17 14:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13 20:48 Philipp Tomsich
2022-11-17 14:58 ` Jeff Law [this message]
2022-11-17 15:12   ` Philipp Tomsich
2022-11-17 16:39     ` Jeff Law
2022-11-17 16:46       ` Philipp Tomsich
2022-11-17 18:25 ` Andrew Pinski
2022-11-17 18:27   ` Andrew Pinski
2022-11-17 18:57     ` Philipp Tomsich
2022-11-17 18:33 ` Andrew Waterman
2022-11-17 18:51   ` Philipp Tomsich
2022-11-17 18:56     ` Andrew Waterman
2022-11-17 18:59       ` Philipp Tomsich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=71d8d0ca-c249-28fd-7327-5a3b932dad94@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=christoph.muellner@vrull.eu \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jlaw@ventanamicro.com \
    --cc=kito.cheng@gmail.com \
    --cc=palmer@rivosinc.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=vineetg@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).