]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
optabs-query: Use opt_machine_mode for smallest_int_mode_for_size [PR115495].
authorRobin Dapp <rdapp@ventanamicro.com>
Tue, 20 Aug 2024 12:02:09 +0000 (14:02 +0200)
committerRobin Dapp <rdapp@ventanamicro.com>
Fri, 23 Aug 2024 09:36:05 +0000 (11:36 +0200)
In get_best_extraction_insn we use smallest_int_mode_for_size with
struct_bits as size argument.  PR115495 has struct_bits = 256 and we
don't have a mode for that.  This patch makes smallest_mode_for_size
and smallest_int_mode_for_size return opt modes so we can just skip
over the loop when there is no mode.

PR middle-end/115495

gcc/ChangeLog:

* cfgexpand.cc (expand_debug_expr): Require mode.
* combine.cc (make_extraction): Ditto.
* config/aarch64/aarch64.cc (aarch64_expand_cpymem): Ditto.
(aarch64_expand_setmem): Ditto.
* config/arc/arc.cc (arc_expand_cpymem): Ditto.
* config/arm/arm.cc (arm_expand_divmod_libfunc): Ditto.
* config/i386/i386.cc (ix86_get_mask_mode): Ditto.
* config/rs6000/predicates.md: Ditto.
* config/rs6000/rs6000.cc (vspltis_constant): Ditto.
* config/s390/s390.cc (s390_expand_insv): Ditto.
* config/sparc/sparc.cc (assign_int_registers): Ditto.
* coverage.cc (get_gcov_type): Ditto.
(get_gcov_unsigned_t): Ditto.
* dse.cc (find_shift_sequence): Ditto.
* expmed.cc (store_integral_bit_field): Ditto.
* expr.cc (convert_mode_scalar): Ditto.
(op_by_pieces_d::smallest_fixed_size_mode_for_size): Ditto.
(emit_block_move_via_oriented_loop): Ditto.
(copy_blkmode_to_reg): Ditto.
(store_field): Ditto.
* internal-fn.cc (expand_arith_overflow): Ditto.
* machmode.h (HAVE_MACHINE_MODES): Ditto.
(smallest_mode_for_size): Use opt_machine_mode.
(smallest_int_mode_for_size): Use opt_scalar_int_mode.
* optabs-query.cc (get_best_extraction_insn): Require mode.
* optabs.cc (expand_twoval_binop_libfunc): Ditto.
* stor-layout.cc (smallest_mode_for_size): Return
opt_machine_mode.
(layout_type): Require mode.
(initialize_sizetypes): Ditto.
* tree-ssa-loop-manip.cc (canonicalize_loop_ivs): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr115495.c: New test.

gcc/ada/ChangeLog:

* gcc-interface/utils2.cc (fast_modulo_reduction): Require mode.
(nonbinary_modular_operation): Ditto.

22 files changed:
gcc/ada/gcc-interface/utils2.cc
gcc/cfgexpand.cc
gcc/combine.cc
gcc/config/aarch64/aarch64.cc
gcc/config/arc/arc.cc
gcc/config/arm/arm.cc
gcc/config/i386/i386.cc
gcc/config/rs6000/predicates.md
gcc/config/rs6000/rs6000.cc
gcc/config/s390/s390.cc
gcc/config/sparc/sparc.cc
gcc/coverage.cc
gcc/dse.cc
gcc/expmed.cc
gcc/expr.cc
gcc/internal-fn.cc
gcc/machmode.h
gcc/optabs-query.cc
gcc/optabs.cc
gcc/stor-layout.cc
gcc/testsuite/gcc.target/riscv/rvv/autovec/pr115495.c [new file with mode: 0644]
gcc/tree-ssa-loop-manip.cc

index 0d7e03ec6b07cf659fe42f6388f95ec387907c0c..8eebf5935960ea277e21f08c0551b1f7a24d7831 100644 (file)
@@ -661,7 +661,7 @@ fast_modulo_reduction (tree op, tree modulus, unsigned int precision)
          if (type_precision < BITS_PER_WORD)
            {
              const scalar_int_mode m
-               = smallest_int_mode_for_size (type_precision + 1);
+               = smallest_int_mode_for_size (type_precision + 1).require ();
              tree new_type = gnat_type_for_mode (m, 1);
              op = fold_convert (new_type, op);
              modulus = fold_convert (new_type, modulus);
@@ -721,7 +721,8 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs,
      for its mode since operations are ultimately performed in the mode.  */
   if (TYPE_PRECISION (type) < precision)
     {
-      const scalar_int_mode m = smallest_int_mode_for_size (precision);
+      const scalar_int_mode m
+       = smallest_int_mode_for_size (precision).require ();
       op_type = gnat_type_for_mode (m, 1);
       modulus = fold_convert (op_type, modulus);
       lhs = fold_convert (op_type, lhs);
index dad3ae1b7c6e1318788dbf021ef7ebfc99e580cf..13f8c08d295abc5cb3b2f0767f18261793ab6536 100644 (file)
@@ -4867,7 +4867,7 @@ expand_debug_expr (tree exp)
                if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT))
                  return NULL;
                /* Bitfield.  */
-               mode1 = smallest_int_mode_for_size (bitsize);
+               mode1 = smallest_int_mode_for_size (bitsize).require ();
              }
            poly_int64 bytepos = bits_to_bytes_round_down (bitpos);
            if (maybe_ne (bytepos, 0))
index 3b50bc3529c45d4ed5a01a3b1f624d2a5c72a977..40e92941e428faab857e98307c3e7d862360bc2f 100644 (file)
@@ -7799,7 +7799,7 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos,
     {
       /* Be careful not to go beyond the extracted object and maintain the
         natural alignment of the memory.  */
-      wanted_inner_mode = smallest_int_mode_for_size (len);
+      wanted_inner_mode = smallest_int_mode_for_size (len).require ();
       while (pos % GET_MODE_BITSIZE (wanted_inner_mode) + len
             > GET_MODE_BITSIZE (wanted_inner_mode))
        wanted_inner_mode = GET_MODE_WIDER_MODE (wanted_inner_mode).require ();
index 69afcc6724a6190003511e64fee1f942e5222a66..40dacfcf2e784032580dec997ad1c85bada3dd85 100644 (file)
@@ -26760,7 +26760,8 @@ aarch64_expand_cpymem (rtx *operands, bool is_memmove)
         (when !STRICT_ALIGNMENT) - this is smaller and faster.  */
       if (size > 0 && size < 16 && !STRICT_ALIGNMENT)
        {
-         next_mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
+         next_mode = smallest_mode_for_size
+           (size * BITS_PER_UNIT, MODE_INT).require ();
          int n_bytes = GET_MODE_SIZE (next_mode).to_constant ();
          gcc_assert (n_bytes <= mode_bytes);
          offset -= n_bytes - size;
@@ -26871,7 +26872,8 @@ aarch64_expand_setmem (rtx *operands)
         (when !STRICT_ALIGNMENT) - this is smaller and faster.  */
       if (len > 0 && len < 16 && !STRICT_ALIGNMENT)
        {
-         next_mode = smallest_mode_for_size (len * BITS_PER_UNIT, MODE_INT);
+         next_mode = smallest_mode_for_size
+           (len * BITS_PER_UNIT, MODE_INT).require ();
          int n_bytes = GET_MODE_SIZE (next_mode).to_constant ();
          gcc_assert (n_bytes <= mode_bytes);
          offset -= n_bytes - len;
index 686de0ff2d574e71cca331a631238d88ef6ee8c3..c800226b179b1025eb8c721e915106e7e900dec0 100644 (file)
@@ -9157,7 +9157,7 @@ arc_expand_cpymem (rtx *operands)
 
       while (piece > size)
        piece >>= 1;
-      mode = smallest_int_mode_for_size (piece * BITS_PER_UNIT);
+      mode = smallest_int_mode_for_size (piece * BITS_PER_UNIT).require ();
       /* If we don't re-use temporaries, the scheduler gets carried away,
         and the register pressure gets unnecessarily high.  */
       if (0 && tmpx[i] && GET_MODE (tmpx[i]) == mode)
index 92cd168e65937ef7350477464e8b0becf85bceed..d54564a6c359ea48aac50b494e89fad53f428eed 100644 (file)
@@ -34332,7 +34332,7 @@ arm_expand_divmod_libfunc (rtx libfunc, machine_mode mode,
     gcc_assert (!TARGET_IDIV);
 
   scalar_int_mode libval_mode
-    = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode));
+    = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode)).require ();
 
   rtx libval = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST,
                                        libval_mode, op0, mode, op1, mode);
index d06e2141e563f412635482ebe46f32046743caad..224a78cc8327d387fd34095bec440b100932f252 100644 (file)
@@ -24637,11 +24637,11 @@ ix86_get_mask_mode (machine_mode data_mode)
       if (elem_size == 4
          || elem_size == 8
          || (TARGET_AVX512BW && (elem_size == 1 || elem_size == 2)))
-       return smallest_int_mode_for_size (nunits);
+       return smallest_int_mode_for_size (nunits).require ();
     }
 
   scalar_int_mode elem_mode
-    = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT);
+    = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT).require ();
 
   gcc_assert (elem_size * nunits == vector_size);
 
index cdfd400f63955f29c63512dd3eb7be7701973ea5..7f0b4ab61e6575f11852d129ec87fd4a325abc85 100644 (file)
       elt += (BYTES_BIG_ENDIAN ? -1 : 1) * (sz - isz) / isz;
     }
   else if (isz > sz)
-    inner = smallest_int_mode_for_size (sz * BITS_PER_UNIT);
+    inner = smallest_int_mode_for_size (sz * BITS_PER_UNIT).require ();
   val = const_vector_elt_as_int (op, elt);
   return EASY_VECTOR_MSB (val, inner);
 })
index f2bd9edea8a16db8c224687773dc00f803ed0954..94c0db4521e2c5549041937d4c1a77ef07db4e64 100644 (file)
@@ -6261,7 +6261,7 @@ vspltis_constant (rtx op, unsigned step, unsigned copies)
           | (small_val & mask)))
        return false;
       splat_val = small_val;
-      inner = smallest_int_mode_for_size (bitsize);
+      inner = smallest_int_mode_for_size (bitsize).require ();
     }
 
   /* Check if SPLAT_VAL can really be the operand of a vspltis[bhw].  */
index 7aea776da2f315cffd7186f092a6c62d27ef2a8a..47e1d5adfd99412244a0214621d315782d54cb82 100644 (file)
@@ -7042,7 +7042,7 @@ s390_expand_insv (rtx dest, rtx op1, rtx op2, rtx src)
       return true;
     }
 
-  smode = smallest_int_mode_for_size (bitsize);
+  smode = smallest_int_mode_for_size (bitsize).require ();
   smode_bsize = GET_MODE_BITSIZE (smode);
   mode_bsize = GET_MODE_BITSIZE (mode);
 
index 9282fb43b44f90975e8bcec558c5514ec88c881b..3a4c13a14e56c4cdedc3c4428a75804def567f8b 100644 (file)
@@ -7163,7 +7163,7 @@ assign_int_registers (int bitpos, assign_data_t *data)
      at the moment but may wish to revisit.  */
   if (intoffset % BITS_PER_WORD != 0)
     mode = smallest_int_mode_for_size (BITS_PER_WORD
-                                      - intoffset % BITS_PER_WORD);
+                                      - intoffset % BITS_PER_WORD).require ();
   else
     mode = word_mode;
 
index f60d1ac9876fc04a6f36717a93815d32d4063f73..22778361da13b26e7d9b1225df767145f088be9a 100644 (file)
@@ -138,7 +138,8 @@ tree
 get_gcov_type (void)
 {
   scalar_int_mode mode
-    = smallest_int_mode_for_size (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32);
+    = smallest_int_mode_for_size
+      (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32).require ();
   return lang_hooks.types.type_for_mode (mode, false);
 }
 
@@ -147,7 +148,7 @@ get_gcov_type (void)
 static tree
 get_gcov_unsigned_t (void)
 {
-  scalar_int_mode mode = smallest_int_mode_for_size (32);
+  scalar_int_mode mode = smallest_int_mode_for_size (32).require ();
   return lang_hooks.types.type_for_mode (mode, true);
 }
 \f
index 1596da91da08cc2e014a36ad1711ff908c47ef93..c3feff06f864939a1936596260800ba4233488a3 100644 (file)
@@ -1737,7 +1737,8 @@ find_shift_sequence (poly_int64 access_size,
   if (store_info->const_rhs
       && known_le (access_size, GET_MODE_SIZE (MAX_MODE_INT)))
     {
-      auto new_mode = smallest_int_mode_for_size (access_size * BITS_PER_UNIT);
+      auto new_mode = smallest_int_mode_for_size
+       (access_size * BITS_PER_UNIT).require ();
       auto byte = subreg_lowpart_offset (new_mode, store_mode);
       rtx ret
        = simplify_subreg (new_mode, store_info->const_rhs, store_mode, byte);
index 2ca93e30e8f2a2298753435118149f983683a1d4..4498f9f38a87f1f37f08709ea9b696951b4a5211 100644 (file)
@@ -972,7 +972,8 @@ store_integral_bit_field (rtx op0, opt_scalar_int_mode op0_mode,
         objects are meant to be handled before calling this function.  */
       fixed_size_mode value_mode = as_a <fixed_size_mode> (GET_MODE (value));
       if (value_mode == VOIDmode)
-       value_mode = smallest_int_mode_for_size (nwords * BITS_PER_WORD);
+       value_mode
+         = smallest_int_mode_for_size (nwords * BITS_PER_WORD).require ();
 
       last = get_last_insn ();
       for (int i = 0; i < nwords; i++)
index 2089c2b86a98ad09a82257858aac22b7f6d8cfee..8d17a5a39b4bd767f2c59048993df8060802682c 100644 (file)
@@ -596,7 +596,7 @@ convert_mode_scalar (rtx to, rtx from, int unsignedp)
   if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
     {
       scalar_int_mode full_mode
-       = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode));
+       = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode)).require ();
 
       gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
                  != CODE_FOR_nothing);
@@ -611,7 +611,7 @@ convert_mode_scalar (rtx to, rtx from, int unsignedp)
     {
       rtx new_from;
       scalar_int_mode full_mode
-       = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode));
+       = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode)).require ();
       convert_optab ctab = unsignedp ? zext_optab : sext_optab;
       enum insn_code icode;
 
@@ -1492,7 +1492,7 @@ op_by_pieces_d::smallest_fixed_size_mode_for_size (unsigned int size)
          }
     }
 
-  return smallest_int_mode_for_size (size * BITS_PER_UNIT);
+  return smallest_int_mode_for_size (size * BITS_PER_UNIT).require ();
 }
 
 /* This function contains the main loop used for expanding a block
@@ -2385,10 +2385,10 @@ emit_block_move_via_oriented_loop (rtx x, rtx y, rtx size,
   if (mode != GET_MODE (y_addr))
     {
       scalar_int_mode xmode
-       = smallest_int_mode_for_size (GET_MODE_BITSIZE (mode));
+       = smallest_int_mode_for_size (GET_MODE_BITSIZE (mode)).require ();
       scalar_int_mode ymode
        = smallest_int_mode_for_size (GET_MODE_BITSIZE
-                                     (GET_MODE (y_addr)));
+                                     (GET_MODE (y_addr))).require ();
       if (GET_MODE_BITSIZE (xmode) < GET_MODE_BITSIZE (ymode))
        mode = ymode;
       else
@@ -3667,7 +3667,7 @@ copy_blkmode_to_reg (machine_mode mode_in, tree src)
   n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
   dst_words = XALLOCAVEC (rtx, n_regs);
   bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
-  min_mode = smallest_int_mode_for_size (bitsize);
+  min_mode = smallest_int_mode_for_size (bitsize).require ();
 
   /* Copy the structure BITSIZE bits at a time.  */
   for (bitpos = 0, xbitpos = padding_correction;
@@ -8205,7 +8205,8 @@ store_field (rtx target, poly_int64 bitsize, poly_int64 bitpos,
          HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
          machine_mode temp_mode = GET_MODE (temp);
          if (temp_mode == BLKmode || temp_mode == VOIDmode)
-           temp_mode = smallest_int_mode_for_size (size * BITS_PER_UNIT);
+           temp_mode
+             = smallest_int_mode_for_size (size * BITS_PER_UNIT).require ();
          rtx temp_target = gen_reg_rtx (temp_mode);
          emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
          temp = temp_target;
@@ -8279,7 +8280,7 @@ store_field (rtx target, poly_int64 bitsize, poly_int64 bitpos,
         word size, we need to load the value (see again store_bit_field).  */
       if (GET_MODE (temp) == BLKmode && known_le (bitsize, BITS_PER_WORD))
        {
-         temp_mode = smallest_int_mode_for_size (bitsize);
+         temp_mode = smallest_int_mode_for_size (bitsize).require ();
          temp = extract_bit_field (temp, bitsize, 0, 1, NULL_RTX, temp_mode,
                                    temp_mode, false, NULL);
        }
index 966594a52ed33ea50ee87c2ddf9fb3a4961d062a..a96e61e527c076e6d6cbb8d1bcf80ea5af60cc55 100644 (file)
@@ -2824,7 +2824,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
       if (orig_precres == precres && precop <= BITS_PER_WORD)
        {
          int p = MAX (min_precision, precop);
-         scalar_int_mode m = smallest_int_mode_for_size (p);
+         scalar_int_mode m = smallest_int_mode_for_size (p).require ();
          tree optype = build_nonstandard_integer_type (GET_MODE_PRECISION (m),
                                                        uns0_p && uns1_p
                                                        && unsr_p);
@@ -2867,7 +2867,7 @@ expand_arith_overflow (enum tree_code code, gimple *stmt)
       if (orig_precres == precres)
        {
          int p = MAX (prec0, prec1);
-         scalar_int_mode m = smallest_int_mode_for_size (p);
+         scalar_int_mode m = smallest_int_mode_for_size (p).require ();
          tree optype = build_nonstandard_integer_type (GET_MODE_PRECISION (m),
                                                        uns0_p && uns1_p
                                                        && unsr_p);
index c31ec2f2ebc7c3ee2efbdb8aabb72616fe730bc0..4c2a8d943cf6928176eaafc121475ee31c9ad316 100644 (file)
@@ -905,15 +905,15 @@ decimal_float_mode_for_size (unsigned int size)
     (mode_for_size (size, MODE_DECIMAL_FLOAT, 0));
 }
 
-extern machine_mode smallest_mode_for_size (poly_uint64, enum mode_class);
+extern opt_machine_mode smallest_mode_for_size (poly_uint64, enum mode_class);
 
-/* Find the narrowest integer mode that contains at least SIZE bits.
-   Such a mode must exist.  */
+/* Find the narrowest integer mode that contains at least SIZE bits,
+   if such a mode exists.  */
 
-inline scalar_int_mode
+inline opt_scalar_int_mode
 smallest_int_mode_for_size (poly_uint64 size)
 {
-  return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
+  return dyn_cast <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
 }
 
 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
index 5149de57468d411e32f35a2d3d4a0989455bd588..c3134d6a2cee34f091c339efba947e841dabf6fd 100644 (file)
@@ -205,6 +205,7 @@ get_best_extraction_insn (extraction_insn *insn,
                          machine_mode field_mode)
 {
   opt_scalar_int_mode mode_iter;
+
   FOR_EACH_MODE_FROM (mode_iter, smallest_int_mode_for_size (struct_bits))
     {
       scalar_int_mode mode = mode_iter.require ();
index 185c5b1a70535a65e78d7709c058f31da9a54be3..ded9cc3d947a860de0bdf869d52abc219de5bcb6 100644 (file)
@@ -2551,7 +2551,8 @@ expand_twoval_binop_libfunc (optab binoptab, rtx op0, rtx op1,
 
   /* The value returned by the library function will have twice as
      many bits as the nominal MODE.  */
-  libval_mode = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode));
+  libval_mode
+    = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode)).require ();
   start_sequence ();
   libval = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST,
                                    libval_mode,
index 0ff8bd1171e11236bd357a0ff44c07c06f248fc2..2e6b826509ab35eca1b02e917bbb2f00854f4ad2 100644 (file)
@@ -339,9 +339,9 @@ mode_for_size_tree (const_tree size, enum mode_class mclass, int limit)
 }
 
 /* Return the narrowest mode of class MCLASS that contains at least
-   SIZE bits.  Abort if no such mode exists.  */
+   SIZE bits, if such a mode exists.  */
 
-machine_mode
+opt_machine_mode
 smallest_mode_for_size (poly_uint64 size, enum mode_class mclass)
 {
   machine_mode mode = VOIDmode;
@@ -353,7 +353,8 @@ smallest_mode_for_size (poly_uint64 size, enum mode_class mclass)
     if (known_ge (GET_MODE_PRECISION (mode), size))
       break;
 
-  gcc_assert (mode != VOIDmode);
+  if (mode == VOIDmode)
+    return opt_machine_mode ();
 
   if (mclass == MODE_INT || mclass == MODE_PARTIAL_INT)
     for (i = 0; i < NUM_INT_N_ENTS; i ++)
@@ -2460,7 +2461,7 @@ layout_type (tree type)
     case ENUMERAL_TYPE:
       {
        scalar_int_mode mode
-         = smallest_int_mode_for_size (TYPE_PRECISION (type));
+         = smallest_int_mode_for_size (TYPE_PRECISION (type)).require ();
        SET_TYPE_MODE (type, mode);
        TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode));
        /* Don't set TYPE_PRECISION here, as it may be set by a bitfield.  */
@@ -2936,7 +2937,8 @@ initialize_sizetypes (void)
 
   bprecision
     = MIN (precision + LOG2_BITS_PER_UNIT + 1, MAX_FIXED_MODE_SIZE);
-  bprecision = GET_MODE_PRECISION (smallest_int_mode_for_size (bprecision));
+  bprecision
+    = GET_MODE_PRECISION (smallest_int_mode_for_size (bprecision).require ());
   if (bprecision > HOST_BITS_PER_DOUBLE_INT)
     bprecision = HOST_BITS_PER_DOUBLE_INT;
 
@@ -2951,14 +2953,14 @@ initialize_sizetypes (void)
   TYPE_UNSIGNED (bitsizetype) = 1;
 
   /* Now layout both types manually.  */
-  scalar_int_mode mode = smallest_int_mode_for_size (precision);
+  scalar_int_mode mode = smallest_int_mode_for_size (precision).require ();
   SET_TYPE_MODE (sizetype, mode);
   SET_TYPE_ALIGN (sizetype, GET_MODE_ALIGNMENT (TYPE_MODE (sizetype)));
   TYPE_SIZE (sizetype) = bitsize_int (precision);
   TYPE_SIZE_UNIT (sizetype) = size_int (GET_MODE_SIZE (mode));
   set_min_and_max_values_for_integral_type (sizetype, precision, UNSIGNED);
 
-  mode = smallest_int_mode_for_size (bprecision);
+  mode = smallest_int_mode_for_size (bprecision).require ();
   SET_TYPE_MODE (bitsizetype, mode);
   SET_TYPE_ALIGN (bitsizetype, GET_MODE_ALIGNMENT (TYPE_MODE (bitsizetype)));
   TYPE_SIZE (bitsizetype) = bitsize_int (bprecision);
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr115495.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr115495.c
new file mode 100644 (file)
index 0000000..bbf4d72
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv_zvl256b -mabi=lp64d -O3" } */
+
+extern short a[];
+short b;
+int main() {
+  for (char c = 0; c < 18; c += 1)
+    a[c + 0] = b;
+}
index 6cef1ae30c19db81d1c7e764785a5d504ae626bf..213f069c440c6c3808bcf19bba74b0760eca40ed 100644 (file)
@@ -1426,7 +1426,7 @@ canonicalize_loop_ivs (class loop *loop, tree *nit, bool bump_in_latch)
       precision = TYPE_PRECISION (type);
     }
 
-  scalar_int_mode mode = smallest_int_mode_for_size (precision);
+  scalar_int_mode mode = smallest_int_mode_for_size (precision).require ();
   precision = GET_MODE_PRECISION (mode);
   type = build_nonstandard_integer_type (precision, unsigned_p);