public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
@ 2016-03-09 12:56 Kyrill Tkachov
  2016-05-09 11:14 ` Kyrill Tkachov
  2016-06-01  9:02 ` Ramana Radhakrishnan
  0 siblings, 2 replies; 8+ messages in thread
From: Kyrill Tkachov @ 2016-03-09 12:56 UTC (permalink / raw)
  To: GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

Hi all,

I notice that the output code for our store exclusive patterns accesses unallocated memory.
It wants to output an strexd instruction with a pair of consecutive registers corresponding
to a DImode value. For that it creates the SImode top half of the DImode register and puts it
into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
or like that, so operands[3] should technically be out of bounds.

We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
So this patch changes those patterns to use that, eliminating the out of bounds access and making
the code a bit simpler as well.

Bootstrapped and tested on arm-none-linux-gnueabihf.

Ok for trunk?

Thanks,
Kyrill

2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     * config/arm/sync.md (arm_store_exclusive<mode>):
     Use 'H' output modifier on operands[2] rather than creating a new
     entry in out-of-bounds memory of the operands array.
     (arm_store_release_exclusivedi): Likewise.

[-- Attachment #2: arm-store-modifier.patch --]
[-- Type: text/x-patch, Size: 1604 bytes --]

diff --git a/gcc/config/arm/sync.md b/gcc/config/arm/sync.md
index 6dd2dc396210bc45374d13e1a20f124cc490b630..8158f53025400045569533a1e8c6583025d490c8 100644
--- a/gcc/config/arm/sync.md
+++ b/gcc/config/arm/sync.md
@@ -422,14 +422,13 @@ (define_insn "arm_store_exclusive<mode>"
   {
     if (<MODE>mode == DImode)
       {
-	rtx value = operands[2];
 	/* The restrictions on target registers in ARM mode are that the two
 	   registers are consecutive and the first one is even; Thumb is
 	   actually more flexible, but DI should give us this anyway.
-	   Note that the 1st register always gets the lowest word in memory.  */
-	gcc_assert ((REGNO (value) & 1) == 0 || TARGET_THUMB2);
-	operands[3] = gen_rtx_REG (SImode, REGNO (value) + 1);
-	return "strexd%?\t%0, %2, %3, %C1";
+	   Note that the 1st register always gets the
+	   lowest word in memory.  */
+	gcc_assert ((REGNO (operands[2]) & 1) == 0 || TARGET_THUMB2);
+	return "strexd%?\t%0, %2, %H2, %C1";
       }
     return "strex<sync_sfx>%?\t%0, %2, %C1";
   }
@@ -445,11 +444,9 @@ (define_insn "arm_store_release_exclusivedi"
 	  VUNSPEC_SLX))]
   "TARGET_HAVE_LDACQ && ARM_DOUBLEWORD_ALIGN"
   {
-    rtx value = operands[2];
     /* See comment in arm_store_exclusive<mode> above.  */
-    gcc_assert ((REGNO (value) & 1) == 0 || TARGET_THUMB2);
-    operands[3] = gen_rtx_REG (SImode, REGNO (value) + 1);
-    return "stlexd%?\t%0, %2, %3, %C1";
+    gcc_assert ((REGNO (operands[2]) & 1) == 0 || TARGET_THUMB2);
+    return "stlexd%?\t%0, %2, %H2, %C1";
   }
   [(set_attr "predicable" "yes")
    (set_attr "predicable_short_it" "no")])

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-03-09 12:56 [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns Kyrill Tkachov
@ 2016-05-09 11:14 ` Kyrill Tkachov
  2016-05-19 13:27   ` Kyrill Tkachov
  2016-06-01  9:02 ` Ramana Radhakrishnan
  1 sibling, 1 reply; 8+ messages in thread
From: Kyrill Tkachov @ 2016-05-09 11:14 UTC (permalink / raw)
  To: GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw

Hi all,

This seems to have fallen through the cracks.
Ping.
https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00558.html

Thanks,
Kyrill

On 09/03/16 12:56, Kyrill Tkachov wrote:
> Hi all,
>
> I notice that the output code for our store exclusive patterns accesses unallocated memory.
> It wants to output an strexd instruction with a pair of consecutive registers corresponding
> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
> or like that, so operands[3] should technically be out of bounds.
>
> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
> So this patch changes those patterns to use that, eliminating the out of bounds access and making
> the code a bit simpler as well.
>
> Bootstrapped and tested on arm-none-linux-gnueabihf.
>
> Ok for trunk?
>
> Thanks,
> Kyrill
>
> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>
>     * config/arm/sync.md (arm_store_exclusive<mode>):
>     Use 'H' output modifier on operands[2] rather than creating a new
>     entry in out-of-bounds memory of the operands array.
>     (arm_store_release_exclusivedi): Likewise.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-05-09 11:14 ` Kyrill Tkachov
@ 2016-05-19 13:27   ` Kyrill Tkachov
  2016-05-31 13:55     ` Kyrill Tkachov
  0 siblings, 1 reply; 8+ messages in thread
From: Kyrill Tkachov @ 2016-05-19 13:27 UTC (permalink / raw)
  To: GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw

Ping.

Thanks,
Kyrill

On 09/05/16 12:13, Kyrill Tkachov wrote:
> Hi all,
>
> This seems to have fallen through the cracks.
> Ping.
> https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00558.html
>
> Thanks,
> Kyrill
>
> On 09/03/16 12:56, Kyrill Tkachov wrote:
>> Hi all,
>>
>> I notice that the output code for our store exclusive patterns accesses unallocated memory.
>> It wants to output an strexd instruction with a pair of consecutive registers corresponding
>> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
>> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
>> or like that, so operands[3] should technically be out of bounds.
>>
>> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
>> So this patch changes those patterns to use that, eliminating the out of bounds access and making
>> the code a bit simpler as well.
>>
>> Bootstrapped and tested on arm-none-linux-gnueabihf.
>>
>> Ok for trunk?
>>
>> Thanks,
>> Kyrill
>>
>> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>>
>>     * config/arm/sync.md (arm_store_exclusive<mode>):
>>     Use 'H' output modifier on operands[2] rather than creating a new
>>     entry in out-of-bounds memory of the operands array.
>>     (arm_store_release_exclusivedi): Likewise.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-05-19 13:27   ` Kyrill Tkachov
@ 2016-05-31 13:55     ` Kyrill Tkachov
  0 siblings, 0 replies; 8+ messages in thread
From: Kyrill Tkachov @ 2016-05-31 13:55 UTC (permalink / raw)
  To: GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw

Ping.

Thanks,
Kyrill

On 19/05/16 14:27, Kyrill Tkachov wrote:
> Ping.
>
> Thanks,
> Kyrill
>
> On 09/05/16 12:13, Kyrill Tkachov wrote:
>> Hi all,
>>
>> This seems to have fallen through the cracks.
>> Ping.
>> https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00558.html
>>
>> Thanks,
>> Kyrill
>>
>> On 09/03/16 12:56, Kyrill Tkachov wrote:
>>> Hi all,
>>>
>>> I notice that the output code for our store exclusive patterns accesses unallocated memory.
>>> It wants to output an strexd instruction with a pair of consecutive registers corresponding
>>> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
>>> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
>>> or like that, so operands[3] should technically be out of bounds.
>>>
>>> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
>>> So this patch changes those patterns to use that, eliminating the out of bounds access and making
>>> the code a bit simpler as well.
>>>
>>> Bootstrapped and tested on arm-none-linux-gnueabihf.
>>>
>>> Ok for trunk?
>>>
>>> Thanks,
>>> Kyrill
>>>
>>> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>>>
>>>     * config/arm/sync.md (arm_store_exclusive<mode>):
>>>     Use 'H' output modifier on operands[2] rather than creating a new
>>>     entry in out-of-bounds memory of the operands array.
>>>     (arm_store_release_exclusivedi): Likewise.
>>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-03-09 12:56 [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns Kyrill Tkachov
  2016-05-09 11:14 ` Kyrill Tkachov
@ 2016-06-01  9:02 ` Ramana Radhakrishnan
  2016-06-01  9:07   ` Ramana Radhakrishnan
  1 sibling, 1 reply; 8+ messages in thread
From: Ramana Radhakrishnan @ 2016-06-01  9:02 UTC (permalink / raw)
  To: Kyrill Tkachov, GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw



On 09/03/16 12:56, Kyrill Tkachov wrote:
> Hi all,
> 
> I notice that the output code for our store exclusive patterns accesses unallocated memory.
> It wants to output an strexd instruction with a pair of consecutive registers corresponding
> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
> or like that, so operands[3] should technically be out of bounds.
> 
> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
> So this patch changes those patterns to use that, eliminating the out of bounds access and making
> the code a bit simpler as well.
> 
> Bootstrapped and tested on arm-none-linux-gnueabihf.
> 
> Ok for trunk?
> 
> Thanks,
> Kyrill
> 
> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
> 
>     * config/arm/sync.md (arm_store_exclusive<mode>):
>     Use 'H' output modifier on operands[2] rather than creating a new
>     entry in out-of-bounds memory of the operands array.
>     (arm_store_release_exclusivedi): Likewise.


Ok,

Thanks,
ramana

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-06-01  9:02 ` Ramana Radhakrishnan
@ 2016-06-01  9:07   ` Ramana Radhakrishnan
  2016-06-01 10:18     ` Kyrill Tkachov
  0 siblings, 1 reply; 8+ messages in thread
From: Ramana Radhakrishnan @ 2016-06-01  9:07 UTC (permalink / raw)
  To: Kyrill Tkachov, GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw



On 01/06/16 10:02, Ramana Radhakrishnan wrote:
> 
> 
> On 09/03/16 12:56, Kyrill Tkachov wrote:
>> Hi all,
>>
>> I notice that the output code for our store exclusive patterns accesses unallocated memory.
>> It wants to output an strexd instruction with a pair of consecutive registers corresponding
>> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
>> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
>> or like that, so operands[3] should technically be out of bounds.
>>
>> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
>> So this patch changes those patterns to use that, eliminating the out of bounds access and making
>> the code a bit simpler as well.
>>
>> Bootstrapped and tested on arm-none-linux-gnueabihf.
>>
>> Ok for trunk?
>>
>> Thanks,
>> Kyrill
>>
>> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>>
>>     * config/arm/sync.md (arm_store_exclusive<mode>):
>>     Use 'H' output modifier on operands[2] rather than creating a new
>>     entry in out-of-bounds memory of the operands array.
>>     (arm_store_release_exclusivedi): Likewise.
> 
> 
> Ok,
> 
Ah hang on - is this safe for big-endian - remind me again why we shouldn't use 'Q' and 'R' here ?

Ramana

> Thanks,
> ramana
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-06-01  9:07   ` Ramana Radhakrishnan
@ 2016-06-01 10:18     ` Kyrill Tkachov
  2016-06-01 10:27       ` Ramana Radhakrishnan
  0 siblings, 1 reply; 8+ messages in thread
From: Kyrill Tkachov @ 2016-06-01 10:18 UTC (permalink / raw)
  To: Ramana Radhakrishnan, GCC Patches; +Cc: Ramana Radhakrishnan, Richard Earnshaw

Hi Ramana,

On 01/06/16 10:07, Ramana Radhakrishnan wrote:
>
> On 01/06/16 10:02, Ramana Radhakrishnan wrote:
>>
>> On 09/03/16 12:56, Kyrill Tkachov wrote:
>>> Hi all,
>>>
>>> I notice that the output code for our store exclusive patterns accesses unallocated memory.
>>> It wants to output an strexd instruction with a pair of consecutive registers corresponding
>>> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
>>> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
>>> or like that, so operands[3] should technically be out of bounds.
>>>
>>> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
>>> So this patch changes those patterns to use that, eliminating the out of bounds access and making
>>> the code a bit simpler as well.
>>>
>>> Bootstrapped and tested on arm-none-linux-gnueabihf.
>>>
>>> Ok for trunk?
>>>
>>> Thanks,
>>> Kyrill
>>>
>>> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>>>
>>>      * config/arm/sync.md (arm_store_exclusive<mode>):
>>>      Use 'H' output modifier on operands[2] rather than creating a new
>>>      entry in out-of-bounds memory of the operands array.
>>>      (arm_store_release_exclusivedi): Likewise.
>>
>> Ok,
>>
> Ah hang on - is this safe for big-endian - remind me again why we shouldn't use 'Q' and 'R' here ?

Thanks for looking at this.
The existing code does an STRD of REG and REG+1 without any concern for endianness.
This patch simplifies that logic (since %H is just REG+1), so there's no change in behaviour.
The question is whether the current behaviour is wrong for big-endian.

I've looked at sections A8.8.214 and A3.3 in the Architecture Reference Manual (I'm using Rev C.c)
and my understanding is that doubleword quantities should not have their words swapped when storing
and that STREXD (and STRD) stores REG at [address] and REG+1 at [address+4] regardless of endianness.
So I think it's correct here to always store REG followed by REG+1.
I note that this is also what we do when storing a normal DImode value with STRD.
In output_move_double we use an STRD of the lower numbered register followed by the next one without
any checks on endianness.

Looking at the uses of Q and R and their comment in arm_print_operand they are only used when performing
arithmetic operations on the DImode values where choosing the most significant or the least significant
word matters.

Hope this makes sense,
Kyrill

> Ramana
>
>> Thanks,
>> ramana
>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns
  2016-06-01 10:18     ` Kyrill Tkachov
@ 2016-06-01 10:27       ` Ramana Radhakrishnan
  0 siblings, 0 replies; 8+ messages in thread
From: Ramana Radhakrishnan @ 2016-06-01 10:27 UTC (permalink / raw)
  To: Kyrill Tkachov, GCC Patches; +Cc: Richard Earnshaw



On 01/06/16 11:18, Kyrill Tkachov wrote:
> Hi Ramana,
> 
> On 01/06/16 10:07, Ramana Radhakrishnan wrote:
>>
>> On 01/06/16 10:02, Ramana Radhakrishnan wrote:
>>>
>>> On 09/03/16 12:56, Kyrill Tkachov wrote:
>>>> Hi all,
>>>>
>>>> I notice that the output code for our store exclusive patterns accesses unallocated memory.
>>>> It wants to output an strexd instruction with a pair of consecutive registers corresponding
>>>> to a DImode value. For that it creates the SImode top half of the DImode register and puts it
>>>> into operands[3]. But the pattern only defines entries only up to operands[2], with no match_dup 3
>>>> or like that, so operands[3] should technically be out of bounds.
>>>>
>>>> We already have a mechanism for printing the top half of a DImode register, that's the 'H' output modifier.
>>>> So this patch changes those patterns to use that, eliminating the out of bounds access and making
>>>> the code a bit simpler as well.
>>>>
>>>> Bootstrapped and tested on arm-none-linux-gnueabihf.
>>>>
>>>> Ok for trunk?
>>>>
>>>> Thanks,
>>>> Kyrill
>>>>
>>>> 2016-03-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>>>>
>>>>      * config/arm/sync.md (arm_store_exclusive<mode>):
>>>>      Use 'H' output modifier on operands[2] rather than creating a new
>>>>      entry in out-of-bounds memory of the operands array.
>>>>      (arm_store_release_exclusivedi): Likewise.
>>>
>>> Ok,
>>>
>> Ah hang on - is this safe for big-endian - remind me again why we shouldn't use 'Q' and 'R' here ?
> 
> Thanks for looking at this.
> The existing code does an STRD of REG and REG+1 without any concern for endianness.
> This patch simplifies that logic (since %H is just REG+1), so there's no change in behaviour.

Yep makes sense - thanks, not enough coffee this morning.

The patch is ok.

Ramana

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-06-01 10:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09 12:56 [PATCH][ARM] Use proper output modifier for DImode register in store exclusive patterns Kyrill Tkachov
2016-05-09 11:14 ` Kyrill Tkachov
2016-05-19 13:27   ` Kyrill Tkachov
2016-05-31 13:55     ` Kyrill Tkachov
2016-06-01  9:02 ` Ramana Radhakrishnan
2016-06-01  9:07   ` Ramana Radhakrishnan
2016-06-01 10:18     ` Kyrill Tkachov
2016-06-01 10:27       ` Ramana Radhakrishnan

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).