https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113576
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rsandifo at gcc dot gnu.org --- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Hongtao Liu from comment #8) > maybe > > diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc > index 1fd957288d4..6d321f9baef 100644 > --- a/gcc/fold-const.cc > +++ b/gcc/fold-const.cc > @@ -8035,6 +8035,9 @@ native_encode_vector_part (const_tree expr, unsigned > char *ptr, int len, > unsigned int extract_elts = extract_bytes * elts_per_byte; > for (unsigned int i = 0; i < extract_elts; ++i) > { > + /* Don't encode any bit beyond the range of the vector. */ > + if (first_elt + i > count) > + break; Hmm. I think that VECTOR_CST_ELT should have ICEd for out-of-bound element queries but it seems to make up elements for us here. Richard? But yes, we do unsigned int extract_elts = extract_bytes * elts_per_byte; and since native_encode_* and native_interpret_* operate on bytes we have difficulties dealing with bit-precision entities with padding. There's either the possibility to fail encoding when that happens or do something else. Note that RTL expansion will do case VECTOR_CST: { tree tmp = NULL_TREE; if (VECTOR_MODE_P (mode)) return const_vector_from_tree (exp); scalar_int_mode int_mode; if (is_int_mode (mode, &int_mode)) { tree type_for_mode = lang_hooks.types.type_for_mode (int_mode, 1); if (type_for_mode) tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR, type_for_mode, exp); which I think should always succeed (otherwise it falls back to expanding a CTOR). That means failing to encode/interpret might get into store_constructor which I think will zero a register destination and thus fill padding with zeros. So yeah, something like this looks OK, but I think instead of only testing against 'count' we should also test against TYPE_VECTOR_SUBPARTS (that might be variable, so with known_gt). Would be interesting to see whether this fixes the issue without the now installed patch.