Bug 237207

Summary: [JSC] Reuse known register values on ARMv7
Product: WebKit Reporter: Angelos Oikonomopoulos <angelos>
Component: New BugsAssignee: Angelos Oikonomopoulos <angelos>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, aperez, ews-watchlist, glore, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer, ysuzuki, zan, zdobersek
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Angelos Oikonomopoulos 2022-02-25 06:27:25 PST
[JSC] Reuse known register values on ARMv7
Comment 1 Angelos Oikonomopoulos 2022-02-25 06:32:21 PST
Created attachment 453209 [details]
Patch
Comment 2 Zan Dobersek 2022-02-28 00:44:17 PST
Comment on attachment 453209 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=453209&action=review

> Source/JavaScriptCore/bytecode/CallLinkInfo.cpp:358
> -            DisallowMacroScratchRegisterUsage disallowScratch(jit);
>              jit.loadPtr(CCallHelpers::Address(callLinkInfoGPR, offsetOfCallee()), scratchGPR);
> +            DisallowMacroScratchRegisterUsage disallowScratch(jit);

Is this necessary? In theory it shouldn't cause problems, but it feels safer to me to disallow usage for the whole block, load including.
Comment 3 Angelos Oikonomopoulos 2022-02-28 01:02:26 PST
(In reply to Zan Dobersek from comment #2)
> Comment on attachment 453209 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=453209&action=review
> 
> > Source/JavaScriptCore/bytecode/CallLinkInfo.cpp:358
> > -            DisallowMacroScratchRegisterUsage disallowScratch(jit);
> >              jit.loadPtr(CCallHelpers::Address(callLinkInfoGPR, offsetOfCallee()), scratchGPR);
> > +            DisallowMacroScratchRegisterUsage disallowScratch(jit);
> 
> Is this necessary? In theory it shouldn't cause problems, but it feels safer
> to me to disallow usage for the whole block, load including.

It's necessary for the code to work in its current form, but not strictly necessary. The difference here is that loadPtr (indirectly) does RELEASE_ASSERT(m_allowScratchRegister) because it explicitly invalidates the associated CachedRegister by calling cachedAddressTempRegister().invalidate().

One could have all callers of load*() invalidate the destination register instead, but that felt a bit more error prone. Especially since my base tree didn't include any caller that would need to skip the invalidation (I discovered this new usage when rebasing on Friday). I'm open to changing things around if anyone thinks that would be more appropriate (either in theory or in practice).
Comment 4 Zan Dobersek 2022-02-28 01:09:37 PST
Comment on attachment 453209 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=453209&action=review

>>> Source/JavaScriptCore/bytecode/CallLinkInfo.cpp:358
>>> +            DisallowMacroScratchRegisterUsage disallowScratch(jit);
>> 
>> Is this necessary? In theory it shouldn't cause problems, but it feels safer to me to disallow usage for the whole block, load including.
> 
> It's necessary for the code to work in its current form, but not strictly necessary. The difference here is that loadPtr (indirectly) does RELEASE_ASSERT(m_allowScratchRegister) because it explicitly invalidates the associated CachedRegister by calling cachedAddressTempRegister().invalidate().
> 
> One could have all callers of load*() invalidate the destination register instead, but that felt a bit more error prone. Especially since my base tree didn't include any caller that would need to skip the invalidation (I discovered this new usage when rebasing on Friday). I'm open to changing things around if anyone thinks that would be more appropriate (either in theory or in practice).

I think the change should be fine. It was actually me changing it to the current form in bug #236064. Even if the scratch register will be needed for address resolution, it will be used as the load destination at the very end of this operation, and it's mostly after where we want to actively disallow the usage.
Comment 5 Angelos Oikonomopoulos 2022-02-28 01:14:54 PST
(In reply to Zan Dobersek from comment #4)
> Comment on attachment 453209 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=453209&action=review
> 
> >>> Source/JavaScriptCore/bytecode/CallLinkInfo.cpp:358
> >>> +            DisallowMacroScratchRegisterUsage disallowScratch(jit);
> >> 
> >> Is this necessary? In theory it shouldn't cause problems, but it feels safer to me to disallow usage for the whole block, load including.
> > 
> > It's necessary for the code to work in its current form, but not strictly necessary. The difference here is that loadPtr (indirectly) does RELEASE_ASSERT(m_allowScratchRegister) because it explicitly invalidates the associated CachedRegister by calling cachedAddressTempRegister().invalidate().
> > 
> > One could have all callers of load*() invalidate the destination register instead, but that felt a bit more error prone. Especially since my base tree didn't include any caller that would need to skip the invalidation (I discovered this new usage when rebasing on Friday). I'm open to changing things around if anyone thinks that would be more appropriate (either in theory or in practice).
> 
> I think the change should be fine. It was actually me changing it to the
> current form in bug #236064. Even if the scratch register will be needed for
> address resolution, it will be used as the load destination at the very end
> of this operation, and it's mostly after where we want to actively disallow
> the usage.

Yah, I tracked down the commit that made this change ;-)

Still, I'm not 100% sure from the above which change you think should be fine. Would you rather I keep the loadPtr out of DisallowMacroScratchRegisterUsage (i.e. keep the submitted patch as is)?
Comment 6 Zan Dobersek 2022-02-28 01:18:43 PST
Keep the submitted patch as-is, with the Disallow struct moved after loadPtr, where it used to be.
Comment 7 EWS 2022-02-28 01:57:46 PST
Committed r290589 (247867@main): <https://commits.webkit.org/247867@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 453209 [details].
Comment 8 Radar WebKit Bug Importer 2022-02-28 01:58:19 PST
<rdar://problem/89548061>
Comment 9 Angelos Oikonomopoulos 2022-03-15 06:44:39 PDT
(In reply to Zan Dobersek from comment #6)
> Keep the submitted patch as-is, with the Disallow struct moved after
> loadPtr, where it used to be.

See also: https://bugs.webkit.org/show_bug.cgi?id=237888.