]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: add consecutive_bits_operand predicate
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Tue, 24 May 2022 13:03:47 +0000 (15:03 +0200)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Tue, 14 Jun 2022 11:35:49 +0000 (13:35 +0200)
Provide an easy way to constrain for constants that are a a single,
consecutive run of ones.

gcc/ChangeLog:

* config/riscv/predicates.md (consecutive_bits_operand):
Implement new predicate.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
gcc/config/riscv/predicates.md

index c37caa2502b58c470a12dec697b970a009ab95c3..90db5dfcdd5f114e59863700900cc39d56aca0c4 100644 (file)
 (define_predicate "imm5_operand"
   (and (match_code "const_int")
        (match_test "INTVAL (op) < 5")))
+
+;; A CONST_INT operand that consists of a single run of consecutive set bits.
+(define_predicate "consecutive_bits_operand"
+  (match_code "const_int")
+{
+       unsigned HOST_WIDE_INT val = UINTVAL (op);
+       if (exact_log2 ((val >> ctz_hwi (val)) + 1) < 0)
+               return false;
+
+       return true;
+})