cmd/compile: add Zext support to known bits

Uniqued by LOC this adds 79 known bits hits when building the std.

Updates #78633

Change-Id: Ib555a49834f848a887d2acea20e89b45613eea30
Reviewed-on: https://go-review.googlesource.com/c/go/+/765800
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Jorropo 2026-04-12 09:21:01 +02:00 committed by Gopher Robot
parent b9e1876c11
commit 1ad012aa6b
2 changed files with 19 additions and 0 deletions

View file

@ -100,6 +100,11 @@ func (kb *knownBitsState) fold(v *Value) (value, known int64) {
return boolToAuxInt(x == y), -1
}
return 0, -1 << 1
case OpZeroExt8to16, OpZeroExt8to32, OpZeroExt8to64, OpZeroExt16to32, OpZeroExt16to64, OpZeroExt32to64:
x, k := kb.fold(v.Args[0])
srcSize := v.Args[0].Type.Size() * 8
mask := int64(1<<srcSize - 1)
return x & mask, k | ^mask
default:
return 0, 0
}

View file

@ -167,3 +167,17 @@ func unknownBitsEq(x, y uint64) bool {
x |= 1
return x == y
}
func knownBitsZeroExtPassThrough(x uint8) uint64 {
x |= 6
return uint64(x) & 6 // ERROR "known value of v[0-9]+ \(And64\): 6$"
}
func knownBitsZeroExtUpperHalf(x uint16) uint32 {
return uint32(x) & 0xFFFF0000 // ERROR "known value of v[0-9]+ \(And32\): 0$"
}
func unknownBitsZeroExt(x uint16) uint32 {
x |= 0xAAAA
return uint32(x) & 0xFFFFF000
}