5544 Commits

Author SHA1 Message Date
Keith Randall
14a6bf0e90 test/codegen: remove unneeded commas
After CL 760780, commas aren't allowed.
But some CLs that were already in flight don't know that.

Change-Id: I31f586c87def4a9746dc2c055923fce8bad6647e
Reviewed-on: https://go-review.googlesource.com/c/go/+/761620
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-31 12:43:09 -07:00
Keith Randall
1582ad4105 test/codegen: fix some unbalanced quotes
Change-Id: I081da8c79f0264118e079af21ff58c511ae37e6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/760682
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@google.com>
2026-03-31 11:01:20 -07:00
Keith Randall
d5b6d583c1 test/codegen: replace commas with spaces between regexps
Change-Id: Ia7a955833d761e08c1b8081fb29a2e6317de004c
Reviewed-on: https://go-review.googlesource.com/c/go/+/760681
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Paul Murphy <paumurph@redhat.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-31 11:01:16 -07:00
Keith Randall
d6492e284b test/codegen: get rid of \s
Replace \s with a space in backtick-quoted strings
Replace \\s with a space in double-quoted strings

Change-Id: I0c8b249bb12c2c8ca69e683e4bc6f27544fd6094
Reviewed-on: https://go-review.googlesource.com/c/go/+/760680
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Paul Murphy <paumurph@redhat.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-31 11:01:13 -07:00
Keith Randall
1673075d4b test/codegen: fix broken syntax
A bunch of tests had broken yet undetected syntax errors
in their assembly output regexps. Things like mismatched quotes,
using ^ instead of - for negation, etc.

In addition, since CL 716060 using commas as separators between
regexps doesn't work, and ends up just silently dropping every
regexp after the comma.

Fix all these things, and add a test to make sure that we're not
silently dropping regexps on the floor.

After this CL I will do some cleanup to align with CL 716060, like
replacing commas and \s with spaces (which was the point of that CL,
but wasn't consistently rewritten everywhere).

Change-Id: I54f226120a311ead0c6c62eaf5d152ceed106034
Reviewed-on: https://go-review.googlesource.com/c/go/+/760521
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Paul Murphy <paumurph@redhat.com>
Auto-Submit: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-31 11:01:09 -07:00
Cuong Manh Le
f665ff8bc1 cmd/compile: fix wrong label loop during rangefunc rewrite
During the rangefunc rewrite, the compiler must correctly identify
the target of branch statements. When a label is defined within a
nested scope - such as inside a function literal or a closure - it
can shadow a label with the same name in the outer scope.

If the rewrite logic does not account for this shadowing, it may
incorrectly associate a branch with a nested label rather than the
intended loop label. Since the typechecker already guarantees that
labels are unique within their respective scopes, any duplicate label
name encountered must belong to a nested scope. These should be
skipped to ensure branch computing correctly targets the current
range-loop scope.

Fixes #78408

Change-Id: I4dce8a4d956f41b3a717a509f8c3f7478720be9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/761420
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-31 10:58:57 -07:00
Cuong Manh Le
9002bd9fa1 cmd/compile: ensure map/slice clearing expressions are walked
The order pass ensures that initialization operations for clear(expr)
are scheduled. However, if 'expr' is a conversion that the walk pass
subsequently optimizes away or transforms, the resulting nodes can
be left in an un-walked state.

These un-walked nodes reach the SSA backend, which does not expect
high-level IR, resulting in an ICE.

This change ensures the expression is always walked during the
transformation of the 'clear' builtin.

Fixes #78410

Change-Id: I1997a28af020f39b2d325a58429eff9495048b1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/760981
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2026-03-31 10:58:53 -07:00
Jorropo
d9fbe4c90d cmd/compile: convert some condmoves in XOR
Similar to CL 685676 but for XOR.

Change-Id: Ib5ffd4c13348f176a808b3218fdbbafc2c42794f
Reviewed-on: https://go-review.googlesource.com/c/go/+/760921
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-31 10:58:48 -07:00
Jorropo
de7f006df2 cmd/compile: convert some condmoves in OR
Similar to CL 685676 but for OR.

Change-Id: I0ddfd457ed9e8888462306138a251ac48ad42084
Reviewed-on: https://go-review.googlesource.com/c/go/+/760920
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
2026-03-31 10:58:45 -07:00
Cuong Manh Le
1f8aff4386 simd/archsimd: mark pa* unsafe helpers as nocheckptr
Despite the cast from smaller to bigger slice, the elements after the
input slice length are not actually read. Thus they should have
nocheckptr annotation to make checkptr happy.

Fixes #78413

Change-Id: I3e27eab8a69b37bb11632b130a87e6625e06e8ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/761120
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2026-03-30 21:19:14 -07:00
Mateusz Poliwczak
09031d907c cmd/compile/internal/devirtualize: use pointer identity for type comparison
Fixes #78404

Change-Id: I6adc1fb42ad6a3acce21333c6819d0796a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/760161
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-30 07:27:52 -07:00
Keith Randall
1fd68799c3 test/codegen: check mips64 sqrt/abs code only for hardfloat
Softfloat doesn't use the hardware instructions.

Followon to CL 739520 + CL 757300

Change-Id: Ic271cd5567c62933d2d0c01d8834f9bf07e31061
Reviewed-on: https://go-review.googlesource.com/c/go/+/760520
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Julian Zhu <jz531210@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-27 21:32:35 -07:00
Jorropo
47c0cd9929 test/codegen: remove noop Ands from test cases
Theses test cases search for an AND that gets
optimized away after CL 760307.

Should help to fix riscv64 (coudn't check as
builders don't appear on https://build.golang.org/ )
and loong64 CI on master.

Change-Id: I57e4e5ab7d3003f239355137472585e46493d8dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/760640
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
2026-03-27 21:20:13 -07:00
Paul Murphy
880f126233 test/codegen: fix ppc64x rldicl bit test
The prove pass removes superfluous bit masking. This was meant to
test the edge cases of the ppc64 folding rules which are exactly
the cases the prove pass now removes.

Fixes #78403

Change-Id: I45eeac58e01b42e19b8a06bb0d7af96c616ccbff
Reviewed-on: https://go-review.googlesource.com/c/go/+/760307
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Paul Murphy <paumurph@redhat.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-27 18:07:27 -07:00
Youlin Feng
faeffecf86 cmd/compile/internal/ssa: prove support induction variable pair
We have two induction variables i and j in the following loop:

for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
    // loop body
}

This CL enables the prove pass to handle cases where one if block
uses two induction variables.

Updates #45078

Change-Id: I8b8dc8b7b2d160a796dab1d1e29a00ef4e8e8157
Reviewed-on: https://go-review.googlesource.com/c/go/+/757700
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-27 06:29:34 -07:00
Jorropo
e7b0a53f31 cmd/compile: use prove to remove no-op Ors
This is hit 3 times (unique by LOC) when building the std.

Change-Id: Ic1fc7b60a129e73470d9bc4f603f4be12d154b0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/750342
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-27 06:27:39 -07:00
Jorropo
2df8c060e8 cmd/compile: remove 68857 And flowLimit workaround in prove
Change-Id: Id8baeb89e6e11a01d53cd63c665f0b2966f50392
Reviewed-on: https://go-review.googlesource.com/c/go/+/750341
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-27 06:27:35 -07:00
Jorropo
33504a8696 cmd/compile: use prove to remove no-op Ands
This is hit 308 times (unique by LOC) when building the std.

There are many hits in defer generated code.

My original intent was to optimize cryptographic code that
uses And to implement modulus by a power of two but the
number is always smaller than the modulus,
it also works there but there (unsurprisingly) far fewer hits.

Change-Id: Ia7a9a57099b98de966673c6e8231ef09f7c80964
Reviewed-on: https://go-review.googlesource.com/c/go/+/750200
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-27 06:27:30 -07:00
Jorropo
3d4fed3179 cmd/compile: on ARM64 merge shifts into TBZ & TBNZ
Change-Id: I4dff3ba1462848f408257cbadedf202e62d1ea69
Reviewed-on: https://go-review.googlesource.com/c/go/+/750320
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-26 09:09:48 -07:00
Cuong Manh Le
b77fdc333a cmd/compile: skip incomplete types in needWrapper
A recursive pointer type *T may still be a TFORW when the compiler
determines if method wrappers are needed. This leads to an incorrect
decision and triggers an internal compiler error.

Fix this by skipping incomplete types during the method wrapper
generation check.

Fixes #78295

Change-Id: I4005e525e9b076c6656aed5419283c0418edcac6
Reviewed-on: https://go-review.googlesource.com/c/go/+/758922
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-26 09:01:18 -07:00
Jorropo
5edb5d729d cmd/compile: do not invert loops that would overflow or underflow
On the final iteration we need space below start (which becomes end)
such that i-step does not overflow or underflow.

In other words the code used to assume that the last time the loop header
execute `start < i - step` (or `<=`, `>` `>=` based on the loop)
is always false.

And it seems correct since by definition the only way for it to be the
last's loop header execution is when the condition becomes false.

However here is an example with uint (even tho the code doesn't
already support them) to make things simpler:
  start = 1
  i = 2
  step = 100

We do 2 - 100 which should give us 1 < -98 == false breaking the loop;
Instead we get 18446744073709551518 which gives
1 < 18446744073709551518 == true which keeps the loop going.

This patch fixes this issue by ensuring that in the last execution of
a loop header the induction variable does not underflow or overflow.

Fixes #78303

Change-Id: I64e8e8592b023d79fdbc7f1598d584726ed601f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/758801
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-26 09:01:13 -07:00
Cuong Manh Le
286a79658e cmd/compile: fix missing walk for OAS2RECV node
When channel receive operator is used in the context that requires
conversion to destination type, there's an implicit conversion operator
inserted by typecheck. This typecheck-ed node is un-walked, then passing
to the backend as-is, causing the ICE.

Fixes #78313

Change-Id: Ibbc70cbd2d8069cc7cf81934406aa68c4da2686a
Reviewed-on: https://go-review.googlesource.com/c/go/+/758660
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-26 08:54:42 -07:00
Cuong Manh Le
670038a5a5 cmd/compile: preserve variadic signature on range-over-func
When rewriting range-over-func loops, copy the variadic bit from the
original function type into the synthesized body closure's type info.
This keeps the generated closure signature aligned with the source
function and avoids losing variadic-ness during rewrite.

Fixes #78314

Change-Id: I4b5f4628e8c8c14d4ff89dd6b996837264c5cb61
Reviewed-on: https://go-review.googlesource.com/c/go/+/758041
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-25 13:06:06 -07:00
Jayanth Krishnamurthy jayanth.krishnamurthy@ibm.com
cbc2d06c9b cmd/compile: ppc64 fold (x+x)<<c into x<<(c+1)
On ppc64/ppc64le, rewrite (x + x) << c to x << (c+1) for constant shifts. This removes an ADD, shortens the dependency chain, and reduces code size.

Add rules for both 64-bit (SLDconst) and 32-bit (SLWconst), and extend
test/codegen/shift.go with ppc64x checks to assert a single SLD/SLW and
forbid ADD. Aligns ppc64 with other architectures that already assert
similar codegen in shift.go.

Change-Id: Ie564afbb029a5bd48887b82b0c455ca1dddd5508
Cq-Include-Trybots: luci.golang.try:gotip-linux-ppc64_power10,gotip-linux-ppc64_power8,gotip-linux-ppc64le_power8,gotip-linux-ppc64le_power9,gotip-linux-ppc64le_power10
Reviewed-on: https://go-review.googlesource.com/c/go/+/712000
Reviewed-by: Archana Ravindar <aravinda@redhat.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2026-03-25 03:52:03 -07:00
David Chase
c52d784d08 test: repair expected-error regexp in simd.go
The test is only run when GOEXPERIMENT=simd, and currently
there are no trybots for that.  This error was found after
merging to dev.simd, where such trybots ARE run.

To run this test:
```
GOEXPERIMENT=simd go test -run=Test/simd.go -v cmd/internal/testdir -target=darwin/amd64
```
or -target=linux/amd64 if that is your OS.

Change-Id: I70e469f080bc62300ff9c18350cc805985e33f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/758980
Auto-Submit: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2026-03-24 21:34:05 -07:00
Julian Zhu
07f0c2074c test/codegen: add codegen checks for float32/float64 conversions optimizations
Updates #75463

Change-Id: Iec51bdedd5a29bbb81ac553ad7e22403e1715ee3
Reviewed-on: https://go-review.googlesource.com/c/go/+/757300
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-23 07:33:12 -07:00
Keith Randall
c60392da8b Revert "runtime: disable test for 78081"
This reverts commit bfa3dc4028.

Reason for revert: re-enabling the test, after CL 757343 is in.

Change-Id: I78ebb000b95a14f39fc1f62a1013bc83849a0a37
Reviewed-on: https://go-review.googlesource.com/c/go/+/757226
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-20 18:56:10 -07:00
Robert Griesemer
2de90fd48f cmd/compile/internal/noder: don't shoot oneself (fix silly mistake)
When reading multiple promoted fields in a struct literal from UIR,
don't overwrite the (top-level) struct literal type needed for the
next field.

Fixes #78262.
For #9859.

Change-Id: Ifac64537bebcb7dbb79a6173d0cd032cbf0b8ed8
Reviewed-on: https://go-review.googlesource.com/c/go/+/757225
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-20 17:58:12 -07:00
Keith Randall
bfa3dc4028 runtime: disable test for 78081
The stack we're trying to revert for this issue is tripping
on the test for it. The test fails halfway through the revert stack.
Disable it for now, we can re-enable once the whole revert stack is in.

Change-Id: I3bc2d2f069030d865f799a63ad0f267aa667db07
Reviewed-on: https://go-review.googlesource.com/c/go/+/757224
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-20 17:29:41 -07:00
Keith Randall
c8df1410d5 cmd/compile: on arm64 pair a load with a load in a subsequent block
Look into the following block(s) for a load that can be paired with
the load we're trying to pair up.

This particularly helps the generated equality functions. Instead of doing

MOVD x(R0), R2
MOVD x(R1), R3
CMP R2, R3
BNE noteq
MOVD x+8(R0), R2
MOVD x+8(R1), R3
CMP R2, R3
BNE noteq

we do

LDP x(R0), (R2, R4)
LDP x(R1), (R3, R5)
CMP R2, R3
BNE noteq
CMP R4, R5
BNE noteq

Removes 5296 bytes of code from cmd/go.

Change-Id: I6368686892ac944783c8b07ed7252126d1ef4031
Reviewed-on: https://go-review.googlesource.com/c/go/+/740741
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-20 13:51:47 -07:00
Robert Griesemer
30bfe53dd7 cmd/compile: enable promoted field selectors as keys in struct literals
Switch the generated UIR version from V2 to V3.
Adjust cmd/compile/internal/types to accept promoted field selectors
in composite literals.

Fixes #9859.

Change-Id: Ie314e28567cfa6cf4c9e962a07b32dd05b06bf5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/755740
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-19 17:16:38 -07:00
Robert Griesemer
9f7e98d263 go/types, types2: allow promoted field names as keys in struct literals
For #9859.

Change-Id: Ie4823e726ab43fe2ce1e96c279f63dad6c1f9873
Reviewed-on: https://go-review.googlesource.com/c/go/+/751702
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2026-03-19 14:32:21 -07:00
Youlin Feng
8afbae3e51 cmd/compile: allow multiple induction variables in one block in prove
In this CL, the restriction that each block can only have one induction
variable has been removed. This reduces missed optimizations.

Fixes #76269

Change-Id: I14043182a40cc7887c5b6d9c1a5df8ea3a1bfedc
Reviewed-on: https://go-review.googlesource.com/c/go/+/719881
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-18 13:35:03 -07:00
Keith Randall
72327dd645 runtime: add a test for issue 78081
Contrive to have a bunch of stack shrinking going on during
memclrNoHeapPointersPreemptible calls.

Fails at tip with this patch:

--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -2184,6 +2184,7 @@ func reusableSize(size uintptr) bool {
 // Use this with care; if the data being cleared is tagged to contain
 // pointers, this allows the GC to run before it is all cleared.
 func memclrNoHeapPointersChunked(size uintptr, x unsafe.Pointer) {
+       y := uintptr(x)
        if getg().preempt {
                // TODO: no need for this, except to test that
                // the preemption point is ok for small zeroings.
@@ -2193,6 +2194,7 @@ func memclrNoHeapPointersChunked(size uintptr, x unsafe.Pointer) {
                // may hold locks, e.g., profiling
                goschedguarded()
        }
+       x = unsafe.Pointer(y)
        // got this from benchmarking. 128k is too small, 512k is too large.
        const chunkBytes = 256 * 1024
        for size > chunkBytes {

Update #78081

Change-Id: Id8f87a4b0d0970cbf971c90ab87703a9e5b3f121
Reviewed-on: https://go-review.googlesource.com/c/go/+/755942
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-18 09:19:06 -07:00
Meng Zhuo
f3966c1ada cmd/compile: (riscv64) optimize float32(abs|sqrt64(float64(x)))
Absorb unnecessary conversion between float32 and float64
if both src and dst are 32 bit.

Updates #75463

Change-Id: Ia71941223b5cca3fea66b559da7b8f916e63feaf
Reviewed-on: https://go-review.googlesource.com/c/go/+/733621
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Julian Zhu <jz531210@gmail.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-16 17:15:04 -07:00
Junyang Shao
9ce4f3876e cmd/compile: keep blank nodes alive in b.loop
The current bloop pass implementation skips blank nodes silently. This
CL makes it aware of that and keep them alive in temps.

Fixes #77654.

Change-Id: Iaffa5194ba1f0fe8d7c80a4c8e5c9a65a47bf534
Reviewed-on: https://go-review.googlesource.com/c/go/+/754920
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-13 09:03:37 -07:00
Oliver Eikemeier
45c6fb4b9b cmd/compile: unwrap OCONVIFACE in staticinit for OAS2
Static initialization only expected OCONVNOP wrappings.
Unwrap OCONVIFACE too, since it occurs when multiple return values
of an OAS2FUNC are implicitly converted to an interface.

Fixes #78016

Change-Id: Ic3fd6151403aabfc087d3240c1fcfabe7108cc0e
GitHub-Last-Rev: 98976d9e64
GitHub-Pull-Request: golang/go#78017
Reviewed-on: https://go-review.googlesource.com/c/go/+/752780
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-10 20:51:48 -07:00
dorbmon
38ac6577cb cmd/compile: forward small Load through Move to avoid redundant copies
Fixes #77720

Add a generic SSA rewrite that forwards `Load` from a `Move` destination
back to the `Move` source when it is provably safe, so field reads like
`s.h.Value().typ` don’t force a full struct copy.

- Add `Load <- Move` rewrite in `generic.rules` with safety guard:
  non-volatile source
- Tweak `fixedbugs/issue22200*` so that it can still trigger the "stack frame too large" error.
- Regenerate `rewritegeneric.go`.
- Add `test/codegen/moveload.go` to assert no `MOVUPS` and direct `MOVBLZX`
  in both direct and inlined forms.

Benchmark results (linux/amd64, i7-14700KF):

$ go test cmd/compile/internal/test -run='^$' -bench='MoveLoad' -count=20

Before:
  BenchmarkMoveLoadTypViaValue-20  ~76.9 ns/op
  BenchmarkMoveLoadTypViaPtr-20    ~1.97 ns/op

After:
  BenchmarkMoveLoadTypViaValue-20  ~1.894 ns/op
  BenchmarkMoveLoadTypViaPtr-20    ~1.905 ns/op

The rewrite removes the redundant struct copy in
`s.h.Value().typ`, bringing it in line with the direct pointer form.

Change-Id: Iddf2263e390030ba013e0642a695b87c75f899da
Reviewed-on: https://go-review.googlesource.com/c/go/+/748200
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Mark Freeman <markfreeman@google.com>
2026-03-10 20:06:05 -07:00
Cuong Manh Le
28b1d8886b cmd/compile: fix ICE when checking slice cap
CL 226737 optimized len check when make slice in common case when len is
within range of cap. However, the generated code does not walk the AST
for the if condition, causing un-walked nodes passed to the backend.

Fixes #78028

Change-Id: I492fb230c10e585dc09391728ef4df2c0058ce12
Reviewed-on: https://go-review.googlesource.com/c/go/+/753100
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-10 04:42:57 -07:00
qmuntal
b0057a4e0c test/fixedbugs: increase issue46234 test timeout
issue46234 is flaky on slow machines, so increase the timeout to 90s.

Note that that test timeout already got increased from 30s to 45s in
CL 382774, but it was still not enough.

Fixes #50973
Fixes #67558
Fixes #74277
Updates #65040

Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14
Change-Id: I809249a05c6ca65fb6c44375c8de5758f21dbb91
Reviewed-on: https://go-review.googlesource.com/c/go/+/747520
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-10 00:37:14 -07:00
Robert Griesemer
e84da0405b cmd/compile, go/*: allow generic methods starting with Go 1.27
This only changes the type checkers and tests.
Backend compiler changes are not included.

For #77273.

Change-Id: I8cf0b6fddf6afd6b08b06ba6fdf9c726af4bea8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/746820
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
2026-03-09 12:16:20 -07:00
Joel Sing
3a29ebeef9 cmd/compile: additional optimisation for CZEROEQZ/CZERONEZ on riscv64
Negation on a condition can be eliminated.

Change-Id: I94fab5f019cbaebb2ca589e1d8796a9cb72f3894
Reviewed-on: https://go-review.googlesource.com/c/go/+/748401
Reviewed-by: Xueqi Luo <1824368278@qq.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Julian Zhu <jz531210@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
2026-03-06 14:39:32 -08:00
Jorropo
426ea5cd22 test: run go fmt on prove.go
Change-Id: I87e493094778144c04298ae96322adf0d4e7eba4
Reviewed-on: https://go-review.googlesource.com/c/go/+/750340
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2026-03-06 13:03:28 -08:00
Cuong Manh Le
bf1b0973db cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.

Fixed #77919

Change-Id: Ibc137c84792d4898eb073cdeabac175684f73746
Reviewed-on: https://go-review.googlesource.com/c/go/+/751040
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2026-03-06 10:31:11 -08:00
Keith Randall
e7a09d1ffb cmd/compile: use tail calls for wrappers for embedded interfaces
type I interface {
    foo()
}

type S struct {
    I
}

Because I is embedded in S, S needs a foo method.  We generate a
wrapper function to implement (*S).foo.  It just loads the embedded
field I out of S and calls foo on it.

When the thing in S.I itself needs a wrapper, then we have a wrapper
calling another wrapper. This can continue, leaving a potentially long
sequence of wrappers on the stack. When we then call runtime.Callers
or friends, we have to walk an unbounded number of frames to find a
bounded number of non-wrapper frames.

This really happens, for instance with I = context.Context, S =
context.ValueCtx, and runtime.Callers = pprof sample (for any of
context.Context's methods).

To fix, make the interface call in the wrapper a tail call.
That way, the number of wrapper frames on the stack does not
increase when there are lots of wrappers happening.

Fixes #75764
Fixes #77781

Change-Id: I03b1731159d9218c7f14f72ecbbac822d6a6bb87
Reviewed-on: https://go-review.googlesource.com/c/go/+/751465
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-06 10:28:08 -08:00
Mateusz Poliwczak
b16360470c cmd/compile: fix ICE when indexing zero-sized arrays of non-SSAable types
Fixes #77868

Change-Id: I3348825e24a71595c514113497db365a6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/749881
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
2026-03-04 13:26:19 -08:00
Junyang Shao
aa80d7a7e6 cmd/compile, simd/archsimd: add VPSRL immeidate peepholes
Before this CL, the simdgen contains a sign check to selectively enable
such rules for deduplication purposes. This left out `VPSRL` as it's
only available in unsigned form. This CL fixes that.

It looks like the previous documentation fix to SHA instruction might
not had run go generate, so this CL also contains the generated code for
that fix.

There is also a weird phantom import in
cmd/compile/internal/ssa/issue77582_test.go
This CL also fixes that

The trybot didn't complain?

Change-Id: Ibbf9f789c1a67af1474f0285ab376bc07f17667e
Reviewed-on: https://go-review.googlesource.com/c/go/+/748501
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
2026-03-02 12:07:34 -08:00
David Chase
d51d4d75a6 cmd/compile: (wasm) optimize float32(round64(float64(x)))
Not a fix because there are other architectures
still to be done.

Updates #75463.

Change-Id: Ia5233c2b6c5f4439e269950efdd851e72e8e7ff6
Reviewed-on: https://go-review.googlesource.com/c/go/+/730160
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-01 11:58:20 -08:00
David Chase
425a88193c cmd/compile: (arm64) optimize float32(round64(float64(x)))
Not a fix because there are other architectures
still to be done.

Updates #75463.

Change-Id: Ifca03975023e4e5d0ffa98d1f877314a1a291be0
Reviewed-on: https://go-review.googlesource.com/c/go/+/729161
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-01 11:58:06 -08:00
David Chase
7336381cd1 cmd/compile: (amd64) optimize float32(round64(float64(x)))
Not a fix because there are other architectures
still to be done.

Updates #75463.

Change-Id: I3d7754ce4a26af0f5c4ef0be1254d164e68f8442
Reviewed-on: https://go-review.googlesource.com/c/go/+/729160
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-01 08:20:35 -08:00