go/test/codegen
Cherry Mui 220d73cc44 [dev.simd] all: merge master (8dd5b13) into dev.simd
Merge List:

+ 2025-11-24 8dd5b13abc cmd/compile: relax stmtline_test on amd64
+ 2025-11-23 feae743bdb cmd/compile: use 32x32->64 multiplies on loong64
+ 2025-11-23 e88be8a128 runtime: fix stale comment for mheap/malloc
+ 2025-11-23 a318843a2a cmd/internal/obj/loong64: optimize duplicate optab entries
+ 2025-11-23 a18294bb6a cmd/internal/obj/arm64, image/gif, runtime, sort: use math/bits to calculate log2
+ 2025-11-23 437323ef7b slices: fix incorrect comment in slices.Insert function documentation
+ 2025-11-23 1993dca400 doc/next: pre-announce end of support for macOS 12 in Go 1.27
+ 2025-11-22 337f7b1f5d cmd/go: update default go directive in mod or work init
+ 2025-11-21 3c26aef8fb cmd/internal/obj/riscv: improve large branch/call/jump tests
+ 2025-11-21 31aa9f800b crypto/tls: use inner hello for earlyData when using QUIC and ECH
+ 2025-11-21 d68aec8db1 runtime: replace trace seqlock with write flag
+ 2025-11-21 8d9906cd34 runtime/trace: add Log benchmark
+ 2025-11-21 6aeacdff38 cmd/go: support sha1 repos when git default is sha256
+ 2025-11-21 9570036ca5 crypto/sha3: make the zero value of SHAKE useable
+ 2025-11-21 155efbbeeb crypto/sha3: make the zero value of SHA3 useable
+ 2025-11-21 6f16669e34 database/sql: don't ignore ColumnConverter for unknown input count
+ 2025-11-21 121bc3e464 runtime/pprof: remove hard-coded sleep in CPU profile reader
+ 2025-11-21 b604148c4e runtime: fix double wakeup in CPU profile buffer
+ 2025-11-21 22f24f90b5 cmd/compile: change testing.B.Loop keep alive semantic
+ 2025-11-21 cfb9d2eb73 net: remove unused linknames
+ 2025-11-21 65ef314f89 net/http: remove unused linknames
+ 2025-11-21 0f32fbc631 net/http: populate Response.Request when using NewFileTransport
+ 2025-11-21 3e0a8e7867 net/http: preserve original path encoding in redirects
+ 2025-11-21 831af61120 net/http: use HTTP 307 redirects in ServeMux
+ 2025-11-21 87269224cb net/http: update Response.Request.URL after redirects on GOOS=js
+ 2025-11-21 7aa9ca729f net/http/cookiejar: treat localhost as secure origin
+ 2025-11-21 f870a1d398 net/url: warn that JoinPath arguments should be escaped
+ 2025-11-21 9962d95fed crypto/internal/fips140/mldsa: unroll NTT and inverseNTT
+ 2025-11-21 f821fc46c5 crypto/internal/fisp140test: update acvptool, test data
+ 2025-11-21 b59efc38a0 crypto/internal/fips140/mldsa: new package
+ 2025-11-21 62741480b8 runtime: remove linkname for gopanic
+ 2025-11-21 7db2f0bb9a crypto/internal/hpke: separate KEM and PublicKey/PrivateKey interfaces
+ 2025-11-21 e15800c0ec crypto/internal/hpke: add ML-KEM and hybrid KEMs, and SHAKE KDFs
+ 2025-11-21 7c985a2df4 crypto/internal/hpke: modularize API and support more ciphersuites
+ 2025-11-21 e7d47ac33d cmd/compile: simplify negative on multiplication
+ 2025-11-21 35d2712b32 net/http: fix typo in Transport docs
+ 2025-11-21 90c970cd0f net: remove unnecessary loop variable copies in tests
+ 2025-11-21 9772d3a690 cmd/cgo: strip top-level const qualifier from argument frame struct
+ 2025-11-21 1903782ade errors: add examples for custom Is/As matching
+ 2025-11-21 ec92bc6d63 cmd/compile: rewrite Rsh to RshU if arguments are proved positive
+ 2025-11-21 3820f94c1d cmd/compile: propagate unsigned relations for Rsh if arguments are positive
+ 2025-11-21 d474f1fd21 cmd/compile: make dse track multiple shadowed ranges
+ 2025-11-21 d0d0a72980 cmd/compile/internal/ssa: correct type of ARM64 conditional instructions
+ 2025-11-21 a9704f89ea internal/runtime/gc/scan: add AVX512 impl of filterNil.
+ 2025-11-21 ccd389036a cmd/internal/objabi: remove -V=goexperiment internal special case
+ 2025-11-21 e7787b9eca runtime: go fmt
+ 2025-11-21 17b3b98796 internal/strconv: go fmt
+ 2025-11-21 c851827c68 internal/trace: go fmt
+ 2025-11-21 f87aaec53d cmd/compile: fix integer overflow in prove pass
+ 2025-11-21 dbd2ab9992 cmd/compile/internal: fix typos
+ 2025-11-21 b9d86baae3 cmd/compile/internal/devirtualize: fix typos
+ 2025-11-20 4b0e3cc1d6 cmd/link: support loading R_LARCH_PCREL20_S2 and R_LARCH_CALL36 relocs
+ 2025-11-20 cdba82c7d6 cmd/internal/obj/loong64: add {,X}VSLT.{B/H/W/V}{,U} instructions support
+ 2025-11-20 bd2b117c2c crypto/tls: add QUICErrorEvent
+ 2025-11-20 3ad2e113fc net/http/httputil: wrap ReverseProxy's outbound request body so Close is a noop
+ 2025-11-20 d58b733646 runtime: track goroutine location until actual STW
+ 2025-11-20 1bc54868d4 cmd/vendor: update to x/tools@68724af
+ 2025-11-20 8c3195973b runtime: disable stack allocation tests on sanitizers
+ 2025-11-20 ff654ea100 net/url: permit colons in the host of postgresql:// URLs
+ 2025-11-20 a662badab9 encoding/json: remove linknames
+ 2025-11-20 5afe237d65 mime: add missing path for mime types in godoc
+ 2025-11-20 c1b7112af8 os/signal: make NotifyContext cancel the context with a cause

Change-Id: Ib93ef643be610dfbdd83ff45095a7b1ca2537b8b
2025-11-24 11:03:06 -05:00
..
addrcalc.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
alloc.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
append.go cmd/compile: stack allocate backing stores during append 2025-11-20 09:19:39 -08:00
arithmetic.go cmd/compile: use 32x32->64 multiplies on loong64 2025-11-23 23:54:44 -08:00
atomics.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
bitfield.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
bits.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
bmi.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
bool.go cmd/compile: fold boolean NOT into branches 2025-11-18 09:31:58 -08:00
clobberdead.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
clobberdeadreg.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
compare_and_branch.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
comparisons.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
condmove.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
constants.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
copy.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
divmod.go cmd/compile: implement Avg64u, Hmul64, Hmul64u for wasm 2025-11-04 11:38:18 -08:00
floats.go cmd/compile: use FCLASSD for subnormal checks on riscv64 2025-11-12 10:03:41 -08:00
fuse.go cmd/compile: optimize comparisons with single bit difference 2025-11-14 10:59:56 -08:00
generics.go cmd/compile: eliminate nil checks on .dict arg 2025-09-30 11:22:35 -07:00
ifaces.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
issue22703.go test: port a nil-check interface test from asm_test 2018-03-03 20:20:54 +00:00
issue25378.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
issue31618.go cmd/compile: always mark atColumn1 results as statements 2019-04-23 17:39:11 +00:00
issue33580.go cmd/compile: reuse dead register before reusing register holding constant 2019-10-07 15:16:26 +00:00
issue38554.go cmd/compile: optimize Move with all-zero ro sym src to Zero 2020-04-24 23:58:10 +00:00
issue42610.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
issue48054.go test/codegen: fix package name for test case 2021-09-08 14:51:40 +00:00
issue52635.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
issue54467.go cmd/compile: use stricter rule for possible partial overlap 2022-09-27 20:09:33 +00:00
issue56440.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
issue58166.go cmd/compile: rename some test packages in codegen 2025-03-27 13:54:37 -07:00
issue59297.go cmd/compile: regalloc: drop values that aren't used until after a call 2024-08-26 22:29:43 +00:00
issue60324.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
issue60673.go cmd/compile: use callsite as line number for argument marshaling 2023-06-12 20:34:37 +00:00
issue61356.go cmd/compile: get rid of special case in scheduler for entry block 2023-07-26 17:19:14 +00:00
issue63332.go cmd/compile/internal/walk: copy SSA-able variables 2023-11-21 20:34:12 +00:00
issue66585.go cmd/compile: rename some test packages in codegen 2025-03-27 13:54:37 -07:00
issue68845.go cmd/compile: improve unneeded zeroing removal 2024-08-14 18:16:29 +00:00
issue69635.go cmd/compile: add shift optimization test 2024-10-25 15:35:29 +00:00
issue70409.go cmd/compile: do not treat OpLocalAddr as load in DSE 2025-02-04 12:52:01 -08:00
issue72832.go cmd/compile: fix offset calculation error in memcombine 2025-05-21 12:17:08 -07:00
issue74485.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
issue74788.go cmd/compile: soften test for 74788 2025-08-12 10:05:55 -07:00
issue75203.go cmd/compile/internal/ssa: load constant values from abi.PtrType.Elem 2025-09-04 07:25:26 -07:00
load_type_from_itab.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
logic.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
mapaccess.go cmd/compile: stop using VARKILL 2022-08-18 17:36:38 +00:00
maps.go cmd/compile/internal/ssa: more aggressive on dead auto elim 2025-11-04 12:46:15 -08:00
math.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
mathbits.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
memcombine.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
memops.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
memops_bigoffset.go cmd/compile: update rules to generate more prefixed instructions 2023-05-15 18:20:54 +00:00
multiply.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
noextend.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
race.go cmd/compile: remove racefuncenterfp when it is not needed 2020-11-02 03:03:16 +00:00
README cmd/compile: deduplicate instructions when rewrite func results 2025-07-30 09:38:10 -07:00
reflect_type.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
regabi_regalloc.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
retpoline.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
rotate.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
schedule.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
select.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
shift.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
shortcircuit.go cmd/compile: handle some additional phis in shortcircuit 2020-04-08 22:13:38 +00:00
simd.go [dev.simd] simd: update CPU feature APIs 2025-11-17 13:37:30 -08:00
slices.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
smallintiface.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
spectre.go test: migrate remaining files to go:build syntax 2023-10-19 23:33:25 +00:00
spills.go cmd/compile: use STP/LDP around morestack on arm64 2024-10-22 16:23:12 +00:00
stack.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
strings.go test: fix tests to work with sizespecializedmalloc turned off 2025-11-13 16:57:31 -08:00
structs.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
switch.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
typeswitch.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00
unique.go cmd/compile/internal/ssa: eliminate string copies for calls to unique.Make 2025-05-21 20:20:31 -07:00
unsafe.go cmd/compile: pull multiple adds out of an unsafe.Pointer<->uintptr conversion 2024-11-21 22:57:04 +00:00
writebarrier.go cmd/compile: make write barrier code amenable to paired loads/stores 2025-02-13 14:08:14 -08:00
zerosize.go test/codegen: simplify asmcheck pattern matching 2025-10-29 13:55:00 -07:00

// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

The codegen directory contains code generation tests for the gc
compiler.


- Introduction

The test harness compiles Go code inside files in this directory and
matches the generated assembly (the output of `go tool compile -S`)
against a set of regexps to be specified in comments that follow a
special syntax (described below). The test driver is implemented as
an action within the GOROOT/test test suite, called "asmcheck".

The codegen harness is part of the all.bash test suite, but for
performance reasons only the codegen tests for the host machine's
GOARCH are enabled by default, and only on GOOS=linux.

To perform comprehensive tests for all the supported architectures
(even on a non-Linux system), one can run the following command:

  $ ../../bin/go test cmd/internal/testdir -run='Test/codegen' -all_codegen -v

This is recommended after any change that affect the compiler's code.

The test harness compiles the tests with the same go toolchain that is
used to run the test. After writing tests for a newly added codegen
transformation, it can be useful to first run the test harness with a
toolchain from a released Go version (and verify that the new tests
fail), and then re-running the tests using the devel toolchain.


- Regexps comments syntax

Instructions to match are specified inside plain comments that start
with an architecture tag, followed by a colon and a quoted Go-style
regexp to be matched. For example, the following test:

  func Sqrt(x float64) float64 {
  	   // amd64:"SQRTSD"
  	   // arm64:"FSQRTD"
  	   return math.Sqrt(x)
  }

verifies that math.Sqrt calls are intrinsified to a SQRTSD instruction
on amd64, and to a FSQRTD instruction on arm64.

It is possible to put multiple architectures checks into the same
line, as:

  // amd64:"SQRTSD" arm64:"FSQRTD"

although this form should be avoided when doing so would make the
regexps line excessively long and difficult to read.

Comments that are on their own line will be matched against the first
subsequent non-comment line. Inline comments are also supported; the
regexp will be matched against the code found on the same line:

  func Sqrt(x float64) float64 {
  	   return math.Sqrt(x) // arm:"SQRTD"
  }

It's possible to specify a comma-separated list of regexps to be
matched. For example, the following test:

  func TZ8(n uint8) int {
  	   // amd64:"BSFQ","ORQ\t\\$256"
  	   return bits.TrailingZeros8(n)
  }

verifies that the code generated for a bits.TrailingZeros8 call on
amd64 contains both a "BSFQ" instruction and an "ORQ $256".

Note how the ORQ regex includes a tab char (\t). In the Go assembly
syntax, operands are separated from opcodes by a tabulation.

Regexps can be quoted using either " or `. Special characters must be
escaped accordingly. Both of these are accepted, and equivalent:

  // amd64:"ADDQ\t\\$3"
  // amd64:`ADDQ\t\$3`

and they'll match this assembly line:

  ADDQ	$3

Negative matches can be specified using a - before the quoted regexp.
For example:

  func MoveSmall() {
  	   x := [...]byte{1, 2, 3, 4, 5, 6, 7}
  	   copy(x[1:], x[:]) // arm64:-".*memmove"
  }

verifies that NO memmove call is present in the assembly generated for
the copy() line.

The expected number of matches for the regexp can be specified using a
positive number:

  func fb(a [4]int) (r [4]int) {
  	   // amd64:2`MOVUPS[^,]+, X0$`,2`MOVUPS\sX0,[^\n]+$`
  	   return a
  }

- Architecture specifiers

There are three different ways to specify on which architecture a test
should be run:

* Specify only the architecture (eg: "amd64"). This indicates that the
  check should be run on all the supported architecture variants. For
  instance, arm checks will be run against all supported GOARM
  variations (5,6,7).
* Specify both the architecture and a variant, separated by a slash
  (eg: "arm/7"). This means that the check will be run only on that
  specific variant.
* Specify the operating system, the architecture and the variant,
  separated by slashes (eg: "plan9/386/sse2", "plan9/amd64/"). This is
  needed in the rare case that you need to do a codegen test affected
  by a specific operating system; by default, tests are compiled only
  targeting linux.


- Remarks, and Caveats

-- Write small test functions

As a general guideline, test functions should be small, to avoid
possible interactions between unrelated lines of code that may be
introduced, for example, by the compiler's optimization passes.

Any given line of Go code could get assigned more instructions than it
may appear from reading the source. In particular, matching all MOV
instructions should be avoided; the compiler may add them for
unrelated reasons and this may render the test ineffective.

-- Line matching logic

Regexps are always matched from the start of the instructions line.
This means, for example, that the "MULQ" regexp is equivalent to
"^MULQ" (^ representing the start of the line), and it will NOT match
the following assembly line:

  IMULQ	$99, AX

To force a match at any point of the line, ".*MULQ" should be used.

For the same reason, a negative regexp like -"memmove" is not enough
to make sure that no memmove call is included in the assembly. A
memmove call looks like this:

  CALL	runtime.memmove(SB)

To make sure that the "memmove" symbol does not appear anywhere in the
assembly, the negative regexp to be used is -".*memmove".