From: Joseph Myers <joseph@codesourcery.com>
To: Richard Biener <rguenther@suse.de>
Cc: <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix PR66313
Date: Thu, 29 Oct 2015 18:36:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.10.1510291825160.10299@digraph.polyomino.org.uk> (raw)
In-Reply-To: <alpine.LSU.2.11.1510291036320.28064@zhemvz.fhfr.qr>
On Thu, 29 Oct 2015, Richard Biener wrote:
> We still regress gcc.dg/tree-ssa/tailrecursion-6.c with it though.
> There we have
>
> int
> foo (int a)
> {
> if (a)
> return a * (2 * (foo (a - 1))) + a + 1;
> else
> return 0;
> }
>
> and tailrecursion detection requires the expression to be
> in the form (2 * (foo (a - 1)) + 1) * a + 1 but folding
> can't see that (2 * (foo (a - 1)) + 1) might not be INT_MIN
> when a is -1. Well, I can't trivially either, maybe its
> just because of the recursion or maybe it's because here
> we are sure that C in C * A is odd (2 * sth + 1) or
> simply because we know that C in (B + C)*A is positive
> and non-zero?
>
> But I guess for the isolated view of the
> a * (2 * X) + a expression we can't factor it using signed
> arithmetic because of the a == 0 case as then the sum
> might trivially overflow (of course here a is not zero
> because of the guard...)
In that isolated view, a transformation a * (2 * X) + a ->
a * (2 * X + 1) is always safe (because Y + 1 only overflows when Y is
INT_MAX, which is odd, so adding 1 to 2 * X cannot overflow). That could
be generalized to cover a * (C * X) + a * D (for C constant, D positive
constant) if (INT_MAX % C) >= D, and similarly for negative constants.
I've no idea if such transformations are useful outside this test.
[Safe = not introducing overflows, but might lose them which is a
consideration for sanitization.]
--
Joseph S. Myers
joseph@codesourcery.com
next prev parent reply other threads:[~2015-10-29 18:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 14:28 Richard Biener
2015-10-27 17:38 ` Joseph Myers
2015-10-29 9:49 ` Richard Biener
2015-10-29 18:36 ` Joseph Myers [this message]
2017-05-31 14:09 Richard Biener
2017-06-13 9:57 ` Richard Sandiford
2017-06-13 10:25 ` Richard Biener
2017-06-13 11:23 ` Richard Sandiford
2017-06-13 11:28 ` Bin.Cheng
2017-06-13 11:49 ` Richard Biener
2017-06-13 11:48 ` Richard Biener
2017-06-13 11:56 ` Bin.Cheng
2017-06-13 12:03 ` Richard Biener
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=alpine.DEB.2.10.1510291825160.10299@digraph.polyomino.org.uk \
--to=joseph@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/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: link
Be 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).