From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1AA443858039; Wed, 2 Feb 2022 13:50:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AA443858039 From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104334] [12 Regression] Ranger/dom miscompilation since r12-4694-gcb153222404e2e Date: Wed, 02 Feb 2022 13:50:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: lto, wrong-code X-Bugzilla-Severity: blocker X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2022 13:50:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104334 --- Comment #16 from Andrew Macleod --- (In reply to Jakub Jelinek from comment #13) > 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 =3D wi::sub (rh_ub, rh_lb, TYPE_SIGN (type), &ov_rh); > wide_int lh_range =3D wi::sub (lh_ub, lh_lb, TYPE_SIGN (type), &ov_lh); > - signop sign =3D TYPE_SIGN (type);; > + signop sign =3D 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 =3D=3D wi::OVF_NONE) > + if (wi::min_precision (4, sign) <=3D wi::get_precision (rh_range) > + && ov_rh =3D=3D 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 =3D=3D wi::OVF_NONE) > + else if (wi::min_precision (4, sign) <=3D wi::get_precision (lh_range) > + && ov_lh =3D=3D 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. yes, I think if the precision is small, simply don't try to break it up. We special case 1 bit all over the place for this reason.=20 Like you did, or simply this way. Either amounts to the same thing and wi_f= old get called on the range. diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 19bdf30911a..a88fb7b8932 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -149,6 +149,11 @@ range_operator::wi_fold_in_parts (irange &r, tree type, wide_int rh_range =3D wi::sub (rh_ub, rh_lb, TYPE_SIGN (type), &ov_rh); wide_int lh_range =3D wi::sub (lh_ub, lh_lb, TYPE_SIGN (type), &ov_lh); signop sign =3D TYPE_SIGN (type);; + + // If precision of the type is too small, don't bother trying to split it up. + if (TYPE_PRECISION (type) <=3D 3) + wi_fold (r, type, lh_lb, lh_ub, rh_lb, rh_ub); + else // 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)=