mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: derive relation between x+delta and x in prove
If x+delta cannot overflow/underflow, we can derive: x+delta < x if delta<0 (this CL included) x+delta > x if delta>0 (this CL not included due to a recursive stack overflow) Remove 95 bounds checks during ./make.bat Fixes #51622 Change-Id: I60d9bd84c5d7e81bbf808508afd09be596644f09 Reviewed-on: https://go-review.googlesource.com/c/go/+/406175 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
6b113c0fec
commit
d2e0587f77
2 changed files with 26 additions and 9 deletions
|
|
@ -463,15 +463,23 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) {
|
|||
if parent.Func.pass.debug > 1 {
|
||||
parent.Func.Warnl(parent.Pos, "x+d %s w; x:%v %v delta:%v w:%v d:%v", r, x, parent.String(), delta, w.AuxInt, d)
|
||||
}
|
||||
underflow := true
|
||||
if l, has := ft.limits[x.ID]; has && delta < 0 {
|
||||
if (x.Type.Size() == 8 && l.min >= math.MinInt64-delta) ||
|
||||
(x.Type.Size() == 4 && l.min >= math.MinInt32-delta) {
|
||||
underflow = false
|
||||
}
|
||||
}
|
||||
if delta < 0 && !underflow {
|
||||
// If delta < 0 and x+delta cannot underflow then x > x+delta (that is, x > v)
|
||||
ft.update(parent, x, v, signed, gt)
|
||||
}
|
||||
if !w.isGenericIntConst() {
|
||||
// If we know that x+delta > w but w is not constant, we can derive:
|
||||
// if delta < 0 and x > MinInt - delta, then x > w (because x+delta cannot underflow)
|
||||
// if delta < 0 and x+delta cannot underflow, then x > w
|
||||
// This is useful for loops with bounds "len(slice)-K" (delta = -K)
|
||||
if l, has := ft.limits[x.ID]; has && delta < 0 {
|
||||
if (x.Type.Size() == 8 && l.min >= math.MinInt64-delta) ||
|
||||
(x.Type.Size() == 4 && l.min >= math.MinInt32-delta) {
|
||||
ft.update(parent, x, w, signed, r)
|
||||
}
|
||||
if delta < 0 && !underflow {
|
||||
ft.update(parent, x, w, signed, r)
|
||||
}
|
||||
} else {
|
||||
// With w,delta constants, we want to derive: x+delta > w ⇒ x > w-delta
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue