mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: compute OR's maximum limits from argument's limits
Change-Id: I6902c405cab7bd573f6a721a6ca7c783713ea39a Reviewed-on: https://go-review.googlesource.com/c/go/+/604456 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
49621cc311
commit
57df33814a
2 changed files with 22 additions and 2 deletions
|
|
@ -1698,10 +1698,12 @@ func (ft *factsTable) flowLimit(v *Value) bool {
|
||||||
b := ft.limits[v.Args[1].ID]
|
b := ft.limits[v.Args[1].ID]
|
||||||
return ft.unsignedMax(v, minU(a.umax, b.umax))
|
return ft.unsignedMax(v, minU(a.umax, b.umax))
|
||||||
case OpOr64, OpOr32, OpOr16, OpOr8:
|
case OpOr64, OpOr32, OpOr16, OpOr8:
|
||||||
// OR can only make the value bigger.
|
// OR can only make the value bigger and can't flip bits proved to be zero in both inputs.
|
||||||
a := ft.limits[v.Args[0].ID]
|
a := ft.limits[v.Args[0].ID]
|
||||||
b := ft.limits[v.Args[1].ID]
|
b := ft.limits[v.Args[1].ID]
|
||||||
return ft.unsignedMin(v, maxU(a.umin, b.umin))
|
return ft.unsignedMinMax(v,
|
||||||
|
maxU(a.umin, b.umin),
|
||||||
|
1<<bits.Len64(a.umax|b.umax)-1)
|
||||||
case OpXor64, OpXor32, OpXor16, OpXor8:
|
case OpXor64, OpXor32, OpXor16, OpXor8:
|
||||||
// XOR can't flip bits that are proved to be zero in both inputs.
|
// XOR can't flip bits that are proved to be zero in both inputs.
|
||||||
a := ft.limits[v.Args[0].ID]
|
a := ft.limits[v.Args[0].ID]
|
||||||
|
|
|
||||||
|
|
@ -1408,6 +1408,24 @@ func xor64(a, b uint64, ensureBothBranchesCouldHappen bool) int {
|
||||||
return int(z)
|
return int(z)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func or64(a, b uint64, ensureBothBranchesCouldHappen bool) int {
|
||||||
|
a &= 0xff
|
||||||
|
b &= 0xfff
|
||||||
|
|
||||||
|
z := a | b
|
||||||
|
|
||||||
|
if ensureBothBranchesCouldHappen {
|
||||||
|
if z > 0xfff { // ERROR "Disproved Less64U$"
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if z <= 0xfff { // ERROR "Proved Leq64U$"
|
||||||
|
return 1337
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return int(z)
|
||||||
|
}
|
||||||
|
|
||||||
//go:noinline
|
//go:noinline
|
||||||
func useInt(a int) {
|
func useInt(a int) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue