go/test/codegen
limeidan bd71b94659 cmd/compile/internal: optimizing add+sll rule using ALSLV instruction on loong64
Reduce the number of go toolchain instructions on loong64 as follows:

	file	    before	after	    Δ 	     %
	go	    1573148	1571708	   -1,440  -0.0915%
	gofmt	    320578	320090	   -488    -0.1522%
	asm	    555066	554406	   -660    -0.1189%
	cgo	    481566	480926	   -640    -0.1329%
	compile	    2475962	2473880	   -2,082  -0.0841%
	cover	    516536	515920	   -616    -0.1193%
	link	    702172	701404	   -768    -0.1094%
	preprofile  238626	238274	   -352    -0.1475%
	vet	    792928	792100	   -828    -0.1044%

Change-Id: I61e462726835959c60e1b4e5256d4020202418ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/693877
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
2025-08-25 12:30:16 -07:00
..
addrcalc.go cmd/compile: use ADDQ instead of LEAQ when we can 2020-02-24 21:33:53 +00:00
alloc.go cmd/compile: don't generate newobject call for 0-sized types 2019-02-26 23:08:15 +00:00
arithmetic.go cmd/compile/internal: optimizing add+sll rule using ALSLV instruction on loong64 2025-08-25 12:30:16 -07:00
atomics.go cmd/compile: make sync/atomic AND/OR operations intrinsic on amd64 2024-07-23 21:29:38 +00:00
bitfield.go cmd/compile: use zero register instead of specialized *zero instructions on loong64 2025-08-21 11:23:05 -07:00
bits.go cmd/compile: add rules about ORN and ANDN 2025-05-21 08:28:37 -07:00
bmi.go cmd/compile: AMD64v3 remove unnecessary TEST comparision in isPowerOfTwo 2023-01-20 04:58:59 +00:00
bool.go cmd/compile: add 2 phiopt cases 2025-05-08 10:18:37 -07:00
clobberdead.go test: migrate remaining files to go:build syntax 2023-10-19 23:33:25 +00:00
clobberdeadreg.go test: migrate remaining files to go:build syntax 2023-10-19 23:33:25 +00:00
compare_and_branch.go cmd/compile/internal/ssa: optimise more branches with zero on riscv64 2025-03-28 01:27:22 -07:00
comparisons.go cmd/compile: on AMD64, turn x < 128 into x <= 127 2025-02-16 07:23:13 -08:00
condmove.go test/codegen: fix failing condmove wasm tests 2025-07-28 11:01:53 -07:00
constants.go cmd/internal/obj/ppc64: generate MOVD mask constants in register 2023-10-05 14:03:32 +00:00
copy.go cmd/compile: add loong64-specific inlining for runtime.memmove 2024-11-05 00:44:11 +00:00
floats.go test/codegen: add Mul2 and DivPow2 test for loong64 2025-08-24 18:14:28 -07:00
fuse.go cmd/compile: allow InlMark operations to be speculatively executed 2025-08-11 00:52:23 -07:00
ifaces.go cmd/compile: avoid ifaceeq call if we know the interface is direct 2025-02-10 13:28:41 -08:00
issue22703.go test: port a nil-check interface test from asm_test 2018-03-03 20:20:54 +00:00
issue25378.go test: make codegen tests work with both ABIs 2021-04-12 21:59:59 +00: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 cmd/compile: use generated loops instead of DUFFZERO on amd64 2025-07-31 17:12:39 -07:00
issue54467.go cmd/compile: use stricter rule for possible partial overlap 2022-09-27 20:09:33 +00:00
issue56440.go cmd/compile: rename some test packages in codegen 2025-03-27 13:54:37 -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 cmd/compile: incorporate inlined function names into closure naming 2023-05-22 22:47:15 +00: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 cmd/compile: use unsigned power-of-two detector for unsigned mod 2025-07-29 16:22:40 -07:00
issue74788.go cmd/compile: soften test for 74788 2025-08-12 10:05:55 -07:00
load_type_from_itab.go cmd/compile: load properly constant values from itabs 2025-02-19 13:39:00 -08:00
logic.go cmd/compile: add De Morgan's rewrite rule 2023-05-10 16:32:25 +00:00
mapaccess.go cmd/compile: stop using VARKILL 2022-08-18 17:36:38 +00:00
maps.go cmd/compile: move []byte->string map key optimization to ssa 2025-02-13 13:03:07 -08:00
math.go test/codegen: add sqrt* abs and copysign test for loong64 2025-08-24 18:14:13 -07:00
mathbits.go test/codegen: add Mul* test for loong64 2025-08-24 18:14:22 -07:00
memcombine.go cmd/compile: allow load-op merging in additional situations 2025-05-15 15:21:36 -07:00
memops.go cmd/compile: don't use BTS when OR works, add direct memory BTS operations 2023-08-04 16:40:24 +00:00
memops_bigoffset.go cmd/compile: update rules to generate more prefixed instructions 2023-05-15 18:20:54 +00:00
multiply.go cmd/compile: use zero register instead of specialized *zero instructions on loong64 2025-08-21 11:23:05 -07:00
noextend.go all: remove newline characters after return statements 2023-12-14 17:22:18 +00: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
regabi_regalloc.go cmd/compile: reduce redundant register moves for regabi calls 2021-04-19 16:21:39 +00:00
retpoline.go test: migrate remaining files to go:build syntax 2023-10-19 23:33:25 +00:00
rotate.go cmd/compile,cmd/internal/obj: provide rotation pseudo-instructions for riscv64 2024-03-07 14:57:07 +00:00
schedule.go cmd/compile: schedule induction variable increments late 2025-05-15 14:06:41 -07:00
select.go cmd/compile: set LocalPkg.Path to -p flag 2022-05-16 18:19:47 +00:00
shift.go cmd/compile: use zero register instead of specialized *zero instructions on loong64 2025-08-21 11:23:05 -07:00
shortcircuit.go cmd/compile: handle some additional phis in shortcircuit 2020-04-08 22:13:38 +00:00
slices.go cmd/compile: fold shift through AND for slice operations 2025-07-24 13:47:20 -07:00
smallintiface.go cmd/compile: use staticuint64s instead of staticbytes 2020-03-04 21:43:01 +00: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 cmd/compile: improve store-to-load forwarding with compatible types 2025-04-04 08:25:47 -07:00
strings.go cmd/compile: optimize []byte(string1 + string2) 2024-09-10 21:20:57 +00:00
structs.go test: migrate remaining files to go:build syntax 2023-10-19 23:33:25 +00:00
switch.go cmd/compile: implement signed loads from read-only memory 2025-02-13 12:27:55 -08:00
typeswitch.go cmd/compile: optimize type switch for a single runtime known type with a case var 2024-10-25 02:56:11 +00: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 cmd/compile/internal/walk: convert composite literals to interfaces without allocating 2025-05-21 12:23:26 -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".