Skip to content

cmd/compile: rematerializable ops must not clobber flags #21080

@mundaym

Description

@mundaym

While debugging #21048 I noticed that there was a conditional jump immediately after a MOVDaddr instruction. This shouldn't happen because MOVDaddr clobbers flags on s390x.

Digging deeper it looks to me like flagalloc is silently failing in runtime.gcDrain. The problem is reproducible on darwin/amd64.

If you do:

GOSSAFUNC=gcDrain go install -a runtime

And look at the generated ssa.html after the regalloc phase you'll see this:

b3: ← b1
    v17 = LoweredGetG <*g> v1 : AX
    v20 = MOVQload <*m> [48] v17 v1 : AX
    v23 = MOVQload <*g> [152] v20 v1 : AX
    v122 = StoreReg <*g> v23 : gp[*g]
    v142 = LoadReg <*gcWork> v6 : CX
    v41 = MOVQload <int64> [24] v142 v1 : DX
    v46 = MOVLload <uint32> {"".work} [136] v3 v1 : BX
    v49 = MOVLload <uint32> {"".work} [140] v3 v1 : SI
    v187 = LoadReg <gcDrainFlags> v7 : DI
    v18 = BTLconst <flags> [0] v187    <===== v18 SET
    v356 = BTLconst <flags> [2] v187   <===== v18 CLOBBERED
    v234 = BTLconst <flags> [3] v187
    v197 = CMPL <flags> v46 v49
ULT v197 → b4 b48

b4: ← b3
    v204 = StoreReg <int64> v41 : initScanWork[int64]
    v100 = BTLconst <flags> [0] v187
Plain → b6

b6: ← b4 b8
    v365 = Phi <mem> v1 v366
ULT v18 → b10 b40                      <==== v18 USED

v18 is clobbered immediately. v356 and v234 are generated but immediately clobbered. All these BTL instructions make it into the final assembly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions