public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* A couple GIMPLE questions
@ 2020-09-05 23:19 Gary Oblock
  2020-09-06  6:29 ` Marc Glisse
  0 siblings, 1 reply; 5+ messages in thread
From: Gary Oblock @ 2020-09-05 23:19 UTC (permalink / raw)
  To: gcc

First off one of the questions just me being curious but
second is quite serious. Note, this is GIMPLE coming
into my optimization and not something I've modified.

Here's the C code:

type_t *
do_comp( type_t *data, size_t len)
{
  type_t *res;
  type_t *x = min_of_x( data, len);
  type_t *y = max_of_y( data, len);

  res = y;
  if ( x < y ) res = 0;
  return res;
}

And here's the resulting GIMPLE:

;; Function do_comp.constprop (do_comp.constprop.0, funcdef_no=5, decl_uid=4392, cgraph_uid=3, symbol_order=68) (executed once)

do_comp.constprop (struct type_t * data)
{
  struct type_t * res;
  struct type_t * x;
  struct type_t * y;
  size_t len;

  <bb 5> [local count: 1073741824]:

  <bb 2> [local count: 1073741824]:
  x_2 = min_of_x (data_1(D), 10000);
  y_3 = max_of_y (data_1(D), 10000);
  if (x_2 < y_3)
    goto <bb 3>; [29.00%]
  else
    goto <bb 4>; [71.00%]

  <bb 3> [local count: 311385128]:

  <bb 4> [local count: 1073741824]:
  # res_4 = PHI <y_3(2), 0B(3)>
  return res_4;

}

The silly question first. In the "if" stmt how does GCC
get those probabilities? Which it shows as 29.00% and
71.00%. I believe they should both be 50.00%.

The serious question is what is going on with this phi?
    res_4 = PHI <y_3(2), 0B(3)>

This makes zero sense practicality wise to me and how is
it supposed to be recognized and used? Note, I really do
need to transform the "0B" into something else for my
structure reorganization optimization.

Thanks,

Gary Oblock




CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to Ampere Computing or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. Any unauthorized review, copying, or distribution of this email (or any attachments thereto) is strictly prohibited. If you are not the intended recipient, please contact the sender immediately and permanently delete the original and any copies of this email and any attachments thereto.

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

* Re: A couple GIMPLE questions
  2020-09-05 23:19 A couple GIMPLE questions Gary Oblock
@ 2020-09-06  6:29 ` Marc Glisse
  2020-09-06  7:38   ` Gary Oblock
  2020-09-06  7:42   ` Gary Oblock
  0 siblings, 2 replies; 5+ messages in thread
From: Marc Glisse @ 2020-09-06  6:29 UTC (permalink / raw)
  To: Gary Oblock; +Cc: gcc

On Sat, 5 Sep 2020, Gary Oblock via Gcc wrote:

> First off one of the questions just me being curious but
> second is quite serious. Note, this is GIMPLE coming
> into my optimization and not something I've modified.
>
> Here's the C code:
>
> type_t *
> do_comp( type_t *data, size_t len)
> {
>  type_t *res;
>  type_t *x = min_of_x( data, len);
>  type_t *y = max_of_y( data, len);
>
>  res = y;
>  if ( x < y ) res = 0;
>  return res;
> }
>
> And here's the resulting GIMPLE:
>
> ;; Function do_comp.constprop (do_comp.constprop.0, funcdef_no=5, decl_uid=4392, cgraph_uid=3, symbol_order=68) (executed once)
>
> do_comp.constprop (struct type_t * data)
> {
>  struct type_t * res;
>  struct type_t * x;
>  struct type_t * y;
>  size_t len;
>
>  <bb 5> [local count: 1073741824]:
>
>  <bb 2> [local count: 1073741824]:
>  x_2 = min_of_x (data_1(D), 10000);
>  y_3 = max_of_y (data_1(D), 10000);
>  if (x_2 < y_3)
>    goto <bb 3>; [29.00%]
>  else
>    goto <bb 4>; [71.00%]
>
>  <bb 3> [local count: 311385128]:
>
>  <bb 4> [local count: 1073741824]:
>  # res_4 = PHI <y_3(2), 0B(3)>
>  return res_4;
>
> }
>
> The silly question first. In the "if" stmt how does GCC
> get those probabilities? Which it shows as 29.00% and
> 71.00%. I believe they should both be 50.00%.

See the profile_estimate pass dump. One branch makes the function return 
NULL, which makes gcc guess that it may be a bit less likely than the 
other. Those are heuristics, which are tuned to help on average, but of 
course they are sometimes wrong.

> The serious question is what is going on with this phi?
>    res_4 = PHI <y_3(2), 0B(3)>
>
> This makes zero sense practicality wise to me and how is
> it supposed to be recognized and used? Note, I really do
> need to transform the "0B" into something else for my
> structure reorganization optimization.

That's not a question? Are you asking why PHIs exist at all? They are the 
standard way to represent merging in SSA representations. You can iterate 
on the PHIs of a basic block, etc.

> CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to Ampere Computing or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. Any unauthorized review, copying, or distribution of this email (or any attachments thereto) is strictly prohibited. If you are not the intended recipient, please contact the sender immediately and permanently delete the original and any copies of this email and any attachments thereto.

Could you please get rid of this when posting on public mailing lists?

-- 
Marc Glisse

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

* Re: A couple GIMPLE questions
  2020-09-06  6:29 ` Marc Glisse
@ 2020-09-06  7:38   ` Gary Oblock
  2020-09-06 16:43     ` Richard Biener
  2020-09-06  7:42   ` Gary Oblock
  1 sibling, 1 reply; 5+ messages in thread
From: Gary Oblock @ 2020-09-06  7:38 UTC (permalink / raw)
  To: gcc

>That's not a question? Are you asking why PHIs exist at all?
>They are the standard way to represent merging in SSA
>representations. You can iterate on the PHIs of a basic block, etc.

Marc,

I first worked with the SSA form twenty years ago so yes I am
aware of what a phi is... I've just never seen a compiler eliminate
an assignment of a variable to a constant and jam the constant into
the phi where the SSA variable should be. What a phi is all about
is representing data flow and a constant in the phi doesn't seem
to be related to that. I can deal with this but it seems that having to
crawl the phis looking for constants seems baroque. I would hope
there is a control that can suppress this or a transformation
that I can invoke to reverse it...

Thanks,

Gary
________________________________
From: Marc Glisse <marc.glisse@inria.fr>
Sent: Saturday, September 5, 2020 11:29 PM
To: Gary Oblock <gary@amperecomputing.com>
Cc: gcc@gcc.gnu.org <gcc@gcc.gnu.org>
Subject: Re: A couple GIMPLE questions

[EXTERNAL EMAIL NOTICE: This email originated from an external sender. Please be mindful of safe email handling and proprietary information protection practices.]


On Sat, 5 Sep 2020, Gary Oblock via Gcc wrote:

> First off one of the questions just me being curious but
> second is quite serious. Note, this is GIMPLE coming
> into my optimization and not something I've modified.
>
> Here's the C code:
>
> type_t *
> do_comp( type_t *data, size_t len)
> {
>  type_t *res;
>  type_t *x = min_of_x( data, len);
>  type_t *y = max_of_y( data, len);
>
>  res = y;
>  if ( x < y ) res = 0;
>  return res;
> }
>
> And here's the resulting GIMPLE:
>
> ;; Function do_comp.constprop (do_comp.constprop.0, funcdef_no=5, decl_uid=4392, cgraph_uid=3, symbol_order=68) (executed once)
>
> do_comp.constprop (struct type_t * data)
> {
>  struct type_t * res;
>  struct type_t * x;
>  struct type_t * y;
>  size_t len;
>
>  <bb 5> [local count: 1073741824]:
>
>  <bb 2> [local count: 1073741824]:
>  x_2 = min_of_x (data_1(D), 10000);
>  y_3 = max_of_y (data_1(D), 10000);
>  if (x_2 < y_3)
>    goto <bb 3>; [29.00%]
>  else
>    goto <bb 4>; [71.00%]
>
>  <bb 3> [local count: 311385128]:
>
>  <bb 4> [local count: 1073741824]:
>  # res_4 = PHI <y_3(2), 0B(3)>
>  return res_4;
>
> }
>
> The silly question first. In the "if" stmt how does GCC
> get those probabilities? Which it shows as 29.00% and
> 71.00%. I believe they should both be 50.00%.

See the profile_estimate pass dump. One branch makes the function return
NULL, which makes gcc guess that it may be a bit less likely than the
other. Those are heuristics, which are tuned to help on average, but of
course they are sometimes wrong.

> The serious question is what is going on with this phi?
>    res_4 = PHI <y_3(2), 0B(3)>
>
> This makes zero sense practicality wise to me and how is
> it supposed to be recognized and used? Note, I really do
> need to transform the "0B" into something else for my
> structure reorganization optimization.

That's not a question? Are you asking why PHIs exist at all? They are the
standard way to represent merging in SSA representations. You can iterate
on the PHIs of a basic block, etc.

> CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to Ampere Computing or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. Any unauthorized review, copying, or distribution of this email (or any attachments thereto) is strictly prohibited. If you are not the intended recipient, please contact the sender immediately and permanently delete the original and any copies of this email and any attachments thereto.

Could you please get rid of this when posting on public mailing lists?

--
Marc Glisse

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

* Re: A couple GIMPLE questions
  2020-09-06  6:29 ` Marc Glisse
  2020-09-06  7:38   ` Gary Oblock
@ 2020-09-06  7:42   ` Gary Oblock
  1 sibling, 0 replies; 5+ messages in thread
From: Gary Oblock @ 2020-09-06  7:42 UTC (permalink / raw)
  To: gcc

>Could you please get rid of this when posting on public mailing lists?

No, I  have no control over that but I'll give the email of our corporate
IT if you want to complain to them...

________________________________
From: Marc Glisse <marc.glisse@inria.fr>
Sent: Saturday, September 5, 2020 11:29 PM
To: Gary Oblock <gary@amperecomputing.com>
Cc: gcc@gcc.gnu.org <gcc@gcc.gnu.org>
Subject: Re: A couple GIMPLE questions

[EXTERNAL EMAIL NOTICE: This email originated from an external sender. Please be mindful of safe email handling and proprietary information protection practices.]


On Sat, 5 Sep 2020, Gary Oblock via Gcc wrote:

> First off one of the questions just me being curious but
> second is quite serious. Note, this is GIMPLE coming
> into my optimization and not something I've modified.
>
> Here's the C code:
>
> type_t *
> do_comp( type_t *data, size_t len)
> {
>  type_t *res;
>  type_t *x = min_of_x( data, len);
>  type_t *y = max_of_y( data, len);
>
>  res = y;
>  if ( x < y ) res = 0;
>  return res;
> }
>
> And here's the resulting GIMPLE:
>
> ;; Function do_comp.constprop (do_comp.constprop.0, funcdef_no=5, decl_uid=4392, cgraph_uid=3, symbol_order=68) (executed once)
>
> do_comp.constprop (struct type_t * data)
> {
>  struct type_t * res;
>  struct type_t * x;
>  struct type_t * y;
>  size_t len;
>
>  <bb 5> [local count: 1073741824]:
>
>  <bb 2> [local count: 1073741824]:
>  x_2 = min_of_x (data_1(D), 10000);
>  y_3 = max_of_y (data_1(D), 10000);
>  if (x_2 < y_3)
>    goto <bb 3>; [29.00%]
>  else
>    goto <bb 4>; [71.00%]
>
>  <bb 3> [local count: 311385128]:
>
>  <bb 4> [local count: 1073741824]:
>  # res_4 = PHI <y_3(2), 0B(3)>
>  return res_4;
>
> }
>
> The silly question first. In the "if" stmt how does GCC
> get those probabilities? Which it shows as 29.00% and
> 71.00%. I believe they should both be 50.00%.

See the profile_estimate pass dump. One branch makes the function return
NULL, which makes gcc guess that it may be a bit less likely than the
other. Those are heuristics, which are tuned to help on average, but of
course they are sometimes wrong.

> The serious question is what is going on with this phi?
>    res_4 = PHI <y_3(2), 0B(3)>
>
> This makes zero sense practicality wise to me and how is
> it supposed to be recognized and used? Note, I really do
> need to transform the "0B" into something else for my
> structure reorganization optimization.

That's not a question? Are you asking why PHIs exist at all? They are the
standard way to represent merging in SSA representations. You can iterate
on the PHIs of a basic block, etc.

> CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to Ampere Computing or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. Any unauthorized review, copying, or distribution of this email (or any attachments thereto) is strictly prohibited. If you are not the intended recipient, please contact the sender immediately and permanently delete the original and any copies of this email and any attachments thereto.

Could you please get rid of this when posting on public mailing lists?

--
Marc Glisse

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

* Re: A couple GIMPLE questions
  2020-09-06  7:38   ` Gary Oblock
@ 2020-09-06 16:43     ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2020-09-06 16:43 UTC (permalink / raw)
  To: Gary Oblock, Gary Oblock via Gcc, gcc

On September 6, 2020 9:38:45 AM GMT+02:00, Gary Oblock via Gcc <gcc@gcc.gnu.org> wrote:
>>That's not a question? Are you asking why PHIs exist at all?
>>They are the standard way to represent merging in SSA
>>representations. You can iterate on the PHIs of a basic block, etc.
>
>Marc,
>
>I first worked with the SSA form twenty years ago so yes I am
>aware of what a phi is... I've just never seen a compiler eliminate
>an assignment of a variable to a constant and jam the constant into
>the phi where the SSA variable should be. What a phi is all about
>is representing data flow and a constant in the phi doesn't seem
>to be related to that. I can deal with this but it seems that having to
>crawl the phis looking for constants seems baroque. I would hope
>there is a control that can suppress this or a transformation
>that I can invoke to reverse it...

No, there isn't. We happily propagate constants into PHI nodes. 

Richard. 

>
>Thanks,
>
>Gary
>________________________________
>From: Marc Glisse <marc.glisse@inria.fr>
>Sent: Saturday, September 5, 2020 11:29 PM
>To: Gary Oblock <gary@amperecomputing.com>
>Cc: gcc@gcc.gnu.org <gcc@gcc.gnu.org>
>Subject: Re: A couple GIMPLE questions
>
>[EXTERNAL EMAIL NOTICE: This email originated from an external sender.
>Please be mindful of safe email handling and proprietary information
>protection practices.]
>
>
>On Sat, 5 Sep 2020, Gary Oblock via Gcc wrote:
>
>> First off one of the questions just me being curious but
>> second is quite serious. Note, this is GIMPLE coming
>> into my optimization and not something I've modified.
>>
>> Here's the C code:
>>
>> type_t *
>> do_comp( type_t *data, size_t len)
>> {
>>  type_t *res;
>>  type_t *x = min_of_x( data, len);
>>  type_t *y = max_of_y( data, len);
>>
>>  res = y;
>>  if ( x < y ) res = 0;
>>  return res;
>> }
>>
>> And here's the resulting GIMPLE:
>>
>> ;; Function do_comp.constprop (do_comp.constprop.0, funcdef_no=5,
>decl_uid=4392, cgraph_uid=3, symbol_order=68) (executed once)
>>
>> do_comp.constprop (struct type_t * data)
>> {
>>  struct type_t * res;
>>  struct type_t * x;
>>  struct type_t * y;
>>  size_t len;
>>
>>  <bb 5> [local count: 1073741824]:
>>
>>  <bb 2> [local count: 1073741824]:
>>  x_2 = min_of_x (data_1(D), 10000);
>>  y_3 = max_of_y (data_1(D), 10000);
>>  if (x_2 < y_3)
>>    goto <bb 3>; [29.00%]
>>  else
>>    goto <bb 4>; [71.00%]
>>
>>  <bb 3> [local count: 311385128]:
>>
>>  <bb 4> [local count: 1073741824]:
>>  # res_4 = PHI <y_3(2), 0B(3)>
>>  return res_4;
>>
>> }
>>
>> The silly question first. In the "if" stmt how does GCC
>> get those probabilities? Which it shows as 29.00% and
>> 71.00%. I believe they should both be 50.00%.
>
>See the profile_estimate pass dump. One branch makes the function
>return
>NULL, which makes gcc guess that it may be a bit less likely than the
>other. Those are heuristics, which are tuned to help on average, but of
>course they are sometimes wrong.
>
>> The serious question is what is going on with this phi?
>>    res_4 = PHI <y_3(2), 0B(3)>
>>
>> This makes zero sense practicality wise to me and how is
>> it supposed to be recognized and used? Note, I really do
>> need to transform the "0B" into something else for my
>> structure reorganization optimization.
>
>That's not a question? Are you asking why PHIs exist at all? They are
>the
>standard way to represent merging in SSA representations. You can
>iterate
>on the PHIs of a basic block, etc.
>
>> CONFIDENTIALITY NOTICE: This e-mail message, including any
>attachments, is for the sole use of the intended recipient(s) and
>contains information that is confidential and proprietary to Ampere
>Computing or its subsidiaries. It is to be used solely for the purpose
>of furthering the parties' business relationship. Any unauthorized
>review, copying, or distribution of this email (or any attachments
>thereto) is strictly prohibited. If you are not the intended recipient,
>please contact the sender immediately and permanently delete the
>original and any copies of this email and any attachments thereto.
>
>Could you please get rid of this when posting on public mailing lists?
>
>--
>Marc Glisse


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

end of thread, other threads:[~2020-09-06 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 23:19 A couple GIMPLE questions Gary Oblock
2020-09-06  6:29 ` Marc Glisse
2020-09-06  7:38   ` Gary Oblock
2020-09-06 16:43     ` Richard Biener
2020-09-06  7:42   ` Gary Oblock

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