From: Cuong Manh Le Date: Mon, 10 Apr 2023 04:08:25 +0000 (+0700) Subject: cmd/compile: teach prove about bitwise OR operation X-Git-Tag: go1.21rc1~977 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=63a08e61bd5ac5132ed160351933622443c16b58;p=gostls13.git 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 Reviewed-by: Cherry Mui Run-TryBot: Cuong Manh Le Reviewed-by: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index 2ca2466086..94d2c525b9 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -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, diff --git a/test/prove.go b/test/prove.go index abc7bfaa21..91d1f55519 100644 --- a/test/prove.go +++ b/test/prove.go @@ -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) { }