* Question on updating function body on specialized functions
@ 2022-03-08 13:53 Erick Ochoa
2022-03-08 14:51 ` Martin Jambor
0 siblings, 1 reply; 5+ messages in thread
From: Erick Ochoa @ 2022-03-08 13:53 UTC (permalink / raw)
To: gcc
Hi,
I have one function (F) that has been specialized for two different calling
contexts (F1 and F2) and two late SIMPLE_IPA_PASSes (A and B). Pass A
changes some MEM_REFs such that the type of MEM_REF is compatible with the
type of the first operand of the expression. Pass A changes both F1 and F2.
I have printed the function bodies of both F1 and F2 during Pass A and
everything looks correct. Pass B uses these changes.
However I noticed this interesting behaviour:
1. If I fix F1 first and then F2, then pass B will see F2 correctly but
some of F1 MEM_REFs will be incorrect.
2. If I fix F2 first and then F1, then pass B will see F1 correctly but
some of F2 MEM_REFs will be incorrect.
My question is do different specialized functions share the same trees? How
would I then change the bodies of specialized functions?
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on updating function body on specialized functions
2022-03-08 13:53 Question on updating function body on specialized functions Erick Ochoa
@ 2022-03-08 14:51 ` Martin Jambor
2022-03-08 15:29 ` Erick Ochoa
0 siblings, 1 reply; 5+ messages in thread
From: Martin Jambor @ 2022-03-08 14:51 UTC (permalink / raw)
To: Erick Ochoa; +Cc: gcc
Hi Erik,
On Tue, Mar 08 2022, Erick Ochoa via Gcc wrote:
> Hi,
>
> I have one function (F) that has been specialized for two different calling
> contexts (F1 and F2) and two late SIMPLE_IPA_PASSes (A and B). Pass A
> changes some MEM_REFs such that the type of MEM_REF is compatible with the
> type of the first operand of the expression. Pass A changes both F1 and F2.
> I have printed the function bodies of both F1 and F2 during Pass A and
> everything looks correct. Pass B uses these changes.
>
> However I noticed this interesting behaviour:
>
> 1. If I fix F1 first and then F2, then pass B will see F2 correctly but
> some of F1 MEM_REFs will be incorrect.
> 2. If I fix F2 first and then F1, then pass B will see F1 correctly but
> some of F2 MEM_REFs will be incorrect.
>
I try to avoid SIMPLE_IPA_PASSes and so would have to look how exactly
they fit into the big picture. Also, I am not sure what you mean by
"incorrect" above (modified when you'd not have expected it to be)?
> My question is do different specialized functions share the same trees? How
> would I then change the bodies of specialized functions?
Virtual clones are, until they are "materialized." But it a simple IPA
pass it does not really make sense to create virtual clones, does it?
Do you create your clones with create_version_clone_with_body?
Martin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on updating function body on specialized functions
2022-03-08 14:51 ` Martin Jambor
@ 2022-03-08 15:29 ` Erick Ochoa
2022-03-08 22:11 ` Gary Oblock
2022-03-09 8:36 ` Richard Biener
0 siblings, 2 replies; 5+ messages in thread
From: Erick Ochoa @ 2022-03-08 15:29 UTC (permalink / raw)
To: Martin Jambor; +Cc: gcc
Hi Martin!
Thanks for replying, turns out that while I was trying to reply to you I
was able to get the answer. Turns out there is indeed one tree node which
is shared across the two functions. And that is
TREE_OPERAND (MEM_REF, 1).
When I was assigning to
TREE_TYPE ( TREE_OPERAND (MEM_REF, 1) ) in one function, I was modifying
the other. The solution was to create a new tree and assign it directly to
TREE_OPERAND (MEM_REF, 1) in both functions.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on updating function body on specialized functions
2022-03-08 15:29 ` Erick Ochoa
@ 2022-03-08 22:11 ` Gary Oblock
2022-03-09 8:36 ` Richard Biener
1 sibling, 0 replies; 5+ messages in thread
From: Gary Oblock @ 2022-03-08 22:11 UTC (permalink / raw)
To: Erick Ochoa, Martin Jambor; +Cc: gcc
Erick my friend,
That's exactly why I'm such a big fan of creating things
anew each time I mess with them. 😉
Later,
Gary
________________________________
From: Erick Ochoa <eochoa@gcc.gnu.org>
Sent: Tuesday, March 8, 2022 7:29 AM
To: Martin Jambor <mjambor@suse.cz>
Cc: gcc@gcc.gnu.org <gcc@gcc.gnu.org>
Subject: Re: Question on updating function body on specialized functions
Hi Martin!
Thanks for replying, turns out that while I was trying to reply to you I
was able to get the answer. Turns out there is indeed one tree node which
is shared across the two functions. And that is
TREE_OPERAND (MEM_REF, 1).
When I was assigning to
TREE_TYPE ( TREE_OPERAND (MEM_REF, 1) ) in one function, I was modifying
the other. The solution was to create a new tree and assign it directly to
TREE_OPERAND (MEM_REF, 1) in both functions.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on updating function body on specialized functions
2022-03-08 15:29 ` Erick Ochoa
2022-03-08 22:11 ` Gary Oblock
@ 2022-03-09 8:36 ` Richard Biener
1 sibling, 0 replies; 5+ messages in thread
From: Richard Biener @ 2022-03-09 8:36 UTC (permalink / raw)
To: Erick Ochoa; +Cc: Martin Jambor, GCC Development
On Tue, Mar 8, 2022 at 4:31 PM Erick Ochoa via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi Martin!
>
> Thanks for replying, turns out that while I was trying to reply to you I
> was able to get the answer. Turns out there is indeed one tree node which
> is shared across the two functions. And that is
>
> TREE_OPERAND (MEM_REF, 1).
>
> When I was assigning to
>
> TREE_TYPE ( TREE_OPERAND (MEM_REF, 1) ) in one function, I was modifying
> the other. The solution was to create a new tree and assign it directly to
> TREE_OPERAND (MEM_REF, 1) in both functions.
Yes, that's because TREE_OPERAND (MEM_REF, 1) is an INTEGER_CST and
we share those. See tree_node_can_be_shared in the sharing verifier. Note
sharing also includes trees like &a.b.c[1].d for example. The general rule of
thumb is to never directly modify trees but call unshare_expr () on them when
you do.
Richard.
>
> Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-09 8:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 13:53 Question on updating function body on specialized functions Erick Ochoa
2022-03-08 14:51 ` Martin Jambor
2022-03-08 15:29 ` Erick Ochoa
2022-03-08 22:11 ` Gary Oblock
2022-03-09 8:36 ` Richard Biener
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).