public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: "roger@nextmovesoftware.com" <roger@nextmovesoftware.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix RTL simplifications of FFS, POPCOUNT and PARITY.
Date: Mon, 2 Jan 2023 10:47:10 -0700	[thread overview]
Message-ID: <eb94dd0d-a881-a0e5-7cd0-a7c7f8f4f4fe@gmail.com> (raw)
In-Reply-To: <FFFEA307-E9BE-465C-B6DB-796D52D3D9B4@nextmovesoftware.com>



On 1/2/23 10:30, roger@nextmovesoftware.com wrote:
> 
> Hi Jeff,
> 
>> On 2 Jan 2023, at 15:45, Jeff Law <jeffreyalaw@gmail.com> wrote:
>> On 1/1/23 08:55, Roger Sayle wrote:
>>> In 2011, the rtl.texi documentation was updated to reflect that the
>>> modes of the RTX unary operations FFS, POPCOUNT and PARITY must
>>> match those of their operands.  Unfortunately, some of the transformations
>>> in simplify-rtx.cc predate this tightening of RTL semantics, and have
>>> not (until now) been updated/fixed.  i.e. The POPCOUNT and PARITY
>>> optimizations were "correct" when I originally added them back in 2007.
>>> Segher requested that I split this piece out from a fix for PR 106594 in
>>> https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601501.html
>>> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
>>> and make -k check, both with and without --target_board=unix{-m32},
>>> with no new failures.  Ok for mainline?
>>> 2023-01-01  Roger Sayle  <roger@nextmovesoftware.com>
>>> gcc/ChangeLog
>>> 	* gcc/simplify-rtx.cc (simplify_unary_operation_1) <case FFS>:
>>> 	Avoid generating FFS with mismatched operand and result modes, by
>>> 	using an explicit SIGN_EXTEND/ZERO_EXTEND instead.
>>> 	<case POPCOUNT>: Likewise, for POPCOUNT of ZERO_EXTEND.
>>> 	<case PARITY>: Likewise, for PARITY of {ZERO,SIGN}_EXTEND.
>> ?!?  The docs still seem to indicate to me that the modes of the input and output operands can differ.
>> Let's take PARITY as an example:
>>
>>> @cindex @code{parity@var{m}2} instruction pattern
>>> @item @samp{parity@var{m}2}
>>> Store into operand 0 the parity of operand 1, i.e.@: the number of 1-bits
>>> in operand 1 modulo 2.
>>> @var{m} is either a scalar or vector integer mode.  When it is a scalar,
>>> operand 1 has mode @var{m} but operand 0 can have whatever scalar
>>> integer mode is suitable for the target.
>>
>> The mode of the pattern name has to match the mode of the input operand.  The mode of the
>> output operand can differ from the mode of the input operand.  we seem to have a disagreement
>> on the documented semantics of these opcodes.
> 
> The documentation that you're looking at is the definition of the parity optab in
> md.texi, not the definition of the PARITY rtx in rtl.texi.  The distinction is subtle.
> Hence a backend can define paritysiqi2 but in the RTL pattern it expands to the
> unary PARITY operator must have the same result type as its operand type,
> wrapped in either a truncate or extension if necessary.
Hmm, yea I was looking at md.texi, not rtl.texi.  I'll take a look at 
the latter after I get some coffee.

Thanks!
jeff

  reply	other threads:[~2023-01-02 17:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-01 15:55 Roger Sayle
2023-01-01 21:03 ` Segher Boessenkool
2023-01-01 22:59   ` roger
2023-01-02 15:45 ` Jeff Law
2023-01-02 15:59   ` Jakub Jelinek
2023-01-02 16:20     ` Jeff Law
2023-01-02 17:22       ` Jakub Jelinek
2023-01-02 17:38         ` Jeff Law
2023-01-03 11:33       ` Segher Boessenkool
2023-01-02 17:30   ` roger
2023-01-02 17:47     ` Jeff Law [this message]
2023-02-21 15:39 ` Jakub Jelinek
2023-02-26 13:10   ` Roger Sayle
2023-02-27 16:47     ` Segher Boessenkool

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=eb94dd0d-a881-a0e5-7cd0-a7c7f8f4f4fe@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=roger@nextmovesoftware.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).