public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to force mem constraint for symbol ?
@ 2019-07-07 17:04 William Tambe
  2019-07-07 17:42 ` Jeff Law
  0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2019-07-07 17:04 UTC (permalink / raw)
  To: gcc-help

Let's consider the following code snippet that retrieve the address of a label:

mylabel:
void* ptr = &&mylabel;

when compiling the above, GCC associate the label with the constraint "i".

However, I am unable to force GCC to associate symbols with the
constraint "A" that I am defining in the excerpt below:

----------------------------------------
(define_constraint "A"
 "A memory address."
 (and (match_code "mem")
      (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
           (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
           (match_test "GET_CODE (XEXP (op, 0)) == CONST"))))

(define_insn "movsi"
 [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r")
       (match_operand:SI 1 "general_operand"      "A,i"))]
 ""
 "@
  gip %0, %1
  li %0, %1")
----------------------------------------------------------

GCC always choose to match the line "li %0, %1" instead of the line
"gip %0, %1".

How can I force GCC to match "gip %0, %1" for a symbol ?

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

* Re: how to force mem constraint for symbol ?
  2019-07-07 17:04 how to force mem constraint for symbol ? William Tambe
@ 2019-07-07 17:42 ` Jeff Law
  2019-07-07 17:45   ` Segher Boessenkool
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2019-07-07 17:42 UTC (permalink / raw)
  To: William Tambe, gcc-help

On 7/7/19 11:02 AM, William Tambe wrote:
> Let's consider the following code snippet that retrieve the address of a label:
> 
> mylabel:
> void* ptr = &&mylabel;
> 
> when compiling the above, GCC associate the label with the constraint "i".
> 
> However, I am unable to force GCC to associate symbols with the
> constraint "A" that I am defining in the excerpt below:
> 
> ----------------------------------------
> (define_constraint "A"
>  "A memory address."
>  (and (match_code "mem")
>       (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
>            (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
>            (match_test "GET_CODE (XEXP (op, 0)) == CONST"))))
> 
> (define_insn "movsi"
>  [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r")
>        (match_operand:SI 1 "general_operand"      "A,i"))]
>  ""
>  "@
>   gip %0, %1
>   li %0, %1")
> ----------------------------------------------------------
> 
> GCC always choose to match the line "li %0, %1" instead of the line
> "gip %0, %1".
> 
> How can I force GCC to match "gip %0, %1" for a symbol ?
> 
You'd have to debug the register allocation and reloading phase to
determine what it's doing and why.

And, in general, you want your constraints and predicates to match as
closely as possible.  So in the above case your predicates are
"nonimmediate_operand and "general_operand".  You'd be better off with
"register_operand" and "immediate_operand" since operand 0's constraints
only allow registers and operand 1's constraints only allow immediates.

Jeff

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

* Re: how to force mem constraint for symbol ?
  2019-07-07 17:42 ` Jeff Law
@ 2019-07-07 17:45   ` Segher Boessenkool
  2019-07-09  0:18     ` William Tambe
  0 siblings, 1 reply; 6+ messages in thread
From: Segher Boessenkool @ 2019-07-07 17:45 UTC (permalink / raw)
  To: Jeff Law; +Cc: William Tambe, gcc-help

On Sun, Jul 07, 2019 at 11:41:53AM -0600, Jeff Law wrote:
> On 7/7/19 11:02 AM, William Tambe wrote:
> > (define_constraint "A"
> >  "A memory address."
> >  (and (match_code "mem")
> >       (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
> >            (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
> >            (match_test "GET_CODE (XEXP (op, 0)) == CONST"))))
> > 
> > (define_insn "movsi"
> >  [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r")
> >        (match_operand:SI 1 "general_operand"      "A,i"))]
> >  ""
> >  "@
> >   gip %0, %1
> >   li %0, %1")
> > ----------------------------------------------------------
> > 
> > GCC always choose to match the line "li %0, %1" instead of the line
> > "gip %0, %1".
> > 
> > How can I force GCC to match "gip %0, %1" for a symbol ?
> > 
> You'd have to debug the register allocation and reloading phase to
> determine what it's doing and why.
> 
> And, in general, you want your constraints and predicates to match as
> closely as possible.  So in the above case your predicates are
> "nonimmediate_operand and "general_operand".  You'd be better off with
> "register_operand" and "immediate_operand" since operand 0's constraints
> only allow registers and operand 1's constraints only allow immediates.

Yup.  And "A" is defined as being a mem, which makes no sense, and its
comment says it is a "memory address".


Segher

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

* Re: how to force mem constraint for symbol ?
  2019-07-07 17:45   ` Segher Boessenkool
@ 2019-07-09  0:18     ` William Tambe
  2019-07-09 16:39       ` Segher Boessenkool
  0 siblings, 1 reply; 6+ messages in thread
From: William Tambe @ 2019-07-09  0:18 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Jeff Law, gcc-help

On Sun, Jul 7, 2019 at 12:45 PM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Sun, Jul 07, 2019 at 11:41:53AM -0600, Jeff Law wrote:
> > On 7/7/19 11:02 AM, William Tambe wrote:
> > > (define_constraint "A"
> > >  "A memory address."
> > >  (and (match_code "mem")
> > >       (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
> > >            (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
> > >            (match_test "GET_CODE (XEXP (op, 0)) == CONST"))))
> > >
> > > (define_insn "movsi"
> > >  [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r")
> > >        (match_operand:SI 1 "general_operand"      "A,i"))]
> > >  ""
> > >  "@
> > >   gip %0, %1
> > >   li %0, %1")
> > > ----------------------------------------------------------
> > >
> > > GCC always choose to match the line "li %0, %1" instead of the line
> > > "gip %0, %1".
> > >
> > > How can I force GCC to match "gip %0, %1" for a symbol ?
> > >
> > You'd have to debug the register allocation and reloading phase to
> > determine what it's doing and why.
> >
> > And, in general, you want your constraints and predicates to match as
> > closely as possible.  So in the above case your predicates are
> > "nonimmediate_operand and "general_operand".  You'd be better off with
> > "register_operand" and "immediate_operand" since operand 0's constraints
> > only allow registers and operand 1's constraints only allow immediates.
>
> Yup.  And "A" is defined as being a mem, which makes no sense, and its
> comment says it is a "memory address".

If not much effort, could you please provide the change I should make
to my define_contraint ?

I tried the following two without success:

(define_constraint "A"
 "A memory address."
(ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
           (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
           (match_test "GET_CODE (XEXP (op, 0)) == CONST")))

(define_constraint "A"
 "A memory address."
 (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
           (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
           (and (match_code "mem")
                  (match_test "GET_CODE (XEXP (op, 0)) == CONST"))))

>
>
> Segher

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

* Re: how to force mem constraint for symbol ?
  2019-07-09  0:18     ` William Tambe
@ 2019-07-09 16:39       ` Segher Boessenkool
  2019-07-09 16:49         ` Jeff Law
  0 siblings, 1 reply; 6+ messages in thread
From: Segher Boessenkool @ 2019-07-09 16:39 UTC (permalink / raw)
  To: William Tambe; +Cc: Jeff Law, gcc-help

On Mon, Jul 08, 2019 at 07:18:00PM -0500, William Tambe wrote:
> On Sun, Jul 7, 2019 at 12:45 PM Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> > Yup.  And "A" is defined as being a mem, which makes no sense, and its
> > comment says it is a "memory address".
> 
> If not much effort, could you please provide the change I should make
> to my define_contraint ?
> 
> I tried the following two without success:
> 
> (define_constraint "A"
>  "A memory address."
> (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
>            (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
>            (match_test "GET_CODE (XEXP (op, 0)) == CONST")))

Something like this.

(define_constraint "A"
  "A memory address."
  (match_code "const,symbol_ref,label_ref"))

Look at other ports?  aarch64's "S" looks a lot like this, for example.


Segher

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

* Re: how to force mem constraint for symbol ?
  2019-07-09 16:39       ` Segher Boessenkool
@ 2019-07-09 16:49         ` Jeff Law
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Law @ 2019-07-09 16:49 UTC (permalink / raw)
  To: Segher Boessenkool, William Tambe; +Cc: gcc-help

On 7/9/19 10:39 AM, Segher Boessenkool wrote:
> On Mon, Jul 08, 2019 at 07:18:00PM -0500, William Tambe wrote:
>> On Sun, Jul 7, 2019 at 12:45 PM Segher Boessenkool
>> <segher@kernel.crashing.org> wrote:
>>> Yup.  And "A" is defined as being a mem, which makes no sense, and its
>>> comment says it is a "memory address".
>>
>> If not much effort, could you please provide the change I should make
>> to my define_contraint ?
>>
>> I tried the following two without success:
>>
>> (define_constraint "A"
>>  "A memory address."
>> (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
>>            (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
>>            (match_test "GET_CODE (XEXP (op, 0)) == CONST")))
> 
> Something like this.
> 
> (define_constraint "A"
>   "A memory address."
>   (match_code "const,symbol_ref,label_ref"))
> 
> Look at other ports?  aarch64's "S" looks a lot like this, for example.
Also note that memory addressing is largely influenced by
go-if-legitimate-address.

jeff

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

end of thread, other threads:[~2019-07-09 16:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-07 17:04 how to force mem constraint for symbol ? William Tambe
2019-07-07 17:42 ` Jeff Law
2019-07-07 17:45   ` Segher Boessenkool
2019-07-09  0:18     ` William Tambe
2019-07-09 16:39       ` Segher Boessenkool
2019-07-09 16:49         ` Jeff Law

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