On 12/6/2021 11:43 AM, Robin Dapp via Gcc-patches wrote:
Currently we only ever call emit_conditional_move with the comparison
(as well as its comparands) we got from the jump.  Thus, backends are
going to emit a CC comparison for every conditional move that is being
generated instead of re-using the existing CC.
This, combined with emitting temporaries for each conditional move,
causes sky-high costs for conditional moves.

This patch allows to re-use a CC so the costing situation is improved a
bit.
---
  gcc/expmed.c |   8 +--
  gcc/expr.c   |  10 ++--
  gcc/ifcvt.c  |  45 ++++++++++-------
  gcc/optabs.c | 135 ++++++++++++++++++++++++++++++++++++++-------------
  gcc/optabs.h |   4 +-
  gcc/rtl.h    |  11 ++++-
  6 files changed, 150 insertions(+), 63 deletions(-)



@@ -4948,17 +4947,85 @@ emit_conditional_move (rtx target, enum rtx_code code, 
rtx op0, rtx op1,

+/* Helper for emitting a conditional move.  */
+
+static rtx
+emit_conditional_move_1 (rtx target, rtx comparison,
+                        rtx op2, rtx op3, machine_mode mode)
+{
+  enum insn_code icode;
+
+  if (comparison == NULL_RTX || !COMPARISON_P (comparison))
+    return NULL_RTX;
+
+  /* If the two source operands are identical, that's just a move.  */
+  if (rtx_equal_p (op2, op3))
+    {
+      if (!target)
+       target = gen_reg_rtx (mode);
+
+      emit_move_insn (target, op3);
+      return target;
+    }
What if the condition has a side effect?  Doesn't this drop the side effect by converting the conditional move into a simple move?

That's my only technical concern.  Obviously the patch needs a ChangeLog.

Jeff

Reply via email to