0006-PATCH-3-5-RISC-V-Cost-model-for-Zicond.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From a2db414e368f4126df3af3376a9b687917b9daf1 Mon Sep 17 00:00:00 2001
  2. From: Xiao Zeng <zengxiao@eswincomputing.com>
  3. Date: Wed, 2 Aug 2023 00:17:12 -0600
  4. Subject: [PATCH 06/30] [PATCH 3/5] [RISC-V] Cost model for Zicond.
  5. This patch implements a reasonable cost model for using Zicond to
  6. implement conditional moves. Essentially the Zicond insns are always
  7. COSTS_N_INSNS (1).
  8. Note there is still a problem with the costing model in general that
  9. results in failure to if-convert as often as we should. In simplest
  10. terms the insn costing model sums the cost of the SET_SRC and the
  11. cost of the SET_DEST. Thus the conditional move is considered twice
  12. as costly as it should be. That will have to be addressed separately.
  13. gcc/
  14. * config/riscv/riscv.cc (riscv_rtx_costs): Add costing for
  15. using Zicond to implement some conditional moves.
  16. ---
  17. gcc/config/riscv/riscv.cc | 14 ++++++++++++++
  18. 1 file changed, 14 insertions(+)
  19. diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
  20. index e95cb2db24c..6ec985db430 100644
  21. --- a/gcc/config/riscv/riscv.cc
  22. +++ b/gcc/config/riscv/riscv.cc
  23. @@ -2358,6 +2358,20 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
  24. *total = COSTS_N_INSNS (1);
  25. return true;
  26. }
  27. + else if (TARGET_ZICOND
  28. + && outer_code == SET
  29. + && ((GET_CODE (XEXP (x, 1)) == REG
  30. + && XEXP (x, 2) == CONST0_RTX (GET_MODE (XEXP (x, 1))))
  31. + || (GET_CODE (XEXP (x, 2)) == REG
  32. + && XEXP (x, 1) == CONST0_RTX (GET_MODE (XEXP (x, 2))))
  33. + || (GET_CODE (XEXP (x, 1)) == REG
  34. + && rtx_equal_p (XEXP (x, 1), XEXP (XEXP (x, 0), 0)))
  35. + || (GET_CODE (XEXP (x, 1)) == REG
  36. + && rtx_equal_p (XEXP (x, 2), XEXP (XEXP (x, 0), 0)))))
  37. + {
  38. + *total = COSTS_N_INSNS (1);
  39. + return true;
  40. + }
  41. else if (LABEL_REF_P (XEXP (x, 1)) && XEXP (x, 2) == pc_rtx)
  42. {
  43. if (equality_operator (XEXP (x, 0), mode)
  44. --
  45. 2.25.1