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