From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 62FE43858C20; Tue, 10 Jan 2023 14:14:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62FE43858C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673360089; bh=A6Q29+5KsylLz3TGrc6XbDxrjDOUTveOYfNOzJ/qyw0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fI3g8nIB73L0jrHZwzMCkT7uIK7NFccdhr7CoEQHGHyAqBToY6cCVwKRBDqalFCVG KRwlq2XD2C8Dj+lhvJGTDyfQ2vShvK6ICinHj/PxMjEKVp1KizSeTdDSoBc+pp7aoX cfZjUW65xqAHwU3fOEgOEAUOaddaf1C88eXEsL/U= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107608] [13 Regression] Failure on fold-overflow-1.c and pr95115.c Date: Tue, 10 Jan 2023 14:14:47 +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: missed-optimization, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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=3D107608 --- Comment #20 from Jakub Jelinek --- (In reply to Aldy Hernandez from comment #16) > Created attachment 54224 [details] > untested patch >=20 > Perhaps this would work. It solves the testcase, though I think we should > probably audit the operators that don't use the generic > range_operator_float::fold_range to make sure they're not doing anything > silly. Even as a workaround this seems to be quite a big hammer. If we want to preserve overflow traps, all we need to arrange is that if non-inf operands result in singleton inf we don't treat that result as singleton. Now, what result one gets in different rounding modes depends on the roundi= ng mode, in round to nearest it should be +-inf, in round to zero +-max, in round to +inf +inf or -max and in round to -inf -inf or +max. But right now GCC doe= sn't handle the separate rounding modes, it just differentiates between -fno-rounding-math where we assume round to nearest and -frounding-math whe= re we should consider any rounding mode. I think for -frounding-math we already don't treat such results as singleto= ns, as we end up with ranges like [+max, +inf] or [-inf, -max]. So, one possible way for -fno-rounding-math -ftrapping-math could be instea= d of making the result VARYING just extend the range by one ulp towards 0, i.e. instead= of singleton [+inf, +inf] use [+max, +inf] etc. Another would be to add some bool flag to frange which would say this is ne= ver a singleton and just take that flag into account, though perhaps it is too risky right now. As for invalid exceptions, that implies result maybe or known NAN, but we d= on't treat maybe or known NAN as singletons, do we? After all, there isn't just a sin= gle NAN and we don't know which one the result is. That doesn't mean we handle= all cases right, say if a result of something is only used in __builtin_isnan or similar, we can still happily optimized it away. As for underflow exceptions, I've tried to construct a testcase but seems we didn't care already in older GCC versions. Say for float foo (void) { float x =3D __FLT_MIN__; return x * x; } without -frounding-math we already optimized it in ccp1 in GCC 12 and older, with -frounding-math again we should be fine because the result isn't singleton. Again with the problem that if the result is in the end used in some compar= ison or test that will not care about details, like if (__builtin_fabsf (foo ())= < 1.0f) then again we optimize away the trapping operation and we didn't previously. And inexact exceptions I think is something we just basically didn't care at all before, those can happen pretty much all the time.=