]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: costs: handle BSWAP
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Fri, 18 Dec 2020 09:00:34 +0000 (10:00 +0100)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Wed, 9 Nov 2022 09:31:48 +0000 (10:31 +0100)
The BSWAP operation is not handled in rtx_costs. Add it.

With Zbb, BSWAP for XLEN is a single instruction; for smaller modes,
it will expand into two.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_rtx_costs): Add BSWAP.

gcc/config/riscv/riscv.cc

index 32f9ef9ade9f3e00f292bad67ae1cebb471b3367..ab6c745c722cc563053deb393fac8c0f75ede733 100644 (file)
@@ -2562,6 +2562,16 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
       *total = riscv_extend_cost (XEXP (x, 0), GET_CODE (x) == ZERO_EXTEND);
       return false;
 
+    case BSWAP:
+      if (TARGET_ZBB)
+       {
+         /* RISC-V only defines rev8 for XLEN, so we will need an extra
+            shift-right instruction for smaller modes. */
+         *total = COSTS_N_INSNS (mode == word_mode ? 1 : 2);
+         return true;
+       }
+      return false;
+
     case FLOAT:
     case UNSIGNED_FLOAT:
     case FIX: