https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104334
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So, I think one way is to punt on these small precision types, like: --- range-op.cc.jj1 2022-01-13 22:29:15.345831749 +0100 +++ range-op.cc 2022-02-02 13:44:05.813637820 +0100 @@ -148,11 +148,13 @@ range_operator::wi_fold_in_parts (irange int_range_max tmp; wide_int rh_range = wi::sub (rh_ub, rh_lb, TYPE_SIGN (type), &ov_rh); wide_int lh_range = wi::sub (lh_ub, lh_lb, TYPE_SIGN (type), &ov_lh); - signop sign = TYPE_SIGN (type);; + signop sign = TYPE_SIGN (type); // If there are 2, 3, or 4 values in the RH range, do them separately. // Call wi_fold_in_parts to check the RH side. - if (wi::gt_p (rh_range, 0, sign) && wi::lt_p (rh_range, 4, sign) - && ov_rh == wi::OVF_NONE) + if (wi::min_precision (4, sign) <= wi::get_precision (rh_range) + && ov_rh == wi::OVF_NONE + && wi::gt_p (rh_range, 0, sign) + && wi::lt_p (rh_range, 4, sign)) { wi_fold_in_parts (r, type, lh_lb, lh_ub, rh_lb, rh_lb); if (wi::gt_p (rh_range, 1, sign)) @@ -170,8 +172,10 @@ range_operator::wi_fold_in_parts (irange } // Otherise check for 2, 3, or 4 values in the LH range and split them up. // The RH side has been checked, so no recursion needed. - else if (wi::gt_p (lh_range, 0, sign) && wi::lt_p (lh_range, 4, sign) - && ov_lh == wi::OVF_NONE) + else if (wi::min_precision (4, sign) <= wi::get_precision (lh_range) + && ov_lh == wi::OVF_NONE + && wi::gt_p (lh_range, 0, sign) + && wi::lt_p (lh_range, 4, sign)) { wi_fold (r, type, lh_lb, lh_lb, rh_lb, rh_ub); if (wi::gt_p (lh_range, 1, sign)) i.e. only optimize if 4 is representable in the given wide_int. The other option is to be extra careful.