Skip to content

cmd/compile: 64 bits shifts on arm get wrong results #48476

@randall77

Description

@randall77
package main

//go:noinline
func f(x, y uint64) uint64 {
	s := "\x04"
	c := s[0]
	return x<<c<<4
}
func main() {
	println(f(1, 1))
}

Should print 256 (0x100), instead prints 1099511628032 (0x10000000100) on arm.

The problem is we build a SLLconst with a shift amount > 32. That in itself is ok, but we then copy the shift amount into a ORshiftLL, where the top bits are magically discarded.

The SLL with a large constant shift amount comes from the 64->32 bit lowering of shifts. We compute things like s-32 and 32-s (unsigned) for shift amounts in [0,63).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions