go icon indicating copy to clipboard operation
go copied to clipboard

cmd/compile/internal/ssa: add codegen for Zicond extension on riscv64

Open lxq015 opened this issue 3 months ago • 91 comments

Zicond is a mandatory extension in rva23u64. This patch converts branches to CondSelect and optimizes them to Zicond instructions on RISC-V, along with additional optimization rules.

Zicond can provide performance benefits on unpredictable branches by avoiding branch misprediction penalties. However, on simple predictable branches, zicond uses 4 instructions vs 2 for traditional branches, which can cause performance regressions.

To avoid regressions, we keep CondSelect globally disabled for riscv64 and only enable it for the ConstantTimeSelect intrinsic, which has been shown to benefit from zicond:

goos: linux goarch: riscv64 pkg: crypto/subtle CPU: SG2044 │ nozicond.txt │ zicond.txt │ │ sec/op │ sec/op vs base │ ConstantTimeSelect-44 2.325n ± 4% 1.750n ± 2% -24.69% (p=0.000 n=10)

Future work can explore enabling zicond for other cases that can benefit from zicond.

Follow-up to CL 631595 Updates #75350

Co-authored-by: [email protected] [email protected]

lxq015 avatar Sep 24 '25 04:09 lxq015

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

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

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 avatar Sep 24 '25 04:09 gopherbot

Message from Gopher Robot:

Patch Set 1:

(1 comment)


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

gopherbot avatar Sep 24 '25 04:09 gopherbot

Message from Mark Ryan:

Patch Set 1:

(1 comment)


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

gopherbot avatar Sep 24 '25 09:09 gopherbot

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

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

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 avatar Sep 25 '25 08:09 gopherbot

Message from Xueqi Luo:

Patch Set 2:

(2 comments)


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

gopherbot avatar Sep 25 '25 09:09 gopherbot

Message from Xueqi Luo:

Patch Set 2:

(1 comment)


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

gopherbot avatar Oct 13 '25 08:10 gopherbot

Message from Joel Sing:

Patch Set 2: Run-TryBot+1


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

gopherbot avatar Oct 13 '25 14:10 gopherbot

Message from Gopher Robot:

Patch Set 2:

(1 comment)


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

gopherbot avatar Oct 13 '25 14:10 gopherbot

Message from Gopher Robot:

Patch Set 2:

(2 comments)


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

gopherbot avatar Oct 16 '25 09:10 gopherbot

Message from Dmitri Shuralyov:

Patch Set 2: Commit-Queue+1

(1 comment)


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

gopherbot avatar Oct 17 '25 20:10 gopherbot

Message from Go LUCI:

Patch Set 2:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2025-10-17T20:47:34Z","revision":"a7132c18e5acb55b578bd3cbdeb82ffcd9700498"}


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

gopherbot avatar Oct 17 '25 20:10 gopherbot

Message from Dmitri Shuralyov:

Patch Set 2: -Commit-Queue


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

gopherbot avatar Oct 17 '25 21:10 gopherbot

Message from Go LUCI:

Patch Set 2:

This CL has passed the run


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

gopherbot avatar Oct 17 '25 21:10 gopherbot

Message from Go LUCI:

Patch Set 2: LUCI-TryBot-Result+1


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

gopherbot avatar Oct 17 '25 21:10 gopherbot

Message from Michael Munday:

Patch Set 2:

(5 comments)


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

gopherbot avatar Oct 19 '25 21:10 gopherbot

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

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

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 avatar Oct 21 '25 08:10 gopherbot

Message from Michael Munday:

Patch Set 4:

(1 comment)


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

gopherbot avatar Oct 21 '25 22:10 gopherbot

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

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

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 avatar Oct 22 '25 09:10 gopherbot

Message from Xueqi Luo:

Patch Set 4:

(1 comment)


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

gopherbot avatar Oct 22 '25 09:10 gopherbot

Message from Joel Sing:

Patch Set 5: Commit-Queue+1


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

gopherbot avatar Oct 22 '25 15:10 gopherbot

Message from Go LUCI:

Patch Set 5:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2025-10-22T15:27:55Z","revision":"a78d7cefbf4d1e3b2df625c9389c8fa01f7aef09"}


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

gopherbot avatar Oct 22 '25 15:10 gopherbot

Message from Joel Sing:

Patch Set 5: -Commit-Queue


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

gopherbot avatar Oct 22 '25 16:10 gopherbot

Message from Go LUCI:

Patch Set 5:

This CL has passed the run


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

gopherbot avatar Oct 22 '25 16:10 gopherbot

Message from Go LUCI:

Patch Set 5: LUCI-TryBot-Result+1


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

gopherbot avatar Oct 22 '25 16:10 gopherbot

Message from Michael Munday:

Patch Set 5:

(9 comments)


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

gopherbot avatar Oct 23 '25 20:10 gopherbot

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

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

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 avatar Nov 04 '25 07:11 gopherbot

Message from Xueqi Luo:

Patch Set 6:

(15 comments)


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

gopherbot avatar Nov 04 '25 07:11 gopherbot

Message from Michael Munday:

Patch Set 6: Code-Review+1

(2 comments)


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

gopherbot avatar Nov 04 '25 09:11 gopherbot

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

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

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 avatar Nov 05 '25 04:11 gopherbot

Message from Xueqi Luo:

Patch Set 7:

(2 comments)


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

gopherbot avatar Nov 05 '25 05:11 gopherbot