0023-Cost-model-for-ZBS-extension.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From 254eef43b7f99cc3308d02343c603286ba121816 Mon Sep 17 00:00:00 2001
  2. From: "yilun.xie" <yilun.xie@starfivetech.com>
  3. Date: Thu, 18 Nov 2021 16:13:59 +0800
  4. Subject: [PATCH 23/26] Cost model for ZBS extension
  5. ---
  6. gcc/config/riscv/riscv.c | 47 +++++++++++++++++++++++++++++++++++++++-
  7. 1 file changed, 46 insertions(+), 1 deletion(-)
  8. diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
  9. index 0978666a366..61666b8b2f6 100644
  10. --- a/gcc/config/riscv/riscv.c
  11. +++ b/gcc/config/riscv/riscv.c
  12. @@ -1830,8 +1830,25 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
  13. *total = COSTS_N_INSNS (1);
  14. return true;
  15. }
  16. - gcc_fallthrough ();
  17. + /* bclri pattern for zbs. */
  18. + if (TARGET_ZBS
  19. + && not_single_bit_mask_operand (XEXP (x, 1), VOIDmode))
  20. + {
  21. + *total = COSTS_N_INSNS (1);
  22. + return true;
  23. + }
  24. + /* bclr pattern for zbs. */
  25. + if (TARGET_ZBS
  26. + && REG_P (XEXP (x, 1))
  27. + && GET_CODE (XEXP (x, 0)) == ROTATE
  28. + && CONST_INT_P (XEXP ((XEXP (x, 0)), 0))
  29. + && INTVAL (XEXP ((XEXP (x, 0)), 0)) == -2)
  30. + {
  31. + *total = COSTS_N_INSNS (1);
  32. + return true;
  33. + }
  34. + gcc_fallthrough ();
  35. case IOR:
  36. case XOR:
  37. /* orn, andn and xorn pattern for zbb. */
  38. @@ -1842,6 +1859,17 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
  39. return true;
  40. }
  41. + /* bset[i] and binv[i] pattern for zbs. */
  42. + if ((GET_CODE (x) == IOR || GET_CODE (x) == XOR)
  43. + && TARGET_ZBS
  44. + && ((GET_CODE (XEXP (x, 0)) == ASHIFT
  45. + && CONST_INT_P (XEXP (XEXP (x, 0), 0)))
  46. + || single_bit_mask_operand (XEXP (x, 1), VOIDmode)))
  47. + {
  48. + *total = COSTS_N_INSNS (1);
  49. + return true;
  50. + }
  51. +
  52. /* Double-word operations use two single-word operations. */
  53. *total = riscv_binary_cost (x, 1, 2);
  54. return false;
  55. @@ -1857,9 +1885,26 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
  56. *total = COSTS_N_INSNS (SINGLE_SHIFT_COST);
  57. return true;
  58. }
  59. + /* bext pattern for zbs. */
  60. + if (TARGET_ZBS && outer_code == SET
  61. + && GET_CODE (XEXP (x, 1)) == CONST_INT
  62. + && INTVAL (XEXP (x, 1)) == 1)
  63. + {
  64. + *total = COSTS_N_INSNS (SINGLE_SHIFT_COST);
  65. + return true;
  66. + }
  67. return false;
  68. case ASHIFT:
  69. + /* bset pattern for zbs. */
  70. + if (TARGET_ZBS
  71. + && CONST_INT_P (XEXP (x, 0))
  72. + && INTVAL (XEXP (x, 0)) == 1)
  73. + {
  74. + *total = COSTS_N_INSNS (1);
  75. + return true;
  76. + }
  77. + gcc_fallthrough ();
  78. case ASHIFTRT:
  79. case LSHIFTRT:
  80. *total = riscv_binary_cost (x, SINGLE_SHIFT_COST,
  81. --
  82. 2.33.1