Richard Biener <richard.guent...@gmail.com> writes:
> On Wed, Aug 21, 2024 at 8:37 AM Robin Dapp <rdapp....@gmail.com> wrote:
>>
>> Hi,
>>
>> in get_best_extraction_insn we use smallest_int_mode_for_size with
>> struct_bits as size argument.  In PR115495 struct_bits = 256 and we
>> don't have a mode for that.  This patch just bails for such cases.
>>
>> This does not happen on the current trunk anymore (so the test passes
>> unpatched) but we've seen it internally.  Does it still make sense
>> to install it (and backport to 14)?
>>
>> Bootstrapped and regtested on x86 and aarch64.  Regtested on rv64gcv.
>>
>> Regards
>>  Robin
>>
>>         PR middle-end/115495
>>
>> gcc/ChangeLog:
>>
>>         * optabs-query.cc (get_best_extraction_insn): Return if
>>         smallest_int_mode_for_size might not find a mode.
>>
>> gcc/testsuite/ChangeLog:
>>
>>         * gcc.target/riscv/rvv/autovec/pr115495.c: New test.
>> ---
>>  gcc/optabs-query.cc                                   | 4 ++++
>>  gcc/testsuite/gcc.target/riscv/rvv/autovec/pr115495.c | 9 +++++++++
>>  2 files changed, 13 insertions(+)
>>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr115495.c
>>
>> diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc
>> index 93c1d7b8485..dc2690e720f 100644
>> --- a/gcc/optabs-query.cc
>> +++ b/gcc/optabs-query.cc
>> @@ -208,6 +208,10 @@ get_best_extraction_insn (extraction_insn *insn,
>>                           machine_mode field_mode)
>>  {
>>    opt_scalar_int_mode mode_iter;
>> +
>> +  if (maybe_gt (struct_bits, GET_MODE_PRECISION (MAX_MODE_INT)))
>> +    return false;
>> +
>>    FOR_EACH_MODE_FROM (mode_iter, smallest_int_mode_for_size (struct_bits))
>
> I think we instead should change this iteration to use FOR_EACH_MODE_IN_CLASS
> (like smallest_mode_for_size does) and skip to small modes?

I can't remember whether we rely on the int_n stuff here.  (If we do though,
it'd only be in a limited way, since the loop only tries int_n for the first
size.)

An alternative would be to make smallest_int_mode_for_size return an
optional mode, which arguably it should be doing anyway.

Thanks,
Richard

>
>>      {
>>        scalar_int_mode mode = mode_iter.require ();
>> 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
>> index 00000000000..bbf4d720f63
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr115495.c
>> @@ -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;
>> +}
>> --
>> 2.46.0
>>

Reply via email to