Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

'Alan Stern'
2024-10-03T01:50:32Z

On Wed, Oct 02, 2024 at 03:24:45PM +0000, David Laight wrote:
> I think I know what you are trying to do, and you just fail.
> Whether something can work is another matter, but that code
> can't ever work.
>
> Inside if (a == b) the compiler will always use the same register
> for references to a and b - because it knows they have the same value.

According to the other people in this discussion who have actually tried
using this code, it _does_ work (at least some of the time).

However, I'm not one of those people and so I leave it up to them to
decide how to respond to this critique.

Alan

> Possibly something like:
> c = b;
> OPTIMISER_HIDE_VAR(c);
> if (a == c) {
> *b
> will ensure that there isn't a speculative load from *a.
> You'll get at least one register-register move - but they are safe.
> Otherwise you'll need to put the condition inside an asm block.
>
> David