cmd/compile: teach prove about bitwise OR operation
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>
diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go
index 2ca24660..94d2c52 100644
--- a/src/cmd/compile/internal/ssa/prove.go
+++ b/src/cmd/compile/internal/ssa/prove.go
@@ -867,6 +867,14 @@
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,
diff --git a/test/prove.go b/test/prove.go
index abc7bfa..91d1f55 100644
--- a/test/prove.go
+++ b/test/prove.go
@@ -1111,6 +1111,11 @@
return 0
}
+func issue45928(x int) {
+ combinedFrac := x / (x | (1 << 31)) // ERROR "Proved Neq64$"
+ useInt(combinedFrac)
+}
+
//go:noinline
func useInt(a int) {
}