Skip to content

cmd/compile: use memory operands in amd64 carry chains - #82122

Open
udaykishore-resu wants to merge 1 commit into
golang:masterfrom
udaykishore-resu:cmd-compile-adcq-sbbq-memory-operands
Open

udaykishore-resu wants to merge 1 commit into
golang:masterfrom
udaykishore-resu:cmd-compile-adcq-sbbq-memory-operands

Conversation

@udaykishore-resu

Copy link
Copy Markdown

cmd/compile: use memory operands in amd64 carry chains

Add ADDQcarryload, ADCQload, SUBQborrowload and SBBQload, which read the second operand of a carry or borrow chain link from memory, and merge a MOVQload into ADDQcarry, ADCQ, SUBQborrow and SBBQ when possible. For

_, c := bits.Add64(a[0], b[0], 0)
_, c2 := bits.Add64(a[1], b[1], c)

the compiler now emits

ADDQ	a(SP), DX
ADCQ	b+24(SP), BX

instead of loading each operand into a register first.

The new ops also absorb FlagEQ and InvertFlags carry inputs, as ADCQ and SBBQ do (see #79887), and fold constant offsets and LEAQ into their address.

flagalloc restores a flag value by copying its generator and, through copyFlags, the generators of that generator's flag inputs: the earlier links of a carry chain. A copy runs later than the original, possibly after a store, so it must not read memory. flagalloc only split generators that were themselves spilled; it now splits, before copying anything, every generator that may be copied and reads memory. Without this, a carry that must survive a call made the compiler fail with "can't move a value with a memory arg". On std and cmd the set of values that flagalloc splits is unchanged.

When both the result and the carry of a link are used, lowering builds two identical ADCQ values that are only merged by the lowered CSE pass, after the load merging rules have run, so such links still load their operand into a register. That leaves the middle links of multi-word additions unchanged; fixing it needs a change to how Add64carry and Sub64borrow are lowered.

Fixes #80400

…64 backend

- Added new operations for ADCQload, ADDQcarryload, SBBQload, and SUBQborrowload in the SSA rewrite rules.
- Enhanced the flag allocation logic to handle cases where carry and borrow values are read from memory.
- Introduced new test cases to validate the behavior of carry and borrow operations when operands are loaded from memory.
- Ensured that the recomputation of flags after function calls does not read memory again, preserving the correctness of carry values.
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 6225523) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/848405.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/848405.
After addressing review feedback, remember to publish your drafts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/compile: add memory operand ADC and SBB to AMD64.rules

2 participants