Skip to content

cmd/compile: instruction reordering with optimizations disabled (go1.21)  #58482

@aarzilli

Description

@aarzilli

The function main.Foo in teststepconcurrent.go compiled with -gcflags=-N -l now produces:

teststepconcurrent.go:13	SP	0x482c80	4883ec10	SUBQ $0x10, SP
teststepconcurrent.go:13		0x482c84	48896c2408	MOVQ BP, 0x8(SP)
teststepconcurrent.go:13		0x482c89	488d6c2408	LEAQ 0x8(SP), BP
teststepconcurrent.go:15	S	0x482c8e	488d0c18	LEAQ 0(AX)(BX*1), CX
teststepconcurrent.go:13	S	0x482c92	4889442418	MOVQ AX, 0x18(SP)
teststepconcurrent.go:13		0x482c97	48895c2420	MOVQ BX, 0x20(SP)
teststepconcurrent.go:13		0x482c9c	48c7042400000000	MOVQ $0x0, 0(SP)
teststepconcurrent.go:15		0x482ca4	48890c24	MOVQ CX, 0(SP)
teststepconcurrent.go:16	S	0x482ca8	4889c8	MOVQ CX, AX
teststepconcurrent.go:16		0x482cab	488b6c2408	MOVQ 0x8(SP), BP
teststepconcurrent.go:16		0x482cb0	4883c410	ADDQ $0x10, SP
teststepconcurrent.go:16		0x482cb4	c3	RET

The block of instructions assigned to the function header (:13) after the (LEAQ) addition is unfortunate.
Before it used to be:

teststepconcurrent.go:13	SP	0x482ac0	4883ec10	SUBQ $0x10, SP
teststepconcurrent.go:13		0x482ac4	48896c2408	MOVQ BP, 0x8(SP)
teststepconcurrent.go:13		0x482ac9	488d6c2408	LEAQ 0x8(SP), BP
teststepconcurrent.go:13		0x482ace	4889442418	MOVQ AX, 0x18(SP)
teststepconcurrent.go:13		0x482ad3	48895c2420	MOVQ BX, 0x20(SP)
teststepconcurrent.go:13		0x482ad8	48c7042400000000	MOVQ $0x0, 0(SP)
teststepconcurrent.go:15	S	0x482ae0	4801d8	ADDQ BX, AX
teststepconcurrent.go:15		0x482ae3	48890424	MOVQ AX, 0(SP)
teststepconcurrent.go:16	S	0x482ae7	488b6c2408	MOVQ 0x8(SP), BP
teststepconcurrent.go:16		0x482aec	4883c410	ADDQ $0x10, SP
teststepconcurrent.go:16		0x482af0	c3	RET

This was introduced by 12befc3 (cmd/compile: improve scheduling pass). cc @randall77 @dr2chase

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions