public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ramana Radhakrishnan <ramana.gcc@googlemail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: will_schmidt@vnet.ibm.com,
	Segher Boessenkool <segher@kernel.crashing.org>,
		GCC Patches <gcc-patches@gcc.gnu.org>,
	David Edelsohn <dje.gcc@gmail.com>,
		Bill Schmidt <wschmidt@linux.vnet.ibm.com>
Subject: Re: [PATCH, rs6000] Fold vector absolutes in GIMPLE
Date: Wed, 31 May 2017 14:06:00 -0000	[thread overview]
Message-ID: <CAJA7tRY5hT_T9Y4qgBMP=VNeJUN-MbsKrg30bi5tDxY8O6S2XA@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc0fDTZFiNn163c_+rLU_TT6zoYCn5jec9719knZnSASYQ@mail.gmail.com>

On Wed, May 31, 2017 at 3:02 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Wed, May 31, 2017 at 3:56 PM, Will Schmidt <will_schmidt@vnet.ibm.com> wrote:
>> On Tue, 2017-05-30 at 09:00 +0200, Richard Biener wrote:
>>> On Mon, May 29, 2017 at 2:21 PM, Segher Boessenkool
>>> <segher@kernel.crashing.org> wrote:
>>> > On Mon, May 29, 2017 at 01:35:22PM +0200, Richard Biener wrote:
>>> >> >> What's the documented behavior for vec_abs with respect to an
>>> >> >argument
>>> >> >> of value INT_MIN?
>>> >> >
>>> >> >The documentation says:
>>> >> >
>>> >> >     "For integer vectors, the arithmetic is modular."
>>> >>
>>> >> This means that folding as ABS_EXPR is not safe for !TYPE_OVERFLOW_WRAPS
>>> >> Integral vector types.
>>> >
>>> > Is it still fine if TYPE_OVERFLOW_UNDEFINED?  So essentially always
>>> > except with -ftrapv?
>>>
>>> The docs say it needs to wrap so the correct check is TYPE_OVERFLOW_WRAPS.
>>> It's not fine with TYPE_OVERFLOW_UNDEFINED as we will conclude the result
>>> can never be INT_MIN while the spec says it can.
>>
>> Ok, thanks for the review.
>>
>> So it looks like I should bail with something like:
>>     ...
>>     case VSX_BUILTIN_XVABSDP:
>>       {
>>         arg0 = gimple_call_arg (stmt, 0);
>>         lhs = gimple_call_lhs (stmt);
>>         if (TYPE_OVERFLOW_WRAPS(TREE_TYPE(arg1))
>>            return false;
>
> No, you want
>
>     if (! TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1)))
>       return false;
>
> that will likely render the transform useless unless -fwrapv is given.
>
> What we miss in the middle-end is a ABSU_EXPR that computes the
> unsigned result of the absolute value (of the signed operand).  That's
> always well-defined.  So you'd then lower to
>
> y = { -2147483648, -2147483648, -2147483648, -2147483648 };
> D.1234 = ABSU_EXPR <y>;
> D.2579 = VIEW_CONVERT <D.1234>;
>
> RTL expansion of ABSU_EXPR can re-use RTL abs since there's
> nothing undefined on RTL.


There is a PR for this in BZ, though can't find it in a quick search
... We can use this on arm and aarch64 as well IIRC.

regards
Ramana

>
> Richard.
>
>>         ...
>>
>> How can I test this scenario?  At a glance, a testcase snippet doesn't
>> appear to error out.  Am I quietly losing an overflow indicator?
>>
>> vector signed int
>> test1_min (vector signed int x)
>> {
>>   vector signed int y = {INT_MIN,INT_MIN,INT_MIN,INT_MIN};
>>   return vec_abs (y);
>> }
>>
>> generates gimple code:
>>   y = { -2147483648, -2147483648, -2147483648, -2147483648 };
>>   D.2579 = __builtin_altivec_abs_v4si (y);
>> or after folding:
>>   y = { -2147483648, -2147483648, -2147483648, -2147483648 };
>>   D.2579 = ABS_EXPR <y>;
>>
>>
>>
>>
>>>
>>> Richard.
>>>
>>> >
>>> >
>>> > Segher
>>>
>>
>>

      reply	other threads:[~2017-05-31 14:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 17:19 Will Schmidt
2017-05-29  8:39 ` Richard Biener
2017-05-29 10:29   ` Segher Boessenkool
2017-05-29 11:55     ` Richard Biener
2017-05-29 12:23       ` Segher Boessenkool
2017-05-30  7:05         ` Richard Biener
2017-05-31 14:02           ` Will Schmidt
2017-05-31 14:04             ` Richard Biener
2017-05-31 14:06               ` Ramana Radhakrishnan [this message]

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='CAJA7tRY5hT_T9Y4qgBMP=VNeJUN-MbsKrg30bi5tDxY8O6S2XA@mail.gmail.com' \
    --to=ramana.gcc@googlemail.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    --cc=segher@kernel.crashing.org \
    --cc=will_schmidt@vnet.ibm.com \
    --cc=wschmidt@linux.vnet.ibm.com \
    /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).