Hi,

this patch adds asserts that ensure we only expand an RDIV_EXPR with
actual float mode.  It also replaces the RDIV_EXPR in setting a
vectorized loop's length by EXACT_DIV_EXPR.  The code in question is
only used with length-control targets (riscv, powerpc, s390).

Bootstrapped and regtested on x86, aarch64, and power10. Regtested on rv64gcv_zvl512b.

Regards
Robin

        PR target/121014

gcc/ChangeLog:

        * cfgexpand.cc (expand_debug_expr): Assert FLOAT_MODE_P.
        * optabs-tree.cc (optab_for_tree_code): Assert FLOAT_TYPE_P.
        * tree-vect-loop.cc (vect_get_loop_len): Use EXACT_DIV_EXPR.
---
gcc/cfgexpand.cc      | 2 ++
gcc/optabs-tree.cc    | 2 ++
gcc/tree-vect-loop.cc | 2 +-
3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc
index 33649d43f71..a656ccebf17 100644
--- a/gcc/cfgexpand.cc
+++ b/gcc/cfgexpand.cc
@@ -5358,6 +5358,8 @@ expand_debug_expr (tree exp)
      return simplify_gen_binary (MULT, mode, op0, op1);

    case RDIV_EXPR:
+      gcc_assert (FLOAT_MODE_P (mode));
+      /* Fall through.  */
    case TRUNC_DIV_EXPR:
    case EXACT_DIV_EXPR:
      if (unsignedp)
diff --git a/gcc/optabs-tree.cc b/gcc/optabs-tree.cc
index 6dfe8ee4c4e..9308a6dfd65 100644
--- a/gcc/optabs-tree.cc
+++ b/gcc/optabs-tree.cc
@@ -82,6 +82,8 @@ optab_for_tree_code (enum tree_code code, const_tree type,
        return unknown_optab;
      /* FALLTHRU */
    case RDIV_EXPR:
+      gcc_assert (FLOAT_TYPE_P (type));
+      /* FALLTHRU */
    case TRUNC_DIV_EXPR:
    case EXACT_DIV_EXPR:
      if (TYPE_SATURATING (type))
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index d5044d5fe22..432a248715e 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11429,7 +11429,7 @@ vect_get_loop_len (loop_vec_info loop_vinfo, 
gimple_stmt_iterator *gsi,
          factor = exact_div (nunits1, nunits2).to_constant ();
          tree iv_type = LOOP_VINFO_RGROUP_IV_TYPE (loop_vinfo);
          gimple_seq seq = NULL;
-         loop_len = gimple_build (&seq, RDIV_EXPR, iv_type, loop_len,
+         loop_len = gimple_build (&seq, EXACT_DIV_EXPR, iv_type, loop_len,
                                   build_int_cst (iv_type, factor));
          if (seq)
            gsi_insert_seq_before (gsi, seq, GSI_SAME_STMT);
--
2.50.0

Reply via email to