public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.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:33:08 +0000 [thread overview] Message-ID: <bug-107608-4-T6vI9rTtlA@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107608-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107608 --- Comment #22 from Aldy Hernandez <aldyh at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #20) > (In reply to Aldy Hernandez from comment #16) > > Created attachment 54224 [details] > > untested patch > > > > 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 > rounding 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 > doesn't handle the separate rounding modes, it just differentiates between > -fno-rounding-math where we assume round to nearest and -frounding-math > where we should consider any rounding mode. Note that we currently can't represent +-inf or +-max, as we only have two endpoints. So that would just be represented as VARYING. > I think for -frounding-math we already don't treat such results as > singletons, as we > end up with ranges like [+max, +inf] or [-inf, -max]. > So, one possible way for -fno-rounding-math -ftrapping-math could be instead > 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. This seems reasonable. So instead of set_varying(), we could do [+max, +inf], etc. > Another would be to add some bool flag to frange which would say this is > never a singleton and just take that flag into account, though perhaps it is > too risky right now. That seems easy to get wrong, especially this late in the cycle. > > As for invalid exceptions, that implies result maybe or known NAN, but we > don't treat > maybe or known NAN as singletons, do we? After all, there isn't just a > single 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. NANs are never singletons, and maybe_nans either. See frange::singleton_p: if (m_kind == VR_RANGE && real_identical (&m_min, &m_max)) { // Return false for any singleton that may be a NAN. if (HONOR_NANS (m_type) && maybe_isnan ()) return false; ... } Also, all the conditional operators in frange fail to fold if maybe_isnan. The only things we fold for sure are: a) One operand is a known NAN. b) None of the operands can ever be a NAN *and* we know the answer to the conditional. For example, foperator_gt::fold_range: ... ... if (op1.known_isnan () || op2.known_isnan ()) r = range_false (type); else if (!maybe_isnan (op1, op2)) { if (real_compare (LE_EXPR, &op1.upper_bound (), &op2.lower_bound ())) r = range_true (type); else if (!real_compare (LE_EXPR, &op1.lower_bound (), &op2.upper_bound ())) r = range_false (type); else r = range_true_and_false (type); } so... we're pretty careful about NOT folding relationals that have the possibility of a NAN, and a singleton is only for a known range without a NAN.
next prev parent reply other threads:[~2023-01-10 14:33 UTC|newest] Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-10 9:47 [Bug tree-optimization/107608] New: [13 Regression] Failure on fold-overflow-1.c jakub at gcc dot gnu.org 2022-11-10 9:49 ` [Bug tree-optimization/107608] " jakub at gcc dot gnu.org 2022-11-10 13:47 ` rguenth at gcc dot gnu.org 2022-11-10 18:13 ` pinskia at gcc dot gnu.org 2022-11-11 7:18 ` pinskia at gcc dot gnu.org 2022-11-13 6:30 ` [Bug tree-optimization/107608] [13 Regression] Failure on fold-overflow-1.c and pr95115.c xry111 at gcc dot gnu.org 2022-11-28 10:06 ` rguenth at gcc dot gnu.org 2022-12-05 13:22 ` aldyh at gcc dot gnu.org 2022-12-05 15:14 ` rguenth at gcc dot gnu.org 2022-12-05 16:30 ` aldyh at gcc dot gnu.org 2022-12-16 13:20 ` jakub at gcc dot gnu.org 2022-12-16 13:32 ` rguenth at gcc dot gnu.org 2023-01-09 15:18 ` aldyh at gcc dot gnu.org 2023-01-10 8:56 ` rguenth at gcc dot gnu.org 2023-01-10 8:58 ` rguenth at gcc dot gnu.org 2023-01-10 10:20 ` aldyh at gcc dot gnu.org 2023-01-10 10:25 ` aldyh at gcc dot gnu.org 2023-01-10 11:00 ` rguenth at gcc dot gnu.org 2023-01-10 11:09 ` jakub at gcc dot gnu.org 2023-01-10 12:08 ` rguenther at suse dot de 2023-01-10 14:14 ` jakub at gcc dot gnu.org 2023-01-10 14:25 ` amacleod at redhat dot com 2023-01-10 14:33 ` aldyh at gcc dot gnu.org [this message] 2023-01-10 14:39 ` jakub at gcc dot gnu.org 2023-01-10 14:40 ` aldyh at gcc dot gnu.org 2023-01-10 14:42 ` jakub at gcc dot gnu.org 2023-01-12 11:42 ` aldyh at gcc dot gnu.org 2023-01-12 12:03 ` jakub at gcc dot gnu.org 2023-01-12 12:26 ` xry111 at gcc dot gnu.org 2023-01-13 13:19 ` aldyh at gcc dot gnu.org 2023-01-13 13:25 ` aldyh at gcc dot gnu.org 2023-01-15 15:43 ` cvs-commit at gcc dot gnu.org 2023-01-16 21:38 ` romain.geissler at amadeus dot com 2023-01-16 21:46 ` jakub at gcc dot gnu.org 2023-01-16 21:55 ` romain.geissler at amadeus dot com 2023-01-16 21:58 ` fw at gcc dot gnu.org 2023-01-18 12:26 ` aldyh at gcc dot gnu.org 2023-01-18 12:54 ` jakub at gcc dot gnu.org 2023-01-18 12:56 ` aldyh at gcc dot gnu.org 2023-01-18 13:00 ` rguenth at gcc dot gnu.org 2023-01-18 13:03 ` rguenth at gcc dot gnu.org 2023-01-18 13:05 ` rguenth at gcc dot gnu.org 2023-01-19 1:15 ` xry111 at gcc dot gnu.org 2023-01-19 7:17 ` rguenther at suse dot de 2023-01-26 14:29 ` xry111 at gcc dot gnu.org 2023-01-27 7:35 ` rguenth at gcc dot gnu.org 2023-01-27 7:59 ` xry111 at gcc dot gnu.org 2023-01-27 9:53 ` rguenther at suse dot de 2023-01-27 10:02 ` xry111 at gcc dot gnu.org 2023-01-27 10:13 ` jakub at gcc dot gnu.org 2023-01-27 11:30 ` rguenther at suse dot de
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107608-4-T6vI9rTtlA@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).