]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: compute Trunc's limits from argument's limits
authorJorropo <jorropo.pgm@gmail.com>
Wed, 14 Aug 2024 19:25:08 +0000 (21:25 +0200)
committerKeith Randall <khr@golang.org>
Tue, 3 Sep 2024 21:12:00 +0000 (21:12 +0000)
Change-Id: I419faa781db085b98ea25008ca127d0317fb34e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/605695
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
src/cmd/compile/internal/ssa/prove.go
test/prove.go

index f76e863453f46539ac90989780218341026050c9..8a351545c9536a6fc6ccd7682b69b393f361734d 100644 (file)
@@ -1643,6 +1643,11 @@ func (ft *factsTable) flowLimit(v *Value) bool {
        case OpSignExt8to64, OpSignExt8to32, OpSignExt8to16, OpSignExt16to64, OpSignExt16to32, OpSignExt32to64:
                a := ft.limits[v.Args[0].ID]
                return ft.signedMinMax(v, a.min, a.max)
+       case OpTrunc64to8, OpTrunc64to16, OpTrunc64to32, OpTrunc32to8, OpTrunc32to16, OpTrunc16to8:
+               a := ft.limits[v.Args[0].ID]
+               if a.umax <= 1<<(uint64(v.Type.Size())*8)-1 {
+                       return ft.unsignedMinMax(v, a.umin, a.umax)
+               }
 
        // math/bits
        case OpCtz64:
index 28b950ce41304ead308422386e35c50998af10e5..16f7b7de96bef768960f37c8601c816919c0000b 100644 (file)
@@ -1586,6 +1586,26 @@ func div64s(a, b int64, ensureAllBranchesCouldHappen func() bool) int64 {
        return z
 }
 
+func trunc64to16(a uint64, ensureAllBranchesCouldHappen func() bool) uint16 {
+       a &= 0xfff
+       a |= 0xff
+
+       z := uint16(a)
+       if ensureAllBranchesCouldHappen() && z > 0xfff { // ERROR "Disproved Less16U$"
+               return 42
+       }
+       if ensureAllBranchesCouldHappen() && z <= 0xfff { // ERROR "Proved Leq16U$"
+               return 1337
+       }
+       if ensureAllBranchesCouldHappen() && z < 0xff { // ERROR "Disproved Less16U$"
+               return 42
+       }
+       if ensureAllBranchesCouldHappen() && z >= 0xff { // ERROR "Proved Leq16U$"
+               return 1337
+       }
+       return z
+}
+
 //go:noinline
 func useInt(a int) {
 }