PING: PATCH [4/n]: Prepare x32: Permute the conversion and addition if one operand is a constant

H.J. Lu hjl.tools@gmail.com
Mon Jul 11 16:57:00 GMT 2011


On Mon, Jul 11, 2011 at 8:54 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Jul 11, 2011 at 4:03 AM, Paolo Bonzini <bonzini@gnu.org> wrote:
>> On 07/11/2011 02:04 AM, H.J. Lu wrote:
>>>
>>> With my original change,  I got
>>>
>>> (const:DI (plus:DI (symbol_ref:DI ("iplane.1577") [flags 0x2]
>>> <var_decl 0x7ffff0857960 iplane>)
>>>         (const_int -4 [0xfffffffffffffffc])))
>>>
>>> I think it is safe to permute the conversion and addition operation
>>> if one operand is a constant and we are zero-extending.  This is
>>> how zero-extending works.
>>
>> Ok, I think I understand what you mean.  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".  For zero-extend, the issue is address-wrap.
> As I understand, to support address-wrap, you need to use ptr_mode.
>

I am totally confused what the current code

     /* For addition we can safely permute the conversion and addition
         operation if one operand is a constant and converting the constant
         does not change it or if one operand is a constant and we are
         using a ptr_extend instruction  (POINTERS_EXTEND_UNSIGNED < 0).
         We can always safely permute them if we are making the address
         narrower.  */
      if (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (from_mode)
          || (GET_CODE (x) == PLUS
              && CONST_INT_P (XEXP (x, 1))
              && (XEXP (x, 1) == convert_memory_address_addr_space
                                   (to_mode, XEXP (x, 1), as)
                 || POINTERS_EXTEND_UNSIGNED < 0)))
        return gen_rtx_fmt_ee (GET_CODE (x), to_mode,
                               convert_memory_address_addr_space
                                 (to_mode, XEXP (x, 0), as),
                               XEXP (x, 1));

is trying to do.  It doesn't support address-wrap at all, regardless if
converting the constant changes the constant.  I think it should be
OK to permute if no instructions are allowed, like:

     if (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (from_mode)
          || (GET_CODE (x) == PLUS
              && CONST_INT_P (XEXP (x, 1))
              && POINTERS_EXTEND_UNSIGNED != 0
              && no_emit))
        return gen_rtx_fmt_ee (GET_CODE (x), to_mode,
                               convert_memory_address_addr_space_1
                                 (to_mode, XEXP (x, 0), as, no_emit),
                               XEXP (x, 1));


-- 
H.J.



More information about the Gcc-patches mailing list