[go] cmd/compile/internal/ssa: constant fold math/bits functions

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Aug 6, 2026, 9:53:01 PM (3 days ago) Aug 6
to Gilbert Morgan, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, Martin Möhrmann, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
cmd/compile/internal/ssa: constant fold math/bits functions

Add constant folding rewrite rules for RotateLeft64/32/16/8,
Sub64borrow, and Div128u generic SSA operations when their inputs
are compile-time constants.

Currently, these operations are evaluated at runtime by target-specific
instruction sequences, even when all their arguments are constant.
This change leverages compiler-level optimization to evaluate these
operations statically during the generic SSA optimization pass, replacing
them with simple constant loads.

Add corresponding codegen assertions to test/codegen/mathbits.go
to verify instruction elimination across major CPU architectures
(amd64, arm64, ppc64x, loong64, riscv64, s390x, and WebAssembly).

Fixes #21872.
Change-Id: Ia3e6f6f93f2255ff4271f75c8636923e62488f18
Reviewed-by: Keith Randall <k...@golang.org>
Auto-Submit: Keith Randall <k...@golang.org>
Reviewed-by: Keith Randall <k...@google.com>
Files:
  • M src/cmd/compile/internal/ssa/_gen/generic.rules
  • M src/cmd/compile/internal/ssa/rewrite.go
  • M src/cmd/compile/internal/ssa/rewritegeneric.go
  • M test/codegen/mathbits.go
Change size: L
Delta: 4 files changed, 264 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e6f6f93f2255ff4271f75c8636923e62488f18
Gerrit-Change-Number: 810700
Gerrit-PatchSet: 2
Gerrit-Owner: Gilbert Morgan <gilber...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages