Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: OpAMD64CMOV*EQF clobbers AX, doesn't tell regalloc #26097

Closed
heschi opened this issue Jun 27, 2018 · 3 comments
Closed

cmd/compile: OpAMD64CMOV*EQF clobbers AX, doesn't tell regalloc #26097

heschi opened this issue Jun 27, 2018 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@heschi
Copy link
Contributor

heschi commented Jun 27, 2018

CL 98695 (commit 080187f) adds OpAMD64CMOV{Q,L,W}EQF. The generated assembly looks like:

// MOV SRC,AX
// CMOV*NE DST,AX
// CMOV*PC AX,DST

That is, it uses AX as a scratch register so that it can check both equality and NAN-ness. (I think.) The problem is, regalloc doesn't know about this:
{name: "CMOVLEQF", argLength: 3, reg: gp21, asm: "CMOVLNE", resultInArg0: true},

gp21 doesn't have clobbers:ax.

I don't have a public repro, but given the below assembly I'm pretty sure I'm in the neighborhood of the problem. The three MOVLs clearly don't make sense.

 v677  	00341 (287)	UCOMISD	X1, X0
 v292  	00342 (287)	MOVL	$2, AX
 v287  	00343 (287)	MOVL	$1, CX
 v456  	00344 (287)	MOVL	CX, AX
 v456  	00345 (287)	CMOVLNE	AX, AX
 v456  	00346 (287)	CMOVLPC	AX, AX
 v460  	00347 (287)	MOVL	AX, "".~r2+24(SP)
 b196  	00348 (35)	RET

cc @randall77 @TocarIP @rasky

This is Google-internal b/110810807.

@heschi heschi added this to the Go1.11 milestone Jun 27, 2018
@TocarIP
Copy link
Contributor

TocarIP commented Jun 27, 2018

Looks like we clobber AX for "ssa.OpAMD64CMOVQEQF, ssa.OpAMD64CMOVLEQF, ssa.OpAMD64CMOVWEQF", but only CMOVQEQF uses gp21pax regspec (which marks ax as clobbered)

@TocarIP
Copy link
Contributor

TocarIP commented Jun 27, 2018

Here is a simple reproducer:

package main

//go:noinline
func foo1(v1, v2 int64, x1, x2 float64) int64 {
        r := v1
        if x1 == x2 {
                r = v2
        }
        return r
}

//go:noinline
func foo3(v1, v2 int16, x1, x2 float64) int16 {
        r := v1
        if x1 == x2 {
                r = v2
        }
        return r
}

//go:noinline
func foo2(v1, v2 int32, x1, x2 float64) int32 {
        r := v1
        if x1 == x2 {
                r = v2
        }
        return r
}

func main() {
//should print 1 1 1
        println(foo1(1, 2, 4.0, 5.0))
        println(foo2(1, 2, 4.0, 5.0))
        println(foo3(1, 2, 4.0, 5.0))
// prints 1 2 2
}

@gopherbot
Copy link

Change https://golang.org/cl/121336 mentions this issue: cmd/compile: mark CMOVLEQF, CMOVWEQF as cloberring AX

@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 27, 2018
@golang golang locked and limited conversation to collaborators Jun 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants