cmd/compile: add Trunc support to known bits
Uniqued by LOC this adds 3 known bits hits when building the std. Updates #78633 Change-Id: I44f2ae1ed31f798d7881691729cce5d9707e8edc Reviewed-on: https://go-review.googlesource.com/c/go/+/766120 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Mark Freeman <markfreeman@google.com> 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>
This commit is contained in:
@@ -88,7 +88,10 @@ func (kb *knownBitsState) fold(v *Value) (value, known int64) {
|
||||
}
|
||||
return value, known
|
||||
case OpCopy, OpCvtBoolToUint8,
|
||||
OpSignExt8to16, OpSignExt8to32, OpSignExt8to64, OpSignExt16to32, OpSignExt16to64, OpSignExt32to64:
|
||||
OpSignExt8to16, OpSignExt8to32, OpSignExt8to64, OpSignExt16to32, OpSignExt16to64, OpSignExt32to64,
|
||||
// The defer block handles maintaining the sign-extension invariant using v.Type.Size()
|
||||
// thus we can just pass Truncs as-is.
|
||||
OpTrunc64to32, OpTrunc64to16, OpTrunc64to8, OpTrunc32to16, OpTrunc32to8, OpTrunc16to8:
|
||||
return kb.fold(v.Args[0])
|
||||
case OpEq64, OpEq32, OpEq16, OpEq8, OpEqB:
|
||||
x, xk := kb.fold(v.Args[0])
|
||||
|
||||
@@ -383,3 +383,51 @@ func unknownBitsRshRightSide(x int32, y int32) int32 {
|
||||
|
||||
return (x >> y) & 0b110
|
||||
}
|
||||
|
||||
func knownBitsTrunc(x int64, cond bool) int32 {
|
||||
x |= 2
|
||||
if cond {
|
||||
x = 3
|
||||
}
|
||||
|
||||
return int32(x) & 2 // ERROR "known value of v[0-9]+ \(And32\): 2$"
|
||||
}
|
||||
|
||||
func unknownBitsTrunc(x int64, cond bool) int32 {
|
||||
x |= 2
|
||||
if cond {
|
||||
x = 3
|
||||
}
|
||||
|
||||
return int32(x) & 1
|
||||
}
|
||||
|
||||
func knownBitsSextAfterTrunc(x int64, cond1, cond2 bool) int64 {
|
||||
x |= -1 << 31
|
||||
if cond1 {
|
||||
x = -3
|
||||
}
|
||||
|
||||
truncated := int32(x)
|
||||
|
||||
if cond2 {
|
||||
truncated |= 4
|
||||
}
|
||||
|
||||
return int64(truncated) & (-1 << 63) // ERROR "known value of v[0-9]+ \(And64\): -9223372036854775808$"
|
||||
}
|
||||
|
||||
func unknownBitsSextAfterTrunc(x int64, cond1, cond2 bool) int64 {
|
||||
x |= 2
|
||||
if cond1 {
|
||||
x = 3
|
||||
}
|
||||
|
||||
truncated := int32(x)
|
||||
|
||||
if cond2 {
|
||||
truncated |= 4
|
||||
}
|
||||
|
||||
return int64(truncated) & (-1 << 63)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user