Skip to content

Commit 63a08e6

Browse files
cuonglmgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent a3f3868 commit 63a08e6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/cmd/compile/internal/ssa/prove.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,14 @@ func prove(f *Func) {
867867
logicVars = make(map[*Block][]*Value)
868868
}
869869
logicVars[b] = append(logicVars[b], v)
870+
case OpOr64, OpOr32, OpOr16, OpOr8:
871+
// TODO: investigate how to always add facts without much slowdown, see issue #57959.
872+
if v.Args[0].isGenericIntConst() {
873+
ft.update(b, v, v.Args[0], unsigned, gt|eq)
874+
}
875+
if v.Args[1].isGenericIntConst() {
876+
ft.update(b, v, v.Args[1], unsigned, gt|eq)
877+
}
870878
case OpDiv64u, OpDiv32u, OpDiv16u, OpDiv8u,
871879
OpRsh8Ux64, OpRsh8Ux32, OpRsh8Ux16, OpRsh8Ux8,
872880
OpRsh16Ux64, OpRsh16Ux32, OpRsh16Ux16, OpRsh16Ux8,

test/prove.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,11 @@ func issue51622(b []byte) int {
11111111
return 0
11121112
}
11131113

1114+
func issue45928(x int) {
1115+
combinedFrac := x / (x | (1 << 31)) // ERROR "Proved Neq64$"
1116+
useInt(combinedFrac)
1117+
}
1118+
11141119
//go:noinline
11151120
func useInt(a int) {
11161121
}

0 commit comments

Comments
 (0)