public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alan Lawrence <alan.lawrence@arm.com>
To: Marcus Shawcroft <Marcus.Shawcroft@arm.com>,
	 Richard Earnshaw <Richard.Earnshaw@arm.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	 "law@redhat.com" <law@redhat.com>
Subject: [AArch64] Re: [PATCH] Relax check against commuting XOR and ASHIFTRT in combine.c
Date: Mon, 22 Sep 2014 11:16:00 -0000	[thread overview]
Message-ID: <542004F5.8080009@arm.com> (raw)
In-Reply-To: <541BC141.500@redhat.com>

Ok thanks Jeff. In that case I think I should draw this to the attention of the 
AArch64 maintainers to check the testsuite updates are OK before I commit...?

Methinks it may be possible to get further, or at least increase our confidence, 
if I "mock" out try_widen_shift_mode, and/or try injecting some dubious RTL from 
a builtin, although this'll only give a momentary snapshot of behaviour. I may 
or may not have time to look into this though ;)...

Cheers, Alan

Jeff Law wrote:
> On 09/18/14 03:35, Alan Lawrence wrote:
>> Moreover, I think we both agree that if result_mode==shift_mode, the
>> transformation is correct. "Just" putting that check in, achieves
>> what I'm trying for here, so I'd be happy to go with the attached
>> patch and call it a day. However, I'm a little concerned about the
>> other cases - i.e. where shift_mode is wider than result_mode.
> Let's go ahead and get the attached patch installed.  I'm pretty sure 
> it's correct and I know you want to see something move forward here.  We 
> can iterate further if we want.
> 
>> If I understand correctly (and I'm not sure about that, let's see how
>> far I get), this means we'll perform the shift in (say) DImode, when
>> we're only really concerned about the lower (say) 32-bits (for an
>> originally-SImode shift).
> That's the class of cases I'm concerned about.
> 
> 
>   try_widen_shift_mode will in this case
>> check that the result of the operation *inside* the shift (in our
>> case an XOR) has 33 sign bit copies (via num_sign_bit_copies), i.e.
>> that its *top* 32-bits are all equal to the original SImode sign bit.
>> <count> of these bits may be fed into the top of the desired SImode
>> result by the DImode shift. Right so far?
> Correct.
> 
>> AFAICT, num_sign_bit_copies for an XOR, conservatively returns the
>> minimum of the num_sign_bit_copies of its two operands. I'm not sure
>> whether this is behaviour we should rely on in its callers, or for
>> the sake of abstraction we should treat num_sign_bit_copies as a
>> black box (which does what it says on the, erm, tin).
> Treat it as a black box.  It returns the number of known sign bit 
> copies.  There may be more, but never less.
> 
> 
>> If the former, doesn't having num_sign_bit_copies >= the difference
>> in size between result_mode and shift_mode, of both operands to the
>> XOR, guarantee safety of the commutation (whether the constant is
>> positive or negative)? We could perform the shift (in the larger
>> mode) on both of the XOR operands safely, then XOR together their
>> lower parts.
> I had convinced myself that when we flip the sign bit via the XOR and 
> commute the XOR out that we invalidate the assumptions made when 
> widening.  But I'm not so sure anymore.  Damn I hate changes made 
> without suitable tests :(
> 
> I almost convinced myself the problem is in the adjustment of C2 in the 
> widened case, but that's not a problem either.  At least not on paper.
> 
>> If, however, we want to play safe and ensure that we deal safely with
>>  any XOR whose top (mode size difference + 1) bits were the same,
>> then I think the restriction that the XOR constant is positive is
>> neither necessary nor sufficient; rather (mirroring
>> try_widen_shift_mode) I think we need that num_sign_bit_copies of the
>> constant in shift_mode, is more than the size difference between
>> result_mode and shift_mode.
> But isn't that the same?  Isn't the only case where it isn't the same 
> when the constant has bits set that are outside the mode of the other 
> operand?
> 
> Hmm, what about (xor:QI A -1)?  In that case -1 will be represented with 
> bits outside the precision of QImode.
> 
>> Hmmm. I might try that patch at some point, I think it is the right
>> check to make. (Meta-comment: this would be *so*much* easier if we
>> could write unit tests more easily!) In the meantime I'd be happy to
>> settle for the attached...
> No argument on the unit testing comment.  It's a major failing in the 
> design of GCC that we can't easily build a unit testing framework.
> 
> Jeff
> 


  reply	other threads:[~2014-09-22 11:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-30 19:05 Alan Lawrence
2014-06-30 21:11 ` Jeff Law
2014-07-16 15:27   ` Alan Lawrence
2014-07-17 17:13     ` Alan Lawrence
2014-08-20 10:05       ` Alan Lawrence
2014-09-05 18:06       ` Jeff Law
2014-09-18  9:40         ` Alan Lawrence
2014-10-05  8:06           ` Andreas Schwab
2014-10-23 13:13             ` Rainer Orth
2014-10-23 16:55               ` Alan Lawrence
2014-10-23 17:30                 ` Rainer Orth
2014-10-24 11:55                   ` Alan Lawrence
2014-10-24 13:20                     ` Rainer Orth
2014-10-24 17:11                       ` Alan Lawrence
2015-01-29 14:54                         ` Rainer Orth
2015-02-02 14:33                           ` Alan Lawrence
2015-02-02 15:47                             ` Rainer Orth
     [not found]         ` <541AA752.9030302@arm.com>
2014-09-19  5:38           ` Jeff Law
2014-09-22 11:16             ` Alan Lawrence [this message]
2014-09-22 17:02               ` [AArch64] " Jeff Law
2014-09-23 11:32               ` Marcus Shawcroft

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=542004F5.8080009@arm.com \
    --to=alan.lawrence@arm.com \
    --cc=Marcus.Shawcroft@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.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).