https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108688
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think the bug is in the match.pd /* Simplify a bit extraction from a bit insertion for the cases with the inserted element fully covering the extraction or the insertion not touching the extraction. */ (simplify (BIT_FIELD_REF (bit_insert @0 @1 @ipos) @rsize @rpos) (with { unsigned HOST_WIDE_INT isize; if (INTEGRAL_TYPE_P (TREE_TYPE (@1))) isize = TYPE_PRECISION (TREE_TYPE (@1)); else isize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (@1))); } (switch (if (wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) && wi::leu_p (wi::to_wide (@rpos) + wi::to_wide (@rsize), wi::to_wide (@ipos) + isize)) (BIT_FIELD_REF @1 @rsize { wide_int_to_tree (bitsizetype, wi::to_wide (@rpos) - wi::to_wide (@ipos)); })) (if (wi::geu_p (wi::to_wide (@ipos), wi::to_wide (@rpos) + wi::to_wide (@rsize)) || wi::geu_p (wi::to_wide (@rpos), wi::to_wide (@ipos) + isize)) (BIT_FIELD_REF @0 @rsize @rpos))))) which folds _ifc__35 = BIT_INSERT_EXPR <_ifc__34, _2, 0 (7 bits)>; _ifc__31 = BIT_FIELD_REF <_ifc__35, 2, 0>; where 34/35 have unsigned char type, 31 signed:2 and 2 signed:7. So, in this case it wants to extract low 2 bits out of the 7 bits _2 which is invalid because _2 doesn't have mode precision. If it tried to extract 7 bits out of it, we have: (simplify (BIT_FIELD_REF @0 @1 integer_zerop) (if (tree_int_cst_equal (@1, TYPE_SIZE (TREE_TYPE (@0)))) (view_convert @0))) simplification but that one wouldn't trigger, because those signed:2 types have TYPE_SIZE 8 rather than 7, only TYPE_PRECISION of 7.