Skip to content

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

Closed

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

Activity

  1. prattmic commented on Feb 14, 2023

    @prattmic
    Member

    cc @golang/compiler

  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Feb 14, 2023
  3. added this to the Go1.21 milestone on Feb 14, 2023
  4. gopherbot commented on Feb 15, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/468455 mentions this issue: cmd/compile: schedule SP earlier

  5. self-assigned this
    on Feb 15, 2023
  6. gopherbot commented on Feb 15, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/468615 mentions this issue: cmd/compile: ensure constant folding of pointer arithmetic remains a pointer

  7. gopherbot commented on Feb 16, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/468695 mentions this issue: cmd/compile: ensure InitMem comes after Args

  8. added 3 commits that reference this issue on Feb 22, 2023
    e3648b6
    dd3dc84
    d55101b
  9. locked and limited conversation to collaborators on Feb 16, 2024
  10. added a commit that references this issue on Sep 29, 2026
    40ed359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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