public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Joseph Myers <joseph@codesourcery.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [RFC][PR target/39726 P4 regression] match.pd pattern to do type narrowing
Date: Mon, 09 Feb 2015 18:33:00 -0000	[thread overview]
Message-ID: <54D8FD76.2060301@redhat.com> (raw)
In-Reply-To: <CAFiYyc0_nvt+GAXmK8RX++XCjqvudaZtsK97XrtK3qiK+B8taA@mail.gmail.com>

On 02/09/15 06:42, Richard Biener wrote:
> On Mon, Feb 9, 2015 at 8:15 AM, Jeff Law <law@redhat.com> wrote:
>> On 02/03/15 04:39, Richard Biener wrote:
>>>>
>>>> I found that explicit types were ignored in some cases.  It was
>>>> frustrating to say the least.
>>>
>>>
>>> Huh, that would be a bug.  Do you have a pattern where that happens?
>>
>> I'll have to recreate them.  In the mean time consider something else I'm
>> playing with that causes an odd error from genmatch...
>>
>> /* If we have a narrowing conversion of an arithmetic or logical
>>     operation where both are operands widening conversions from the
>>     same type as the outer narrowing conversion.  Then convert the
>>     innermost operands to a suitable unsigned type (to avoid introducing
>>     undefined behaviour), perform the operation and convert the result to
>>     the desired type.  */
>>    (simplify
>>      (convert (plus (convert@2 @0) (convert @1)))
>>      (if (TREE_TYPE (@0) == TREE_TYPE (@1)
>>           && TREE_TYPE (@0) == type
>>           && INTEGRAL_TYPE_P (type)
>>           && TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE
>> (@0)))
>>        (with { tree utype = unsigned_type_for (TREE_TYPE (@0));}
>>          (convert (plus (convert:utype @0) (convert:utype @1)))))))
>>
>> So given two narrow operands that get widened, added, and the final result
>> narrowed back down to the original operand types.  Replace with convert the
>> operands to an unsigned type (of same size as the operand), operate on them
>> and convert to the final desired type.
>>
>> This happens to fix 47477 (P2 regression).  Works perfectly for the
>> testcase.
>>
>>
>> Of course we'd like to extend that to other operators...  So, adding the
>> obvious for iterator...
>>
>> (for op (plus minus)
>>    (simplify
>>      (convert (op (convert@2 @0) (convert @1)))
>>      (if (TREE_TYPE (@0) == TREE_TYPE (@1)
>>           && TREE_TYPE (@0) == type
>>           && INTEGRAL_TYPE_P (type)
>>           && TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE
>> (@0)))
>>        (with { tree utype = unsigned_type_for (TREE_TYPE (@0));}
>>          (convert (op (convert:utype @0) (convert:utype @1)))))))
>>
>>
>> Which causes genmatch to barf:
>>
>> build/genmatch --gimple /home/gcc/GIT-2/gcc/gcc/match.pd \
>>      > tmp-gimple-match.c
>> genmatch: two conversions in a row
>>
>>
>> Not only does genmatch barf, it doesn't give any indication what part of the
>> .pd file it found objectionable.
>
> Yeah, I'll have to assign locations to more places at some point.
>
> But the following fixes your testcase, committed to trunk as obvious.
>
> Richard.
>
> 2015-02-09  Richard Biener  <rguenther@suse.de>
>
>          * genmatch.c (replace_id): Copy expr_type.
Cool, thanks!
jeff

  reply	other threads:[~2015-02-09 18:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-31  8:53 Jeff Law
2015-02-01  0:47 ` Joseph Myers
2015-02-01  5:46   ` Jeff Law
2015-02-02  8:57     ` Richard Biener
2015-02-02 18:32       ` Jeff Law
2015-02-03 11:39         ` Richard Biener
2015-02-09  7:15           ` Jeff Law
2015-02-09 13:42             ` Richard Biener
2015-02-09 18:33               ` Jeff Law [this message]
2015-02-02 16:59     ` Joseph Myers
2015-02-02 18:04       ` Jeff Law
2015-02-03  7:20         ` Jeff Law
2015-02-03 12:23           ` Joseph Myers
2015-02-08  7:43             ` Jeff Law
2015-02-11  6:43             ` Jeff Law
2015-02-11 11:16               ` Richard Biener
2015-02-11 15:56                 ` Jeff Law
2015-02-11 16:06                   ` Jakub Jelinek
2015-02-11 17:13               ` Joseph Myers

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=54D8FD76.2060301@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=richard.guenther@gmail.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).