From: Richard Sandiford <rdsandiford@googlemail.com>
To: Mike Stump <mikestump@comcast.net>
Cc: gcc-patches Patches <gcc-patches@gcc.gnu.org>
Subject: Re: remove wrong code in immed_double_const
Date: Thu, 22 Mar 2012 10:16:00 -0000 [thread overview]
Message-ID: <g4iphxeya9.fsf@richards-thinkpad.stglab.manchester.uk.ibm.com> (raw)
In-Reply-To: <DF6339D4-BFF6-45FA-A5E0-8141F0BD4199@comcast.net> (Mike Stump's message of "Wed, 21 Mar 2012 14:35:40 -0700")
Mike Stump <mikestump@comcast.net> writes:
>> This is changing the real case, where sign extension doesn't make
>> much sense.
>
> I'm not sure I followed. Do you want me to remove the change for the
> second case, leave it as it, or something else? I've left it as I had
> modified it.
Sorry, meant we should leave the svn version as it is. The new docs
(rightly) only mention sign-extension for integer modes, so the comment
about it not mattering for FP modes is still correct. (In principle
I'd prefer to replace it with an assert, but that's a separate change.
Nothing we're doing here should change whether the FP path gets executed.)
>> simplify_const_unary_operation needs to check for overflow
>> when handling 2-HWI arithmetic, since we can no longer assume
>> that the result is <= 2 HWIs in size. E.g.:
>>
>> case NEG:
>> neg_double (l1, h1, &lv, &hv);
>> break;
>>
>> should probably be:
>>
>> case NEG:
>> if (neg_double (l1, h1, &lv, &hv))
>> gcc_assert (GET_MODE_BITSIZE (mode) <= 2 * HOST_WIDE_INT);
>> break;
>
> Are you talking about the block of code inside:
>
> /* We can do some operations on integer CONST_DOUBLEs. Also allow
> for a DImode operation on a CONST_INT. */
> else if (GET_MODE (op) == VOIDmode
> && width <= HOST_BITS_PER_WIDE_INT * 2
>
> ?
Heh. it seems so :-) Never mind that bit then.
> diff --git a/gcc/explow.c b/gcc/explow.c
> index 2fae1a1..c94ad25 100644
> --- a/gcc/explow.c
> +++ b/gcc/explow.c
> @@ -73,14 +73,20 @@ trunc_int_for_mode (HOST_WIDE_INT c, enum machine_mode mode)
> return c;
> }
>
> -/* Return an rtx for the sum of X and the integer C. */
> +/* Return an rtx for the sum of X and the integer C, given that X has
> + mode MODE. This routine should be used instead of plus_constant
> + when they want to ensure that addition happens in a particular
> + mode, which is necessary when x can be a VOIDmode CONST_INT or
> + CONST_DOUBLE and the width of the constant is smaller than the
> + width of the expression. */
I think this should be s/is smaller than/is different from/.
We're in trouble whenever the width of the HWIs is different
from the width of the constant they represent.
> @@ -103,11 +123,16 @@ plus_constant (rtx x, HOST_WIDE_INT c)
> unsigned HOST_WIDE_INT l1 = CONST_DOUBLE_LOW (x);
> HOST_WIDE_INT h1 = CONST_DOUBLE_HIGH (x);
> unsigned HOST_WIDE_INT l2 = c;
> - HOST_WIDE_INT h2 = c < 0 ? ~0 : 0;
> + HOST_WIDE_INT h2 = c < 0 ? -1 : 0;
> unsigned HOST_WIDE_INT lv;
> HOST_WIDE_INT hv;
>
> - add_double (l1, h1, l2, h2, &lv, &hv);
> + if (add_double_with_sign (l1, h1, l2, h2, &lv, &hv, false))
> + if (GET_MODE_BITSIZE (mode) > 2*HOST_BITS_PER_WIDE_INT)
> + /* Sorry, we have no way to represent overflows this
> + wide. To fix, add constant support wider than
> + CONST_DOUBLE. */
> + gcc_assert (0);
Should be:
if (add_double_with_sign (l1, h1, l2, h2, &lv, &hv, false))
/* Sorry, we have no way to represent overflows this
wide. To fix, add constant support wider than
CONST_DOUBLE. */
gcc_assert (GET_MODE_BITSIZE (mode) > 2 * HOST_BITS_PER_WIDE_INT)
(note spacing).
> @@ -121,8 +146,8 @@ plus_constant (rtx x, HOST_WIDE_INT c)
> {
> tem
> = force_const_mem (GET_MODE (x),
> - plus_constant (get_pool_constant (XEXP (x, 0)),
> - c));
> + plus_constant_mode (mode, get_pool_constant (XEXP (x, 0)),
> + c));
> if (memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
> return tem;
> }
Nitlet, but line is wider than 80 chars. Probably easiest fix is:
tem = plus_constant_mode (mode, get_pool_constant (XEXP (x, 0)), c);
tem = force_const_mem (GET_MODE (x), tem);
> diff --git a/gcc/expmed.c b/gcc/expmed.c
> index 3507dad..2361b7e 100644
> --- a/gcc/expmed.c
> +++ b/gcc/expmed.c
> @@ -3122,9 +3122,11 @@ expand_mult (enum machine_mode mode, rtx op0, rtx op1, rtx target,
> {
> int shift = floor_log2 (CONST_DOUBLE_HIGH (op1))
> + HOST_BITS_PER_WIDE_INT;
> - return expand_shift (LSHIFT_EXPR, mode, op0,
> - build_int_cst (NULL_TREE, shift),
> - target, unsignedp);
> + if (shift < 2*HOST_BITS_PER_WIDE_INT-1
> + || GET_MODE_BITSIZE (mode) <= 2*HOST_BITS_PER_WIDE_INT)
Missing spaces around binary operators.
> @@ -1219,15 +1220,10 @@ simplify_const_unary_operation (enum rtx_code code, enum machine_mode mode,
> else
> lv = CONST_DOUBLE_LOW (op), hv = CONST_DOUBLE_HIGH (op);
>
> - if (op_mode == VOIDmode)
> - {
> - /* We don't know how to interpret negative-looking numbers in
> - this case, so don't try to fold those. */
> - if (hv < 0)
> - return 0;
> - }
> - else if (GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT * 2)
> - ;
> + if (op_mode == VOIDmode
> + || GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT * 2)
> + /* We should never get a negative number. */
> + gcc_assert (hv >= 0);
> else
> hv = 0, lv &= GET_MODE_MASK (op_mode);
>
Sorry, with this bit, I meant that the current svn code is correct
for GET_MODE_BITSIZE (op_mode) == HOST_BITS_PER_WIDE_INT * 2.
In that case, hv < 0 can just mean that we have a uint128_t
(or whatever) whose high bit happens to be set. I think it
should be something like:
if (op_mode == VOIDmode
|| GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT * 2)
/* We should never get a negative number. */
gcc_assert (hv >= 0);
else if (GET_MODE_BITSIZE (op_mode) <= HOST_BITS_PER_WIDE_INT)
hv = 0, lv &= GET_MODE_MASK (op_mode);
> @@ -2214,7 +2210,9 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode,
> || GET_MODE_CLASS (GET_MODE (trueop1)) == MODE_INT)
> && GET_MODE (op0) == mode
> && CONST_DOUBLE_LOW (trueop1) == 0
> - && (val = exact_log2 (CONST_DOUBLE_HIGH (trueop1))) >= 0)
> + && (val = exact_log2 (CONST_DOUBLE_HIGH (trueop1))) >= 0
> + && (val < 2*HOST_BITS_PER_WIDE_INT-1
> + || GET_MODE_BITSIZE (mode) <= 2*HOST_BITS_PER_WIDE_INT))
> return simplify_gen_binary (ASHIFT, mode, op0,
> GEN_INT (val + HOST_BITS_PER_WIDE_INT));
>
Missing spaces around binary operators.
OK with those changes as far as the RTL optimisations go. I'm happy
with the rest too, but despite all this fuss, I can't approve the
immed_double_const change itself. Sounds like Richard G would be
willing though.
Richard
next prev parent reply other threads:[~2012-03-22 10:16 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-16 21:54 Mike Stump
2012-03-16 22:04 ` Steven Bosscher
2012-03-17 1:03 ` Mike Stump
2012-03-17 7:37 ` Richard Sandiford
2012-03-18 0:29 ` Mike Stump
2012-03-18 10:16 ` Richard Sandiford
2012-03-18 16:35 ` Mike Stump
2012-03-19 21:44 ` Richard Sandiford
2012-03-19 23:31 ` Mike Stump
2012-03-20 10:32 ` Richard Guenther
2012-03-20 10:50 ` Richard Sandiford
2012-03-20 11:38 ` Richard Guenther
2012-03-20 12:27 ` Richard Sandiford
2012-03-20 12:47 ` Richard Guenther
2012-03-20 13:55 ` Michael Matz
2012-03-20 20:44 ` Mike Stump
2012-03-21 13:47 ` Michael Matz
2012-03-21 17:01 ` Mike Stump
2012-03-22 13:16 ` Michael Matz
2012-03-22 18:37 ` Mike Stump
2012-03-20 19:41 ` Mike Stump
2012-03-21 1:01 ` Mike Stump
2012-03-21 13:17 ` Richard Sandiford
2012-03-21 21:36 ` Mike Stump
2012-03-22 10:16 ` Richard Sandiford [this message]
2012-03-22 10:25 ` Richard Sandiford
2012-03-22 20:28 ` Mike Stump
2012-03-23 10:02 ` Richard Sandiford
2012-03-26 19:14 ` Mike Stump
2012-03-26 20:04 ` Richard Sandiford
2012-03-26 23:57 ` Mike Stump
2012-04-04 21:07 ` Mike Stump
2012-03-22 14:12 ` Michael Matz
2012-03-22 18:55 ` Mike Stump
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=g4iphxeya9.fsf@richards-thinkpad.stglab.manchester.uk.ibm.com \
--to=rdsandiford@googlemail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=mikestump@comcast.net \
/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).