mirror of
https://github.com/golang/go.git
synced 2026-06-27 19:30:52 +00:00
cmd/compile: add Neq support to known bits
When known bits analyze an Neq if it finds any bit that is known in both sides but different, it also knows the neq will always be true. Uniqued by LOC this adds 7 known bits hits when building the std. Updates #78633 Change-Id: I3ec907e2def9d365e6360b6c81dde47920c62bf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/766040 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Keith Randall <khr@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:
parent
8963c303b4
commit
9c0a8a2b46
2 changed files with 31 additions and 0 deletions
|
|
@ -101,6 +101,17 @@ func (kb *knownBitsState) fold(v *Value) (value, known int64) {
|
|||
return boolToAuxInt(x == y), -1
|
||||
}
|
||||
return 0, -1 << 1
|
||||
case OpNeq64, OpNeq32, OpNeq16, OpNeq8, OpNeqB:
|
||||
x, xk := kb.fold(v.Args[0])
|
||||
y, yk := kb.fold(v.Args[1])
|
||||
differentBits := x ^ y
|
||||
if differentBits&xk&yk != 0 {
|
||||
return 1, -1
|
||||
}
|
||||
if xk == -1 && yk == -1 {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -168,6 +168,26 @@ func unknownBitsEq(x, y uint64) bool {
|
|||
return x == y
|
||||
}
|
||||
|
||||
func knownBitsNeqTrue(x, y uint64) bool {
|
||||
x |= 1
|
||||
y &^= 1
|
||||
return x != y // ERROR "known value of v[0-9]+ \(Neq64\): true$"
|
||||
}
|
||||
|
||||
func knownBitsNeqFalse(x uint64, cond bool) bool {
|
||||
x |= (1<<32 - 1) << 32
|
||||
if cond {
|
||||
x |= 42
|
||||
}
|
||||
x |= 1<<32 - 1
|
||||
return x != 1<<64-1 // ERROR "known value of v[0-9]+ \(Neq64\): false$"
|
||||
}
|
||||
|
||||
func unknownBitsNeq(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$"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue