mirror of
https://github.com/golang/go.git
synced 2026-06-28 03:40:37 +00:00
cmd/compile: add CvtBoolToUint8 support to known bits
This doesn't have any hits in the std. Updates #78633 Change-Id: I12d1d5c224b5cd6e45fcfbe9680d2fd89ff99e4d Reviewed-on: https://go-review.googlesource.com/c/go/+/765801 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> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
This commit is contained in:
parent
1ad012aa6b
commit
d75902b195
2 changed files with 34 additions and 1 deletions
|
|
@ -87,7 +87,7 @@ func (kb *knownBitsState) fold(v *Value) (value, known int64) {
|
|||
}
|
||||
}
|
||||
return value, known
|
||||
case OpCopy:
|
||||
case OpCopy, OpCvtBoolToUint8:
|
||||
return kb.fold(v.Args[0])
|
||||
case OpEq64, OpEq32, OpEq16, OpEq8, OpEqB:
|
||||
x, xk := kb.fold(v.Args[0])
|
||||
|
|
|
|||
|
|
@ -181,3 +181,36 @@ func unknownBitsZeroExt(x uint16) uint32 {
|
|||
x |= 0xAAAA
|
||||
return uint32(x) & 0xFFFFF000
|
||||
}
|
||||
|
||||
func cvtBoolToUint8(cond bool) (r uint8) {
|
||||
if cond {
|
||||
r = 1
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func knownBitsCvtBoolToUint8False(x, y uint64) uint8 {
|
||||
x |= 1
|
||||
y &^= 1
|
||||
bool := x == y // ERROR "known value of v[0-9]+ \(Eq64\): false$"
|
||||
return cvtBoolToUint8(bool) & 1 // ERROR "known value of v[0-9]+ \(CvtBoolToUint8\): 0$"
|
||||
}
|
||||
|
||||
func knownBitsCvtBoolToUint8True(x int64, cond bool) uint8 {
|
||||
x |= 6
|
||||
if cond {
|
||||
x |= 1
|
||||
x |= 4
|
||||
}
|
||||
// I would expect "known value of v[0-9]+ \(And64\): 6$" to be required, but somehow it's not there even tho the AND is being folded.
|
||||
// I think it's an issue with the And's LOC meaning known bits prints it without a LOC and errorcheck skips it.
|
||||
r := cvtBoolToUint8(x&6 == 6) // ERROR "known value of v[0-9]+ \(Eq64\): true$" "known value of v[0-9]+ \(CvtBoolToUint8\): 1$"
|
||||
if cond {
|
||||
r |= 4 // ERROR "known value of v[0-9]+ \(Or8\): 5$"
|
||||
}
|
||||
return r & 3 // ERROR "known value of v[0-9]+ \(And8\): 1$"
|
||||
}
|
||||
|
||||
func unknownBitsCvtBoolToUint8(cond bool) uint8 {
|
||||
return cvtBoolToUint8(cond) & 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue