123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- From 687b8b8b116d51a7533c270a4fba87efa51a0629 Mon Sep 17 00:00:00 2001
- From: "Maciej W. Rozycki" <macro@embecosm.com>
- Date: Wed, 22 Nov 2023 01:18:27 +0000
- Subject: [PATCH 25/30] RISC-V: Fold all the cond-move variants together
- Code in `riscv_expand_conditional_move' for Ventana and Zicond targets
- seems like bolted on as an afterthought rather than properly merged so
- as to handle all the cases together.
- Fold the existing code pieces together then (observing that for short
- forward branch targets no integer comparisons need to be canonicalized),
- letting T-Head targets produce branchless sequences for all the integer
- comparisons rather than for equality ones only, and preparing for the
- handling of floating-point comparisons here across all conditional-move
- targets.
- gcc/
- * config/riscv/riscv.cc (riscv_expand_conditional_move): Unify
- conditional-move handling across all the relevant targets.
- ---
- gcc/config/riscv/riscv.cc | 79 ++++++++++++++++-----------------------
- 1 file changed, 33 insertions(+), 46 deletions(-)
- diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
- index 4784fa051e1..6ed3c2d1d1d 100644
- --- a/gcc/config/riscv/riscv.cc
- +++ b/gcc/config/riscv/riscv.cc
- @@ -3533,7 +3533,6 @@ riscv_expand_conditional_move_onesided (rtx dest, rtx cons, rtx alt,
-
- /* Emit a cond move: If OP holds, move CONS to DEST; else move ALT to DEST.
- Return 0 if expansion failed. */
- -
- bool
- riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt)
- {
- @@ -3542,50 +3541,28 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt)
- rtx op0 = XEXP (op, 0);
- rtx op1 = XEXP (op, 1);
-
- - if (TARGET_XTHEADCONDMOV
- - && GET_MODE_CLASS (mode) == MODE_INT
- - && reg_or_0_operand (cons, mode)
- - && reg_or_0_operand (alt, mode)
- - && GET_MODE (op) == mode
- - && GET_MODE (op0) == mode
- - && GET_MODE (op1) == mode
- - && (code == EQ || code == NE))
- + if ((TARGET_ZICOND_LIKE && GET_MODE_CLASS (mode) == MODE_INT)
- + || TARGET_SFB_ALU || TARGET_XTHEADCONDMOV)
- {
- - riscv_expand_conditional_move_onesided (dest, cons, alt, code, op0, op1);
- - return true;
- - }
- - else if (TARGET_SFB_ALU
- - && mode == word_mode)
- - {
- - riscv_emit_int_compare (&code, &op0, &op1);
- - rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
- + machine_mode mode0 = GET_MODE (op0);
- + machine_mode mode1 = GET_MODE (op1);
-
- - /* The expander is a bit loose in its specification of the true
- - arm of the conditional move. That allows us to support more
- - cases for extensions which are more general than SFB. But
- - does mean we need to force CONS into a register at this point. */
- - cons = force_reg (GET_MODE (dest), cons);
- - emit_insn (gen_rtx_SET (dest, gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
- - cond, cons, alt)));
- - return true;
- - }
- - else if (TARGET_ZICOND_LIKE
- - && GET_MODE_CLASS (mode) == MODE_INT)
- - {
- /* The comparison must be comparing WORD_MODE objects. We must
- enforce that so that we don't strip away a sign_extension
- thinking it is unnecessary. We might consider using
- riscv_extend_operands if they are not already properly extended. */
- - if (GET_MODE (op0) != word_mode || GET_MODE (op1) != word_mode)
- + if ((mode0 != word_mode && mode0 != VOIDmode)
- + || (mode1 != word_mode && mode1 != VOIDmode))
- return false;
-
- /* Canonicalize the comparison. It must be an equality comparison
- - of integer operands. If it isn't, then emit an SCC instruction
- + of integer operands, or with SFB it can be any comparison of
- + integer operands. If it isn't, then emit an SCC instruction
- so that we can then use an equality comparison against zero. */
- - if (!equality_operator (op, VOIDmode) || !INTEGRAL_MODE_P (mode0))
- + if ((!TARGET_SFB_ALU && !equality_operator (op, VOIDmode))
- + || !INTEGRAL_MODE_P (mode0))
- {
- - enum rtx_code new_code = NE;
- - bool *invert_ptr = 0;
- + bool *invert_ptr = nullptr;
- bool invert = false;
-
- /* If riscv_expand_int_scc inverts the condition, then it will
- @@ -3599,21 +3576,15 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt)
- rtx tmp = gen_reg_rtx (word_mode);
-
- /* We can support both FP and integer conditional moves. */
- - if (INTEGRAL_MODE_P (GET_MODE (XEXP (op, 0))))
- + if (INTEGRAL_MODE_P (mode0))
- riscv_expand_int_scc (tmp, code, op0, op1, invert_ptr);
- - else if (FLOAT_MODE_P (GET_MODE (XEXP (op, 0)))
- + else if (FLOAT_MODE_P (mode0)
- && fp_scc_comparison (op, GET_MODE (op)))
- riscv_expand_float_scc (tmp, code, op0, op1);
- else
- return false;
-
- - /* If riscv_expand_int_scc inverts the condition, then it will
- - flip the value of INVERT. We need to know where so that
- - we can adjust it for our needs. */
- - if (invert)
- - new_code = EQ;
- -
- - op = gen_rtx_fmt_ee (new_code, mode, tmp, const0_rtx);
- + op = gen_rtx_fmt_ee (invert ? EQ : NE, mode, tmp, const0_rtx);
-
- /* We've generated a new comparison. Update the local variables. */
- code = GET_CODE (op);
- @@ -3621,10 +3592,26 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt)
- op1 = XEXP (op, 1);
- }
-
- + if (TARGET_SFB_ALU || TARGET_XTHEADCONDMOV)
- + {
- + riscv_emit_int_compare (&code, &op0, &op1, !TARGET_SFB_ALU);
- + rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
- +
- + /* The expander is a bit loose in its specification of the true
- + arm of the conditional move. That allows us to support more
- + cases for extensions which are more general than SFB. But
- + does mean we need to force CONS into a register at this point. */
- + cons = force_reg (mode, cons);
- + /* With XTheadCondMov we need to force ALT into a register too. */
- + alt = force_reg (mode, alt);
- + emit_insn (gen_rtx_SET (dest, gen_rtx_IF_THEN_ELSE (mode, cond,
- + cons, alt)));
- + return true;
- + }
- /* 0, reg or 0, imm */
- - if (cons == CONST0_RTX (mode)
- - && (REG_P (alt)
- - || (CONST_INT_P (alt) && alt != CONST0_RTX (mode))))
- + else if (cons == CONST0_RTX (mode)
- + && (REG_P (alt)
- + || (CONST_INT_P (alt) && alt != CONST0_RTX (mode))))
- {
- riscv_emit_int_compare (&code, &op0, &op1, true);
- rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
- --
- 2.25.1
|