public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: pinskia@gmail.com
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Paolo Bonzini <bonzini@gnu.org>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: PING: PATCH [4/n]: Prepare x32: Permute the conversion and addition if one operand is a constant
Date: Thu, 29 May 2014 17:20:00 -0000	[thread overview]
Message-ID: <FE0DE2BB-F07A-406A-870B-CE7DE441A3CF@gmail.com> (raw)
In-Reply-To: <CAMe9rOrrtwZYESJKQagQJMfcxqvSr6JSfKd7mLbhKvnnwL0eCQ@mail.gmail.com>



> On May 29, 2014, at 10:09 AM, "H.J. Lu" <hjl.tools@gmail.com> wrote:
> 
>> On Thu, May 29, 2014 at 9:23 AM,  <pinskia@gmail.com> wrote:
>> 
>> 
>>>> On May 29, 2014, at 9:13 AM, "H.J. Lu" <hjl.tools@gmail.com> wrote:
>>>> 
>>>>> On Wed, May 28, 2014 at 9:52 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>>>>>> On Wed, Jul 13, 2011 at 9:39 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>> On Wed, Jul 13, 2011 at 9:13 AM, Paolo Bonzini <bonzini@gnu.org> wrote:
>>>>>>> On 07/11/2011 05:54 PM, H.J. Lu wrote:
>>>>>>> 
>>>>>>> The key is the
>>>>>>>> 
>>>>>>>>   XEXP (x, 1) == convert_memory_address_addr_space
>>>>>>>>                  (to_mode, XEXP (x, 1), as)
>>>>>>>> 
>>>>>>>> test.  It ensures basically that the constant has 31-bit precision,
>>>>>>>> because
>>>>>>>> otherwise the constant would change from e.g. (const_int -0x7ffffffc)
>>>>>>>> to
>>>>>>>> (const_int 0x80000004) when zero-extending it from SImode to DImode.
>>>>>>>> 
>>>>>>>> But I'm not sure it's safe.  You have,
>>>>>>>> 
>>>>>>>>  (zero_extend:DI (plus:SI FOO:SI) (const_int Y))
>>>>>>>> 
>>>>>>>> and you want to convert it to
>>>>>>>> 
>>>>>>>>  (plus:DI FOO:DI (zero_extend:DI (const_int Y)))
>>>>>>>> 
>>>>>>>> (where the zero_extend is folded).  Ignore that FOO is a SYMBOL_REF
>>>>>>>> (this
>>>>>>>> piece of code does not assume anything about its shape); if FOO ==
>>>>>>>> 0xfffffffc and Y = 8, the result will be respectively 0x4 (valid) and
>>>>>>>> 0x100000004 (invalid).
>>>>>>> 
>>>>>>> This example contradicts what you said above "It ensures basically that
>>>>>>> the
>>>>>>> constant has 31-bit precision".
>>>>>> 
>>>>>> Why?  Certainly Y = 8 has 31-bit (or less) precision.  So it has the same
>>>>>> representation in SImode and DImode, and the test above on XEXP (x, 1)
>>>>>> succeeds.
>>>>> 
>>>>> And then we permute conversion and addition, which leads to the issue you
>>>>> raised above.  In another word, the current code permutes conversion
>>>>> and addition.
>>>>> It leads to different values in case of symbol (0xfffffffc) + 8.
>>>>> Basically the current
>>>>> test for 31-bit (or less) precision is bogus.  The real question is
>>>>> for a address
>>>>> computation, A + B, if address wrap-around is supported in
>>>>> convert_memory_address_addr_space.
>>>> 
>>>> Unless the code has already reassociated the additions already.
>>>> Like in the AARCH64 ILP32 case:
>>>> 
>>>> (plus:SI (plus:SI (mult:SI (reg/v:SI 80 [ b ])
>>>>           (const_int -4 [0xfffffffffffffffc]))
>>>>       (subreg/s/u:SI (reg/v/f:DI 79 [ a ]) 0))
>>>>   (const_int -1073742592 [0xffffffffbffffd00]))
>>>> 
>>>> The Tree level is correct in that it did not reassociate the addition
>>>> but the RTL level ignores that.
>>>> 
>>>> So this patch is invalid and incorrect unless you know the non
>>>> constant part of the addition is a pointer (which is not the case
>>>> here).
>>> 
>>> There is an address overflow.  Is the address overflow behavior
>>> defined here?
>> 
>> There was no address overflow in the original code and there was no address overflow in the tree level. The rtl level does introduce an address overflow but the semantics of plus is defined to be wrapping so there is no overflow.   This is blocking me from testing ilp32 under gnu/Linux as ld.so gets miscompiled and stack addresses have the "sign" bit set.
>> 
> 
> What is your Pmode?

Pmode is dimode while ptr_mode is simode.  Pointers are zero extended when converting between si and di modes. 

Thanks,
Andrew


> 
> 
> -- 
> H.J.

  reply	other threads:[~2014-05-29 17:20 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05 14:30 H.J. Lu
2011-07-09 21:22 ` H.J. Lu
2011-07-09 21:23 ` Paolo Bonzini
2011-07-09 21:41   ` H.J. Lu
2011-07-10 17:04     ` Paolo Bonzini
2011-07-10 21:16       ` H.J. Lu
2011-07-11  0:48         ` H.J. Lu
2011-07-11  1:14           ` H.J. Lu
2011-07-11  6:49             ` H.J. Lu
2011-07-11 11:09             ` Paolo Bonzini
2011-07-11 15:58               ` H.J. Lu
2011-07-11 16:57                 ` H.J. Lu
2011-07-11 17:26                   ` H.J. Lu
2011-07-13 16:24                 ` Paolo Bonzini
2011-07-13 16:52                   ` H.J. Lu
2011-07-13 16:55                     ` Paolo Bonzini
2011-07-13 16:58                       ` Paolo Bonzini
2011-07-13 18:42                         ` H.J. Lu
2011-07-25 10:34                           ` Paolo Bonzini
2011-07-27 18:18                             ` H.J. Lu
2011-07-27 22:41                               ` Paolo Bonzini
2011-07-28  3:11                                 ` H.J. Lu
2011-07-28  7:59                                   ` Paolo Bonzini
2014-05-29  4:52                     ` Andrew Pinski
2014-05-29 16:13                       ` H.J. Lu
2014-05-29 16:23                         ` pinskia
2014-05-29 17:09                           ` H.J. Lu
2014-05-29 17:20                             ` pinskia [this message]
2014-05-30  7:18                               ` Paolo Bonzini
2011-07-28 10:24 Uros Bizjak
2011-07-28 10:27 ` Paolo Bonzini
2011-07-29 13:29   ` H.J. Lu
2011-07-28 18:23     ` Uros Bizjak
2011-07-29  9:32     ` Paolo Bonzini
2011-07-29  9:37       ` Paolo Bonzini
2011-07-30  0:47       ` H.J. Lu
2011-07-30 16:35         ` Paolo Bonzini

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=FE0DE2BB-F07A-406A-870B-CE7DE441A3CF@gmail.com \
    --to=pinskia@gmail.com \
    --cc=bonzini@gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@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).