public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: branch-(not)equals-zero compares against $zero
@ 2022-11-08 19:55 Philipp Tomsich
  2022-11-17 22:44 ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Philipp Tomsich @ 2022-11-08 19:55 UTC (permalink / raw)
  To: gcc-patches
  Cc: Vineet Gupta, Kito Cheng, Jeff Law, Palmer Dabbelt,
	Christoph Muellner, Philipp Tomsich

If we are testing a register or a paradoxical subreg (i.e. anything that is not
a partial subreg) for equality/non-equality with zero, we can generate a branch
that compares against $zero.  This will work for QI, HI, SI and DImode, so we
enable this for ANYI.

2020-08-30  gcc/ChangeLog:

	* config/riscv/riscv.md (*branch<mode>_equals_zero): Added pattern.

---

 gcc/config/riscv/riscv.md | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 798f7370a08..97f6ca37891 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -2205,6 +2205,19 @@
 
 ;; Conditional branches
 
+(define_insn "*branch<mode>_equals_zero"
+  [(set (pc)
+	(if_then_else
+	 (match_operator 1 "equality_operator"
+			 [(match_operand:ANYI 2 "register_operand" "r")
+			  (const_int 0)])
+	 (label_ref (match_operand 0 "" ""))
+	 (pc)))]
+  "!partial_subreg_p (operands[2])"
+  "b%C1\t%2,zero,%0"
+  [(set_attr "type" "branch")
+   (set_attr "mode" "none")])
+
 (define_insn "*branch<mode>"
   [(set (pc)
 	(if_then_else
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-19 16:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 19:55 [PATCH] RISC-V: branch-(not)equals-zero compares against $zero Philipp Tomsich
2022-11-17 22:44 ` Jeff Law
2022-11-18  4:53   ` Palmer Dabbelt
2022-11-18  9:14     ` Philipp Tomsich
2022-11-19 16:47     ` Jeff Law

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).