}
}
+func unsignedSubUnderflows(a, b uint64) bool {
+ return a < b
+}
+
func addLocalFacts(ft *factsTable, b *Block) {
// Propagate constant ranges among values in this block.
// We do this before the second loop so that we have the
}
ft.update(b, v, v.Args[0], signed, r)
}
+ case OpSub64, OpSub32, OpSub16, OpSub8:
+ x := ft.limits[v.Args[0].ID]
+ y := ft.limits[v.Args[1].ID]
+ if !unsignedSubUnderflows(x.umin, y.umax) {
+ r := lt
+ if !y.nonzero() {
+ r |= eq
+ }
+ ft.update(b, v, v.Args[0], unsigned, r)
+ }
+ // FIXME: we could also do signed facts but the overflow checks are much trickier and I don't need it yet.
case OpAnd64, OpAnd32, OpAnd16, OpAnd8:
ft.update(b, v, v.Args[0], unsigned, lt|eq)
ft.update(b, v, v.Args[1], unsigned, lt|eq)
}
}
+func transitiveProofsThroughNonOverflowingUnsignedSub(x, y, z uint64) {
+ x |= 0xfff
+ y &= 0xfff
+
+ a := x - y
+ if a < z {
+ return
+ }
+
+ if x < z { // ERROR "Disproved Less64U$"
+ return
+ }
+ if y < z {
+ return
+ }
+ if a == x {
+ return
+ }
+ if a == y {
+ return
+ }
+
+ y |= 1
+ a = x - y
+ if a == x { // ERROR "Disproved Eq64$"
+ return
+ }
+ if a == y {
+ return
+ }
+}
+
+func transitiveProofsThroughOverflowingUnsignedSub(x, y, z uint64) {
+ a := x - y
+ if a < z {
+ return
+ }
+
+ if x < z {
+ return
+ }
+ if y < z {
+ return
+ }
+ if a == x {
+ return
+ }
+ if a == y {
+ return
+ }
+
+ y |= 1
+ a = x - y
+ if a == x {
+ return
+ }
+ if a == y {
+ return
+ }
+}
+
//go:noinline
func useInt(a int) {
}