]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: compute Negation's limits from argument's limits
authorJorropo <jorropo.pgm@gmail.com>
Thu, 15 Aug 2024 02:54:46 +0000 (04:54 +0200)
committerKeith Randall <khr@golang.org>
Tue, 3 Sep 2024 21:12:20 +0000 (21:12 +0000)
Change-Id: I2e4d74a86faa95321e847a061e06c3efff7f20df
Reviewed-on: https://go-review.googlesource.com/c/go/+/605775
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/ssa/prove.go
test/prove.go

index db0ad97ad0b4734ffe55ec87ec7df77da08e56a3..415d627784ced484e0e88121f24b234b5f528894 100644 (file)
@@ -1787,6 +1787,10 @@ func (ft *factsTable) flowLimit(v *Value) bool {
                a := ft.limits[v.Args[0].ID]
                b := ft.limits[v.Args[1].ID]
                return ft.newLimit(v, a.sub(b, 8))
+       case OpNeg64, OpNeg32, OpNeg16, OpNeg8:
+               a := ft.limits[v.Args[0].ID]
+               bitsize := uint(v.Type.Size()) * 8
+               return ft.newLimit(v, a.com(bitsize).add(limit{min: 1, max: 1, umin: 1, umax: 1}, bitsize))
        case OpMul64:
                a := ft.limits[v.Args[0].ID]
                b := ft.limits[v.Args[1].ID]
index fd709f119ea8c58dccc9c20e70c26d8c2aaa13a7..2265b637bad02094ec03db6f2634c47e359ba275 100644 (file)
@@ -1627,6 +1627,49 @@ func com64(a uint64, ensureAllBranchesCouldHappen func() bool) uint64 {
        return z
 }
 
+func neg64(a uint64, ensureAllBranchesCouldHappen func() bool) uint64 {
+       var lo, hi uint64 = 0xff, 0xfff
+       a &= hi
+       a |= lo
+
+       z := -a
+
+       if ensureAllBranchesCouldHappen() && z > -lo { // ERROR "Disproved Less64U$"
+               return 42
+       }
+       if ensureAllBranchesCouldHappen() && z <= -lo { // ERROR "Proved Leq64U$"
+               return 1337
+       }
+       if ensureAllBranchesCouldHappen() && z < -hi { // ERROR "Disproved Less64U$"
+               return 42
+       }
+       if ensureAllBranchesCouldHappen() && z >= -hi { // ERROR "Proved Leq64U$"
+               return 1337
+       }
+       return z
+}
+func neg64mightOverflowDuringNeg(a uint64, ensureAllBranchesCouldHappen func() bool) uint64 {
+       var lo, hi uint64 = 0, 0xfff
+       a &= hi
+       a |= lo
+
+       z := -a
+
+       if ensureAllBranchesCouldHappen() && z > -lo {
+               return 42
+       }
+       if ensureAllBranchesCouldHappen() && z <= -lo {
+               return 1337
+       }
+       if ensureAllBranchesCouldHappen() && z < -hi {
+               return 42
+       }
+       if ensureAllBranchesCouldHappen() && z >= -hi {
+               return 1337
+       }
+       return z
+}
+
 //go:noinline
 func useInt(a int) {
 }