<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">On 29/09/2025 14:17, Sven Barth via
fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFMUeB_EvuwwfGtA0LTfq5gUGsWkatLnDvBt9PWw6bLny-Trgg@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">
<div>
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">Martin Frb via fpc-devel
<<a href="mailto:fpc-devel@lists.freepascal.org"
moz-do-not-send="true" class="moz-txt-link-freetext">fpc-devel@lists.freepascal.org</a>>
schrieb am Mo., 29. Sep. 2025, 12:30:<br>
</div>
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Tested
with 3.3.1 d3ac07ad27<br>
-O4<br>
Win 64 bit<br>
<br>
In the code below, compiled with -alr<br>
.section .text.n_p$project1_$$_foo,"ax"<br>
....<br>
# Var a located in register rbx<br>
(and it stays in rbx, until the call to write is prepared)<br>
<br>
<br>
<br>
But if I comment out the "write", and uncomment the "a.w"<br>
# Var a located at rsp+32, size=OS_64<br>
<br>
Even the initial 2 lines will then NOT use a register for
"a"?<br>
</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">The Self parameter of a type helper is a
pointer, so the compiler needs to be able to take the address
which in turn prohibits the use of the regvar optimization for
that variable.</div>
<br>
</div>
</blockquote>
<br>
Ok, I see (well mostly....)<br>
<br>
Does that need to affect (all the) code in which the pointer is used
as just a pointer?<br>
<br>
I mean, ok, (if) for the last statement (where the type helper is
called) it needs to be on the stackframe, then the variable could be
stored then. (and there after)<br>
<br>
But for section of the code where it isn't using the type helper, a
copy could be in a register? => afaik if there are more vars
than registers, then one register can be used for more than one var,
just in different places? So then vars are swapped between frame and
register?<br>
<br>
<br>
Well, ok, the type helper could store a copy of self (pointer to the
pointer) somewhere, and that could be accessed.<br>
But then<br>
- any code before the first call to the type helper should be safe
to optimize<br>
- code after would be tricky, as anything could be that copied
pointer (maybe when "pure" functions exists, and the type helper
method is pure)<br>
<br>
It also raises the question (I could test that, but...) what happens
if I take a pointer of any other local var => will the compiler
see that, and prevent such a local var from being optimised to a
register?<br>
<br>
<br>
Anyway, not important to change. Just important for me to know (so I
know I am not trying to get something to work, that can't work)<br>
Thanks for the explanation.
</body>
</html>