[Bug middle-end/115091] Support value speculation in frontend

2024-05-16 Thread amonakov at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115091

Alexander Monakov  changed:

   What|Removed |Added

 CC||amonakov at gcc dot gnu.org

--- Comment #3 from Alexander Monakov  ---
(In reply to andi from comment #2)
> > That said, I heard CPUs have prefetchers that recognize this kind of list
> > walking.  I wonder why they wouldn't then also be able to speculate the
> > load value like you say.
> 
> These are on the L2 or L3 level, not L1. This is about hiding L1
> latencies, which normally doesn't have a prefetcher.

Richard is correct in the sense that Apple M1 CPUs do that. Intel is not
holding the IPC crown these days ;)

[Bug middle-end/115091] Support value speculation in frontend

2024-05-15 Thread andi at firstfloor dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115091

--- Comment #2 from andi at firstfloor dot org ---
On Wed, May 15, 2024 at 06:23:27AM +, rguenth at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115091
> 
> --- Comment #1 from Richard Biener  ---
> maybe represent this in a more formal way:

Makes sense.
> 
>   node = __builtin_speculate (node + 1, node->next);
> 
> and in GIMPLE:
> 
>   _1 = node + 1;
>   _2 = node->next;
>   node = .SPECULATE (_1, _2);
> 
> and during RTL expansion leave the desired representation to the targets
> which could use an UNSPEC to avoid optimizing it away.

There might be speculation constructs that don't use equal in more
complex scenarios. For example you could speculate on a binary search.
Perhaps could extend it to more conditions?

> Formally we'd say __builtin_speculate "uses" the first argument if its
> value is equal to the second argument value.
> 
> That said, I heard CPUs have prefetchers that recognize this kind of list
> walking.  I wonder why they wouldn't then also be able to speculate the
> load value like you say.

These are on the L2 or L3 level, not L1. This is about hiding L1
latencies, which normally doesn't have a prefetcher.

> Oh, and doesn't this explicit speculation of using node++ open up spectre
> style attacks?

It's not different than any other condition in this regard.

[Bug middle-end/115091] Support value speculation in frontend

2024-05-15 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115091

--- Comment #1 from Richard Biener  ---
maybe represent this in a more formal way:

  node = __builtin_speculate (node + 1, node->next);

and in GIMPLE:

  _1 = node + 1;
  _2 = node->next;
  node = .SPECULATE (_1, _2);

and during RTL expansion leave the desired representation to the targets
which could use an UNSPEC to avoid optimizing it away.

Formally we'd say __builtin_speculate "uses" the first argument if its
value is equal to the second argument value.

That said, I heard CPUs have prefetchers that recognize this kind of list
walking.  I wonder why they wouldn't then also be able to speculate the
load value like you say.

Oh, and doesn't this explicit speculation of using node++ open up spectre
style attacks?

[Bug middle-end/115091] Support value speculation in frontend

2024-05-14 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115091

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement
  Component|c++ |middle-end