https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111720

--- Comment #17 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
(In reply to Richard Biener from comment #16)
> The issue is that we cannot CSE a VLA typed "load" (whatever that is) to a
> constnant.
> 
>     char arr[] = {1, 2, 7, 1, 3, 4, 5, 3, 1
>     , 0, 1, 2, 4, 4, 9, 9, 1, 2, 7, 1, 3, 4, 5, 3, 
>     1, 0, 1, 2, 4, 4, 9, 9};
>     char m = 1;
> 
>     svint8_t varr = *(svint8_t*)arr;
> 
> we don't know what portion of 'arr' this accesses.  The relevant bit in
> vn_reference_lookup_3 would be
> 
>   /* 3) Assignment from a constant.  We can use folds native encode/interpret
>      routines to extract the assigned bits.  */
>   else if (known_eq (ref->size, maxsize)
>            && is_gimple_reg_type (vr->type)
>            && !reverse_storage_order_for_component_p (vr->operands)
>            && !contains_storage_order_barrier_p (vr->operands)
>            && gimple_assign_single_p (def_stmt)
>            && CHAR_BIT == 8
>            && BITS_PER_UNIT == 8
>            && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN
>            /* native_encode and native_decode operate on arrays of bytes
>               and so fundamentally need a compile-time size and offset.  */
>            && maxsize.is_constant (&maxsizei)
>            && offset.is_constant (&offseti)
>            && (is_gimple_min_invariant (gimple_assign_rhs1 (def_stmt))
>                || (TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME
>                    && is_gimple_min_invariant (SSA_VAL (gimple_assign_rhs1
> (def_
> 
> and we fail at maxsize.is_constant (&maxsizei), that's the actual size of
> the load.  Maybe there's constraints that are target specific and not
> encoded in poly-int that could be used here, but I don't really know.
> 
> So yes, pieces of the compiler are defensive about VLA accesses and
> they probably have to be.
> 
> In particular this part of VN doesn't try to use undefinedness (the access
> exceeds the size of 'arr') to limit things - but in the end we'd still
> need to construct a VLA typed constant and I have no idea how to do that.
> 
> Maybe Richard has an idea.
> 
> Note this has nothing to do about whether we have a CLOBBER or not.  You
> can "disable" those with -fstack-reuse=none and that doesn't make a
> difference.

Thanks Richi.

But how about this case in RVV:

https://godbolt.org/z/sMYor3arP

Use --param=riscv-autovec-preference=fixed-vlmax will set the mode as a known
size.  This code still have redundant stack transferring load/store.

Reply via email to