From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2F1B33858C39; Tue, 7 Mar 2023 13:58:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F1B33858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678197514; bh=7XNwryGnG3hx9EZFCKkM/KmtlUsLvrgD1tnSSKXdsIM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vDa+r65z7/AcJ9hxXtT52K3SAvojL4VVplMZS1+S+cycI/2tBtmmGq/6xMyFPeeVP WtTY+jzVCaokot62QtxOWP1d07KENR309ey4aoy19zAGa0VRv5W5kCVQAGMqbfZN2A u7wSnGRLK3QoTecF20R7d9yDY+L2EdzLM3+gZElI= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109008] [13 Regression] Wrong code in scipy package since r13-3926-gd4c2f1d376da6f Date: Tue, 07 Mar 2023 13:58:33 +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: 13.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109008 --- Comment #21 from Richard Biener --- So without messing with real.cc to try exposing 0.5ulp adjustments for GCC = 13 I'd simply do something like the following: diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index ff42b95de4f..1ae68503664 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -2214,7 +2214,26 @@ public: range_op_handler minus (MINUS_EXPR, type); if (!minus) return false; - return float_binary_op_range_finish (minus.fold_range (r, type, lhs, o= p2), + /* The forward operation is + lhs =3D r + op2 + where the result is +-0.5ulp of lhs before rounding. For the + reverse operation we need the lhs range before rounding, so + conservatively use nextafter on it. + ??? REAL_VALUE_TYPE could handle this more precisely if we + make sure to not round the inputs for the format before the + real_operation is carried out and when we can properly round + towards +-Inf for the lower/upper bounds. */ + frange wlhs (lhs); + if (!lhs.known_isnan ()) + { + REAL_VALUE_TYPE lhsl =3D lhs.lower_bound (); + frange_nextafter (TYPE_MODE (type), lhsl, dconstninf); + REAL_VALUE_TYPE lhsu =3D lhs.upper_bound (); + frange_nextafter (TYPE_MODE (type), lhsu, dconstinf); + wlhs.set (type, lhsl, lhsu); + wlhs.union_ (lhs); /* Copy NaN state. */ + } + return float_binary_op_range_finish (minus.fold_range (r, type, wlhs, op2), r, type, lhs); } virtual bool op2_range (frange &r, tree type,=