1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:01:37 -07:00

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>
This commit is contained in:
Cuong Manh Le 2023-04-10 11:08:25 +07:00 committed by Gopher Robot
parent a3f3868c7a
commit 63a08e61bd
2 changed files with 13 additions and 0 deletions

View 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,

View 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) {
}