]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: teach prove about bitwise OR operation
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 10 Apr 2023 04:08:25 +0000 (11:08 +0700)
committerGopher Robot <gobot@golang.org>
Mon, 10 Apr 2023 17:13:41 +0000 (17:13 +0000)
For now, only apply the rule if either of arguments are constants. That
would catch a lot of real user code, without slowing down the compiler
with code generated for string comparison (experience in CL 410336).

Updates #57959
Fixes #45928

Change-Id: Ie2e830d6d0d71cda3947818b22c2775bd94f7971
Reviewed-on: https://go-review.googlesource.com/c/go/+/483359
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/prove.go
test/prove.go

index 2ca246608626e7210089e4060948b338f7e29b08..94d2c525b91c48a38b46ff06c3024dc13e37b0d0 100644 (file)
@@ -867,6 +867,14 @@ func prove(f *Func) {
                                        logicVars = make(map[*Block][]*Value)
                                }
                                logicVars[b] = append(logicVars[b], v)
+                       case OpOr64, OpOr32, OpOr16, OpOr8:
+                               // TODO: investigate how to always add facts without much slowdown, see issue #57959.
+                               if v.Args[0].isGenericIntConst() {
+                                       ft.update(b, v, v.Args[0], unsigned, gt|eq)
+                               }
+                               if v.Args[1].isGenericIntConst() {
+                                       ft.update(b, v, v.Args[1], unsigned, gt|eq)
+                               }
                        case OpDiv64u, OpDiv32u, OpDiv16u, OpDiv8u,
                                OpRsh8Ux64, OpRsh8Ux32, OpRsh8Ux16, OpRsh8Ux8,
                                OpRsh16Ux64, OpRsh16Ux32, OpRsh16Ux16, OpRsh16Ux8,
index abc7bfaa210b596f366294d3f1bff21f27e47715..91d1f555191b86cb708675c08028cff41022e7e7 100644 (file)
@@ -1111,6 +1111,11 @@ func issue51622(b []byte) int {
        return 0
 }
 
+func issue45928(x int) {
+       combinedFrac := x / (x | (1 << 31)) // ERROR "Proved Neq64$"
+       useInt(combinedFrac)
+}
+
 //go:noinline
 func useInt(a int) {
 }