aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/prove.go
AgeCommit message (Collapse)Author
2026-01-29cmd/compile: make prove use non-equality in subtraction for a stronger boundJonah Uellenberg
Given: s := /* slice */ k := /* proved valid index in s (0 <= k < len(s)) */ v := s[k:] len(v) >= 1, so v[0] needs no bounds check. However, for len(v) = len(s) - k, we only checked if len(s) >= k and so could only prove len(v) >= 0, thus the bounds check wasn't removed. As far as I can tell these checks were commented out for performance, but after benchmarking prove I see no difference. Fixes: #76429 Change-Id: I39ba2a18cbabc0559924d4d226dcb99dbe9a06ed GitHub-Last-Rev: 53f3344d261986cd021c8d7b8435ab89b5438b8f GitHub-Pull-Request: golang/go#76609 Reviewed-on: https://go-review.googlesource.com/c/go/+/725100 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-01-23cmd/compile: cleanup noLimit in proveJorropo
- make it immutable - calculate it rather than using hardcoded value (it all is inlined and constant folded away into noLimit's callers) Change-Id: Ica12442df4d03e99123e62c0fe561c1078e35d75 Reviewed-on: https://go-review.googlesource.com/c/go/+/727181 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-01-23cmd/compile: improve PopCount's limits modeling and add bruteforce testsJorropo
This make PopCount perfect within the limitations limits can represent. Change-Id: Ia52e5d79064ad8109117f009c5390a6eba8ccd98 Reviewed-on: https://go-review.googlesource.com/c/go/+/727782 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
2026-01-23cmd/compile: add limits bruteforce tests for bitlenJorropo
This ensure BitLen is perfect within the limitations limits can represent. Change-Id: I5c1770b4a9f6408fd68fe77b4ef2b2cdd52e26cb Reviewed-on: https://go-review.googlesource.com/c/go/+/727781 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2026-01-23cmd/compile: improve Ctz's limits modeling and add bruteforce testsJorropo
This make Ctz perfect within the limitations limits can represent. Change-Id: I1e596d8d01892d1b70031cf03cecc487ce147b38 Reviewed-on: https://go-review.googlesource.com/c/go/+/727780 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
2026-01-23cmd/compile: cleanup isUnsignedPowerOfTwoJorropo
Merge the signed and unsigned generic functions. The only implementation difference between the two is: n > 0 vs n != 0 check. For unsigned numbers n > 0 == n != 0 and we infact optimize the first to the second. Change-Id: Ia2f6c3e3d4eb098d98f85e06dc2e81baa60bad4e Reviewed-on: https://go-review.googlesource.com/c/go/+/726720 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-05cmd/compile: fix mis-infer bounds in slice len/cap calculationsCuong Manh Le
CL 704875 enhanced prove to infer bounds when index have a relationship with len(A) - K. However, the change incorrectly infer "K - len(A)" case, causing wrong bounds information. Fixing this by matching exactly "len(A) - K" case. Fixes #76709 Change-Id: Ibeedff55520658401af5bd3aa7e98cc1bcf38fd6 Reviewed-on: https://go-review.googlesource.com/c/go/+/727180 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jakub Ciolek <jakub@ciolek.dev> Reviewed-by: David Chase <drchase@google.com>
2025-12-04cmd/compile: use isUnsignedPowerOfTwo rather than isPowerOfTwo for unsignedsJorropo
Fixes #76688 Change-Id: Icb8dab54a5ce7d83b656d50d5ea605d2a62b96f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/726680 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-11-26cmd/compile: add tests bruteforcing limit negation and improve limit additionJorropo
I had to improve addition to make the tests pass. Change-Id: I4daba2ee0f24a0dbc3929bf9afadd2116e16efae Reviewed-on: https://go-review.googlesource.com/c/go/+/724600 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-11-24cmd/compile: add cases for StringLen to proveDavid Chase
Tricky index-offset logic had been added for slices, but not for strings. This fixes that, and also adds tests for same behavior in string/slice cases, and adds a new test for code in prove that had been added but not explicitly tested. Fixes #76270. Change-Id: Ibd92b89e944d86b7f30b4486a9008e6f1ac6af7d Reviewed-on: https://go-review.googlesource.com/c/go/+/723980 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-11-21cmd/compile: rewrite Rsh to RshU if arguments are proved positiveJorropo
Fixes #76332 Change-Id: I9044025d5dc599531c7f88ed2870bcf3d8b0acbd Reviewed-on: https://go-review.googlesource.com/c/go/+/721206 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-11-21cmd/compile: propagate unsigned relations for Rsh if arguments are positiveJorropo
Updates #76332 Change-Id: Ifaa4d12897138d88d56b9d4e530c53dcee70bd58 Reviewed-on: https://go-review.googlesource.com/c/go/+/721205 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Keith Randall <khr@google.com>
2025-11-21cmd/compile: fix integer overflow in prove passJakub Ciolek
The detectSliceLenRelation function incorrectly deduced lower bounds for "len(s) - i" without checking if the subtraction could overflow (e.g. when i is negative). This led to incorrect elimination of bounds checks. Fixes: #76355 Change-Id: I30ada0e5f1425929ddd8ae1b66e55096ec209b5b Reviewed-on: https://go-review.googlesource.com/c/go/+/721920 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
2025-11-19cmd/compile: fix control flow for unsigned divisions proof relationsJorropo
The continue used to make sense since I first wrote this patch with a loop, for testing the commutativity of the add. This was refactored to just try both but I forgot to fix the continue. Change-Id: I91466a052d5d8ee7193084a71faf69bd27e36d2a Reviewed-on: https://go-review.googlesource.com/c/go/+/721204 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
2025-11-19cmd/compile: cleanup useless if statement in proveJorropo
Change-Id: Icf5db366b311b5f88809dd07f22cf4bfdead516c Reviewed-on: https://go-review.googlesource.com/c/go/+/721203 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-11-17cmd/compile: teach prove about subtract idiomsKeith Randall
For v = x-y: if y >= 0 then v <= x if y <= x then v >= 0 (With appropriate guards against overflow/underflow.) Fixes #76304 Change-Id: I8f8f1254156c347fa97802bd057a8379676720ae Reviewed-on: https://go-review.googlesource.com/c/go/+/720740 Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
2025-11-17cmd/compile: clean up prove passKeith Randall
flowLimit no longer needs to return whether it updated any information, after CL 714920 which got rid of the iterate-until-done paradigm. Change-Id: I0c5f592578ff27c27586c1f8b8a8d9071d94846d Reviewed-on: https://go-review.googlesource.com/c/go/+/720720 Reviewed-by: Youlin Feng <fengyoulin@live.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-30cmd/compile/internal/ssa: model right shift more preciselyRuss Cox
Prove currently checks for 0 sign bit extraction (x>>63) at the end of the pass, but it is more general and more useful (and not really more work) to model right shift during value range tracking. This handles sign bit extraction (both 0 and -1) but also makes the value ranges available for proving bounds checks. 'go build -a -gcflags=-d=ssa/prove/debug=1 std' finds 105 new things to prove. https://gist.github.com/rsc/8ac41176e53ed9c2f1a664fc668e8336 For example, the compiler now recognizes that this code in strconv does not need to check the second shift for being ≥ 64. msb := xHi >> 63 retMantissa := xHi >> (msb + 38) nor does this code in regexp: return b < utf8.RuneSelf && specialBytes[b%16]&(1<<(b/16)) != 0 This code in math no longer has a bounds check on the first index: if 0 <= n && n <= 308 { return pow10postab32[uint(n)/32] * pow10tab[uint(n)%32] } The diff shows one "lost" proof in ycbcr.go but it's not really lost: the expression was folded to a constant instead, and that only shows up with debug=2. A diff of that output is at https://gist.github.com/rsc/9139ed46c6019ae007f5a1ba4bb3250f Change-Id: I84087311e0a303f00e2820d957a6f8b29ee22519 Reviewed-on: https://go-review.googlesource.com/c/go/+/716140 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com>
2025-10-29cmd/compile: make prove understand div, mod betterRuss Cox
This CL introduces new divisible and divmod passes that rewrite divisibility checks and div, mod, and mul. These happen after prove, so that prove can make better sense of the code for deriving bounds, and they must run before decompose, so that 64-bit ops can be lowered to 32-bit ops on 32-bit systems. And then they need another generic pass as well, to optimize the generated code before decomposing. The three opt passes are "opt", "middle opt", and "late opt". (Perhaps instead they should be "generic", "opt", and "late opt"?) The "late opt" pass repeats the "middle opt" work on any new code that has been generated in the interim. There will not be new divs or mods, but there may be new muls. The x%c==0 rewrite rules are much simpler now, since they can match before divs have been rewritten. This has the effect of applying them more consistently and making the rewrite rules independent of the exact div rewrites. Prove is also now charged with marking signed div/mod as unsigned when the arguments call for it, allowing simpler code to be emitted in various cases. For example, t.Seconds()/2 and len(x)/2 are now recognized as unsigned, meaning they compile to a simple shift (unsigned division), avoiding the more complex fixup we need for signed values. https://gist.github.com/rsc/99d9d3bd99cde87b6a1a390e3d85aa32 shows a diff of 'go build -a -gcflags=-d=ssa/prove/debug=1 std' output before and after. "Proved Rsh64x64 shifts to zero" is replaced by the higher-level "Proved Div64 is unsigned" (the shift was in the signed expansion of div by constant), but otherwise prove is only finding more things to prove. One short example, in code that does x[i%len(x)]: < runtime/mfinal.go:131:34: Proved Rsh64x64 shifts to zero --- > runtime/mfinal.go:131:34: Proved Div64 is unsigned > runtime/mfinal.go:131:38: Proved IsInBounds A longer example: < crypto/internal/fips140/sha3/shake.go:28:30: Proved Rsh64x64 shifts to zero < crypto/internal/fips140/sha3/shake.go:38:27: Proved Rsh64x64 shifts to zero < crypto/internal/fips140/sha3/shake.go:53:46: Proved Rsh64x64 shifts to zero < crypto/internal/fips140/sha3/shake.go:55:46: Proved Rsh64x64 shifts to zero --- > crypto/internal/fips140/sha3/shake.go:28:30: Proved Div64 is unsigned > crypto/internal/fips140/sha3/shake.go:28:30: Proved IsInBounds > crypto/internal/fips140/sha3/shake.go:28:30: Proved IsSliceInBounds > crypto/internal/fips140/sha3/shake.go:38:27: Proved Div64 is unsigned > crypto/internal/fips140/sha3/shake.go:45:7: Proved IsSliceInBounds > crypto/internal/fips140/sha3/shake.go:46:4: Proved IsInBounds > crypto/internal/fips140/sha3/shake.go:53:46: Proved Div64 is unsigned > crypto/internal/fips140/sha3/shake.go:53:46: Proved IsInBounds > crypto/internal/fips140/sha3/shake.go:53:46: Proved IsSliceInBounds > crypto/internal/fips140/sha3/shake.go:55:46: Proved Div64 is unsigned > crypto/internal/fips140/sha3/shake.go:55:46: Proved IsInBounds > crypto/internal/fips140/sha3/shake.go:55:46: Proved IsSliceInBounds These diffs are due to the smaller opt being better and taking work away from prove: < image/jpeg/dct.go:307:5: Proved IsInBounds < image/jpeg/dct.go:308:5: Proved IsInBounds ... < image/jpeg/dct.go:442:5: Proved IsInBounds In the old opt, Mul by 8 was rewritten to Lsh by 3 early. This CL delays that rule to help prove recognize mods, but it also helps opt constant-fold the slice x[8*i:8*i+8:8*i+8]. Specifically, computing the length, opt can now do: (Sub64 (Add (Mul 8 i) 8) (Add (Mul 8 i) 8)) -> (Add 8 (Sub (Mul 8 i) (Mul 8 i))) -> (Add 8 (Mul 8 (Sub i i))) -> (Add 8 (Mul 8 0)) -> (Add 8 0) -> 8 The key step is (Sub (Mul x y) (Mul x z)) -> (Mul x (Sub y z)), Leaving the multiply as Mul enables using that step; the old rewrite to Lsh blocked it, leaving prove to figure out the length and then remove the bounds checks. But now opt can evaluate the length down to a constant 8 and then constant-fold away the bounds checks 0 < 8, 1 < 8, and so on. After that, the compiler has nothing left to prove. Benchmarks are noisy in general; I checked the assembly for the many large increases below, and the vast majority are unchanged and presumably hitting the caches differently in some way. The divisibility optimizations were not reliably triggering before. This leads to a very large improvement in some cases, like DivisiblePow2constI64, DivisibleconstI64 on 64-bit systems and DivisbleconstU64 on 32-bit systems. Another way the divisibility optimizations were unreliable before was incorrectly triggering for x/3, x%3 even though they are written not to do that. There is a real but small slowdown in the DivisibleWDivconst benchmarks on Mac because in the cases used in the benchmark, it is still faster (on Mac) to do the divisibility check than to remultiply. This may be worth further study. Perhaps when there is no rotate (meaning the divisor is odd), the divisibility optimization should be enabled always. In any event, this CL makes it possible to study that. benchmark \ host s7 linux-amd64 mac linux-arm64 linux-ppc64le linux-386 s7:GOARCH=386 linux-arm vs base vs base vs base vs base vs base vs base vs base vs base LoadAdd ~ ~ ~ ~ ~ -1.59% ~ ~ ExtShift ~ ~ -42.14% +0.10% ~ +1.44% +5.66% +8.50% Modify ~ ~ ~ ~ ~ ~ ~ -1.53% MullImm ~ ~ ~ ~ ~ +37.90% -21.87% +3.05% ConstModify ~ ~ ~ ~ -49.14% ~ ~ ~ BitSet ~ ~ ~ ~ -15.86% -14.57% +6.44% +0.06% BitClear ~ ~ ~ ~ ~ +1.78% +3.50% +0.06% BitToggle ~ ~ ~ ~ ~ -16.09% +2.91% ~ BitSetConst ~ ~ ~ ~ ~ ~ ~ -0.49% BitClearConst ~ ~ ~ ~ -28.29% ~ ~ -0.40% BitToggleConst ~ ~ ~ +8.89% -31.19% ~ ~ -0.77% MulNeg ~ ~ ~ ~ ~ ~ ~ ~ Mul2Neg ~ ~ -4.83% ~ ~ -13.75% -5.92% ~ DivconstI64 ~ ~ ~ ~ ~ -30.12% ~ +0.50% ModconstI64 ~ ~ -9.94% -4.63% ~ +3.15% ~ +5.32% DivisiblePow2constI64 -34.49% -12.58% ~ ~ -12.25% ~ ~ ~ DivisibleconstI64 -24.69% -25.06% -0.40% -2.27% -42.61% -3.31% ~ +1.63% DivisibleWDivconstI64 ~ ~ ~ ~ ~ -17.55% ~ -0.60% DivconstU64/3 ~ ~ ~ ~ ~ +1.51% ~ ~ DivconstU64/5 ~ ~ ~ ~ ~ ~ ~ ~ DivconstU64/37 ~ ~ -0.18% ~ ~ +2.70% ~ ~ DivconstU64/1234567 ~ ~ ~ ~ ~ ~ ~ +0.12% ModconstU64 ~ ~ ~ -0.24% ~ -5.10% -1.07% -1.56% DivisibleconstU64 ~ ~ ~ ~ ~ -29.01% -59.13% -50.72% DivisibleWDivconstU64 ~ ~ -12.18% -18.88% ~ -5.50% -3.91% +5.17% DivconstI32 ~ ~ -0.48% ~ -34.69% +89.01% -6.01% -16.67% ModconstI32 ~ +2.95% -0.33% ~ ~ -2.98% -5.40% -8.30% DivisiblePow2constI32 ~ ~ ~ ~ ~ ~ ~ -16.22% DivisibleconstI32 ~ ~ ~ ~ ~ -37.27% -47.75% -25.03% DivisibleWDivconstI32 -11.59% +5.22% -12.99% -23.83% ~ +45.95% -7.03% -10.01% DivconstU32 ~ ~ ~ ~ ~ +74.71% +4.81% ~ ModconstU32 ~ ~ +0.53% +0.18% ~ +51.16% ~ ~ DivisibleconstU32 ~ ~ ~ -0.62% ~ -4.25% ~ ~ DivisibleWDivconstU32 -2.77% +5.56% +11.12% -5.15% ~ +48.70% +25.11% -4.07% DivconstI16 -6.06% ~ -0.33% +0.22% ~ ~ -9.68% +5.47% ModconstI16 ~ ~ +4.44% +2.82% ~ ~ ~ +5.06% DivisiblePow2constI16 ~ ~ ~ ~ ~ ~ ~ -0.17% DivisibleconstI16 ~ ~ -0.23% ~ ~ ~ +4.60% +6.64% DivisibleWDivconstI16 -1.44% -0.43% +13.48% -5.76% ~ +1.62% -23.15% -9.06% DivconstU16 +1.61% ~ -0.35% -0.47% ~ ~ +15.59% ~ ModconstU16 ~ ~ ~ ~ ~ -0.72% ~ +14.23% DivisibleconstU16 ~ ~ -0.05% +3.00% ~ ~ ~ +5.06% DivisibleWDivconstU16 +52.10% +0.75% +17.28% +4.79% ~ -37.39% +5.28% -9.06% DivconstI8 ~ ~ -0.34% -0.96% ~ ~ -9.20% ~ ModconstI8 +2.29% ~ +4.38% +2.96% ~ ~ ~ ~ DivisiblePow2constI8 ~ ~ ~ ~ ~ ~ ~ ~ DivisibleconstI8 ~ ~ ~ ~ ~ ~ +6.04% ~ DivisibleWDivconstI8 -26.44% +1.69% +17.03% +4.05% ~ +32.48% -24.90% ~ DivconstU8 -4.50% +14.06% -0.28% ~ ~ ~ +4.16% +0.88% ModconstU8 ~ ~ +25.84% -0.64% ~ ~ ~ ~ DivisibleconstU8 ~ ~ -5.70% ~ ~ ~ ~ ~ DivisibleWDivconstU8 +49.55% +9.07% ~ +4.03% +53.87% -40.03% +39.72% -3.01% Mul2 ~ ~ ~ ~ ~ ~ ~ ~ MulNeg2 ~ ~ ~ ~ -11.73% ~ ~ -0.02% EfaceInteger ~ ~ ~ ~ ~ +18.11% ~ +2.53% TypeAssert +33.90% +2.86% ~ ~ ~ -1.07% -5.29% -1.04% Div64UnsignedSmall ~ ~ ~ ~ ~ ~ ~ ~ Div64Small ~ ~ ~ ~ ~ -0.88% ~ +2.39% Div64SmallNegDivisor ~ ~ ~ ~ ~ ~ ~ +0.35% Div64SmallNegDividend ~ ~ ~ ~ ~ -0.84% ~ +3.57% Div64SmallNegBoth ~ ~ ~ ~ ~ -0.86% ~ +3.55% Div64Unsigned ~ ~ ~ ~ ~ ~ ~ -0.11% Div64 ~ ~ ~ ~ ~ ~ ~ +0.11% Div64NegDivisor ~ ~ ~ ~ ~ -1.29% ~ ~ Div64NegDividend ~ ~ ~ ~ ~ -1.44% ~ ~ Div64NegBoth ~ ~ ~ ~ ~ ~ ~ +0.28% Mod64UnsignedSmall ~ ~ ~ ~ ~ +0.48% ~ +0.93% Mod64Small ~ ~ ~ ~ ~ ~ ~ ~ Mod64SmallNegDivisor ~ ~ ~ ~ ~ ~ ~ +1.44% Mod64SmallNegDividend ~ ~ ~ ~ ~ +0.22% ~ +1.37% Mod64SmallNegBoth ~ ~ ~ ~ ~ ~ ~ -2.22% Mod64Unsigned ~ ~ ~ ~ ~ -0.95% ~ +0.11% Mod64 ~ ~ ~ ~ ~ ~ ~ ~ Mod64NegDivisor ~ ~ ~ ~ ~ ~ ~ -0.02% Mod64NegDividend ~ ~ ~ ~ ~ ~ ~ ~ Mod64NegBoth ~ ~ ~ ~ ~ ~ ~ -0.02% MulconstI32/3 ~ ~ ~ -25.00% ~ ~ ~ +47.37% MulconstI32/5 ~ ~ ~ +33.28% ~ ~ ~ +32.21% MulconstI32/12 ~ ~ ~ -2.13% ~ ~ ~ -0.02% MulconstI32/120 ~ ~ ~ +2.93% ~ ~ ~ -0.03% MulconstI32/-120 ~ ~ ~ -2.17% ~ ~ ~ -0.03% MulconstI32/65537 ~ ~ ~ ~ ~ ~ ~ +0.03% MulconstI32/65538 ~ ~ ~ ~ ~ -33.38% ~ +0.04% MulconstI64/3 ~ ~ ~ +33.35% ~ -0.37% ~ -0.13% MulconstI64/5 ~ ~ ~ -25.00% ~ -0.34% ~ ~ MulconstI64/12 ~ ~ ~ +2.13% ~ +11.62% ~ +2.30% MulconstI64/120 ~ ~ ~ -1.98% ~ ~ ~ ~ MulconstI64/-120 ~ ~ ~ +0.75% ~ ~ ~ ~ MulconstI64/65537 ~ ~ ~ ~ ~ +5.61% ~ ~ MulconstI64/65538 ~ ~ ~ ~ ~ +5.25% ~ ~ MulconstU32/3 ~ +0.81% ~ +33.39% ~ +77.92% ~ -32.31% MulconstU32/5 ~ ~ ~ -24.97% ~ +77.92% ~ -24.47% MulconstU32/12 ~ ~ ~ +2.06% ~ ~ ~ +0.03% MulconstU32/120 ~ ~ ~ -2.74% ~ ~ ~ +0.03% MulconstU32/65537 ~ ~ ~ ~ ~ ~ ~ +0.03% MulconstU32/65538 ~ ~ ~ ~ ~ -33.42% ~ -0.03% MulconstU64/3 ~ ~ ~ +33.33% ~ -0.28% ~ +1.22% MulconstU64/5 ~ ~ ~ -25.00% ~ ~ ~ -0.64% MulconstU64/12 ~ ~ ~ +2.30% ~ +11.59% ~ +0.14% MulconstU64/120 ~ ~ ~ -2.82% ~ ~ ~ +0.04% MulconstU64/65537 ~ +0.37% ~ ~ ~ +5.58% ~ ~ MulconstU64/65538 ~ ~ ~ ~ ~ +5.16% ~ ~ ShiftArithmeticRight ~ ~ ~ ~ ~ -10.81% ~ +0.31% Switch8Predictable +14.69% ~ ~ ~ ~ -24.85% ~ ~ Switch8Unpredictable ~ -0.58% -3.80% ~ ~ -11.78% ~ -0.79% Switch32Predictable -10.33% +17.89% ~ ~ ~ +5.76% ~ ~ Switch32Unpredictable -3.15% +1.19% +9.42% ~ ~ -10.30% -5.09% +0.44% SwitchStringPredictable +70.88% +20.48% ~ ~ ~ +2.39% ~ +0.31% SwitchStringUnpredictable ~ +3.91% -5.06% -0.98% ~ +0.61% +2.03% ~ SwitchTypePredictable +146.58% -1.10% ~ -12.45% ~ -0.46% -3.81% ~ SwitchTypeUnpredictable +0.46% -0.83% ~ +4.18% ~ +0.43% ~ +0.62% SwitchInterfaceTypePredictable -13.41% -10.13% +11.03% ~ ~ -4.38% ~ +0.75% SwitchInterfaceTypeUnpredictable -6.37% -2.14% ~ -3.21% ~ -4.20% ~ +1.08% Fixes #63110. Fixes #75954. Change-Id: I55a876f08c6c14f419ce1a8cbba2eaae6c6efbf0 Reviewed-on: https://go-review.googlesource.com/c/go/+/714160 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-28cmd/compile: rewrite proved multiplies by 0 or 1 into CondSelectJorropo
Updates #76056 Change-Id: I64fe631ab381c74f902f877392530d7cc91860ab Reviewed-on: https://go-review.googlesource.com/c/go/+/715044 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/compile: introduce bytesizeToConst to cleanup switches in proveJorropo
Change-Id: I32b45d9632a8131911cb9bd6eff075eb8312ccfd Reviewed-on: https://go-review.googlesource.com/c/go/+/715043 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-10-27cmd/compile: teach prove about unsigned rounding-up divideJorropo
Change-Id: Ia7b5242c723f83ba85d12e4ca64a19fbbd126016 Reviewed-on: https://go-review.googlesource.com/c/go/+/714622 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-27cmd/compile: change !l.nonzero() into l.maybezero()Jorropo
if l.maybezero() is easier to read than if !l.nonzero() Change-Id: I1183b0c0dc51fa1eed26dfc7a5a996783806a991 Reviewed-on: https://go-review.googlesource.com/c/go/+/714621 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-27cmd/compile: remove 68857 ModU flowLimit workaround in proveJorropo
We can know this is correct because all the testcases added by CL 605156 are still passing. Partial revert of CL 605156 (everything but the testcases). Change-Id: I5d8daadb4cb35a9de29daaabc22baee642511fe0 Reviewed-on: https://go-review.googlesource.com/c/go/+/714941 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/compile: remove 68857 min & max flowLimit workaround in proveJorropo
We can know this is correct because all the testcases added by CL 656157 are still passing. Partial revert of CL 656157 (everything but the testcases). Change-Id: I24931fa1affba7e9e92233b3de74ebade3d48a09 Reviewed-on: https://go-review.googlesource.com/c/go/+/714921 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/compile: use topo-sort in prove to correctly learn facts while walking onceJorropo
Fixes #68857 Change-Id: Ideb359cc6f1550afb4c79f02d25a00d0ae5e5c50 Reviewed-on: https://go-review.googlesource.com/c/go/+/714920 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-15cmd/compile: eliminate bound check for slices of the same lengthYoulin Feng
If two slices start out with the same length and decrease in length by the same amount on each round of the loop (or in the if block), then we think their length are always equal. For example: if len(a) != len(b) { return } for len(a) >= 4 { a = a[4:] b = b[4:] // proved here, omit boundary check } if len(a) == len(b) { // proved here //... } Or, change 'for' to 'if': if len(a) != len(b) { return } if len(a) >= 4 { a = a[4:] b = b[4:] } if len(a) == len(b) { // proved here //... } Fixes #75144 Change-Id: I4e5902a02b5cf8fdc122715a7dbd2fb5e9a8f5dc Reviewed-on: https://go-review.googlesource.com/c/go/+/699155 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org>
2025-10-03cmd/compile: improve slicemask removalDavid Chase
this will be subsumed by pending changes in local slice representation, however this was easy and works well. Cherry-picked from the dev.simd branch. This CL is not necessarily SIMD specific. Apply early to reduce risk. Change-Id: I5b6eb10d257f04f906be7a8a6f2b6833992a39e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/704876 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/708866 Reviewed-by: David Chase <drchase@google.com>
2025-10-03cmd/compile: enhance prove to infer bounds in slice len/cap calculationsDavid Chase
the example comes up in chunked reslicing, e.g. A[i:] where i has a relationship with len(A)-K. Cherry-picked from the dev.simd branch. This CL is not necessarily SIMD specific. Apply early to reduce risk. Change-Id: Ib97dede6cfc7bbbd27b4f384988f741760686604 Reviewed-on: https://go-review.googlesource.com/c/go/+/704875 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/708863 Reviewed-by: David Chase <drchase@google.com>
2025-10-03cmd/compile: enhance the chunked indexing case to include reslicingDavid Chase
this helps SIMD, but also helps plain old Go Cherry-picked from the dev.simd branch. This CL is not necessarily SIMD specific. Apply early to reduce risk. Change-Id: Idcdacd54b6776f5c32b497bc94485052611cfa8d Reviewed-on: https://go-review.googlesource.com/c/go/+/704756 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/708862 Reviewed-by: David Chase <drchase@google.com>
2025-10-03cmd/compile: enhance prove to deal with double-offset IsInBounds checksDavid Chase
For chunked iterations (useful for, but not exclusive to, SIMD calculations) it is common to see the combination of ``` for ; i <= len(m)-4; i += 4 { ``` and ``` r0, r1, r2, r3 := m[i], m[i+1], m[i+2], m[i+3] `` Prove did not handle the case of len-offset1 vs index+offset2 checking, but this change fixes this. There may be other similar cases yet to handle -- this worked for the chunked loops for simd, as well as a handful in std. Cherry-picked from the dev.simd branch. This CL is not necessarily SIMD specific. Apply early to reduce risk. Change-Id: I3785df83028d517e5e5763206653b34b2befd3d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/700696 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/708859 Reviewed-by: David Chase <drchase@google.com>
2025-08-13cmd/compile: teach prove about len's & cap's max based on the element sizeJorropo
Change-Id: I88056fada1ff488c199fce54cf737dbdd091214d Reviewed-on: https://go-review.googlesource.com/c/go/+/695095 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-08-12Revert "cmd/compile/internal/ssa: Use transitive properties for len/cap"Keith Randall
This reverts commit a3295df873bb22b3ba427124b1220370a5ca5cdb (CL 679155) Reason for revert: leads to a very expensive prove pass, see #74974 (Maybe not this CL's fault, just tickling some superlinear behavior.) Change-Id: I75302c04cfc5e1e075aeb80edb73080bfb1efcac Reviewed-on: https://go-review.googlesource.com/c/go/+/695175 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Keith Randall <khr@golang.org>
2025-08-05cmd: remove dead codeqiulaidongfeng
Fixes #74076 Change-Id: Icc67b3d4e342f329584433bd1250c56ae8f5a73d Reviewed-on: https://go-review.googlesource.com/c/go/+/690635 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Alan Donovan <adonovan@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-08-05cmd/compile/internal/ssa: Use transitive properties for len/capDaniel Morsing
Remove the special casing for len/cap and rely on the posets. After removing the special logic, I ran `go build -gcflags='-d ssa/prove/debug=2' all` to verify my results. During this, I found 2 common cases where the old implicit unsigned->signed domain conversion made proving a branch possible that shouldn't be strictly possible and added these. The 2 cases are shifting a non-negative signed integer and unsigned comparisons that happen with arguments that fits entirely inside the unsigned argument Change-Id: Ic88049ff69efc5602fc15f5dad02028e704f5483 Reviewed-on: https://go-review.googlesource.com/c/go/+/679155 Reviewed-by: Mark Freeman <mark@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-07-24cmd/compile: add missing StringLen rule in proveKeith Randall
(StringLen (StringMake _ x)) == x, just like the rules we currently have for slices. This helps propagate string length knowledge to places which need it. Change-Id: Ifdcf6d1f2d430c1c4bbac32e0ea74c188eae998e Reviewed-on: https://go-review.googlesource.com/c/go/+/682777 Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
2025-07-24cmd/compile: learn transitive proofs for safe unsigned subsJorropo
I've split this into it's own CL to make git bisect more effective. Change-Id: I436ff21a3e2362b3924de25a458534eb9947e013 Reviewed-on: https://go-review.googlesource.com/c/go/+/685821 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
2025-07-24cmd/compile: learn transitive proofs for safe negative signed addsJorropo
I've split this into it's own CL to make git bisect more effective. Change-Id: Ib2c6dbc82fb04f50f2d17fbe6626c9fc322fb478 Reviewed-on: https://go-review.googlesource.com/c/go/+/685820 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-07-24cmd/compile: learn transitive proofs for safe positive signed addsJorropo
I've split this into it's own CL to make git bisect more effective. Change-Id: I3fbb42ec7d29169a29f7f55ef2c188317512f532 Reviewed-on: https://go-review.googlesource.com/c/go/+/685819 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-07-24cmd/compile: learn transitive proofs for safe unsigned addsJorropo
I've split this into it's own CL to make git bisect more effective. Change-Id: Iaab5f0bd2ad51e86ced8c6b8fbd371eb75eeef14 Reviewed-on: https://go-review.googlesource.com/c/go/+/685815 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Mark Freeman <mark@golang.org>
2025-07-08cmd/compile: run fmt on ssaJorropo
prove.go used to make my editor and precomit checks very unhappy. Change-Id: I25f7ffa2191480bc1b4f91fa91ccf3e4768045fa Reviewed-on: https://go-review.googlesource.com/c/go/+/685818 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-19cmd/compile: derive bounds on signed %N for N a power of 2Keith Randall
-N+1 <= x % N <= N-1 This is useful for cases like: func setBit(b []byte, i int) { b[i/8] |= 1<<(i%8) } The shift does not need protection against larger-than-7 cases. (It does still need protection against <0 cases.) Change-Id: Idf83101386af538548bfeb6e2928cea855610ce2 Reviewed-on: https://go-review.googlesource.com/c/go/+/672995 Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-04-11cmd/compile/internal/ssa: small cleanupsMarcel Meyer
Change-Id: I0420fb3956577c56fa24a31929331d526d480556 GitHub-Last-Rev: d74b0d4d75d4e432aaf84d02964da4a2e12d0e1b GitHub-Pull-Request: golang/go#73339 Reviewed-on: https://go-review.googlesource.com/c/go/+/664975 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org>
2025-04-11cmd/compile/internal/ssa: use built-in min, max functionMarcel Meyer
Change-Id: I6dd6e3f8a581931fcea3c3e0ac30ce450253e1d8 GitHub-Last-Rev: c476f8b9a3741a682340d3a37d6d5a9a44a56e5f GitHub-Pull-Request: golang/go#73318 Reviewed-on: https://go-review.googlesource.com/c/go/+/664615 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-03-11cmd/compile: compute bitsize from type size in prove to clean some switchesJorropo
Change-Id: I215adda9050d214576433700aed4c371a36aaaed Reviewed-on: https://go-review.googlesource.com/c/go/+/656335 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
2025-03-11cmd/compile: compute bits.OnesCount's limits from argument's limitsJorropo
Change-Id: Ia90d48ea0fab363c8592221fad88958b522edefe Reviewed-on: https://go-review.googlesource.com/c/go/+/656159 Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-11cmd/compile: set bits.OnesCount's limits to [0, 64]Jorropo
Change-Id: I2f60de836f58ef91baae856f44d8f73c190326f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/656158 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org>
2025-03-11cmd/compile: compute min's & max's limits from argument's limits inside ↵Jorropo
flowLimit Updates #68857 Change-Id: Ied07e656bba42f3b1b5f9b9f5442806aa2e7959b Reviewed-on: https://go-review.googlesource.com/c/go/+/656157 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
2025-02-20cmd/compile: don't report newLimit discovered when unsat happens multiple timesJorropo
Fixes #71852 Change-Id: I696fcb8fc8c0c2e5e5ae6ab50596f6bdb9b7d498 Reviewed-on: https://go-review.googlesource.com/c/go/+/650975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-02-05cmd/compile: establish limits of bool to uint8 conversionsJakub Ciolek
Improves bound check elimination for: func arrayLargeEnough(b bool, a [2]int64) int64 { c := byte(0) if b { c = 1 } // this bound check gets elided return a[c] } We also detect never true branches like: func cCanOnlyBe0or1(b bool) byte { var c byte if b { c = 1 } // this statement can never be true so we can elide it if c == 2 { c = 3 } return c } Hits a few times: crypto/internal/sysrand crypto/internal/sysrand.Read 357 -> 349 (-2.24%) testing testing.(*F).Fuzz.func1.1 837 -> 828 (-1.08%) image/png image/png.(*Encoder).Encode 1735 -> 1733 (-0.12%) vendor/golang.org/x/crypto/cryptobyte vendor/golang.org/x/crypto/cryptobyte.(*Builder).callContinuation 187 -> 185 (-1.07%) crypto/internal/sysrand [cmd/compile] crypto/internal/sysrand.Read 357 -> 349 (-2.24%) go/parser go/parser.(*parser).parseType 463 -> 457 (-1.30%) go/parser.(*parser).embeddedElem 633 -> 626 (-1.11%) go/parser.(*parser).parseFuncDecl 917 -> 914 (-0.33%) go/parser.(*parser).parseDotsType 393 -> 391 (-0.51%) go/parser.(*parser).error 1061 -> 1054 (-0.66%) go/parser.(*parser).parseTypeName 537 -> 532 (-0.93%) go/parser.(*parser).parseParamDecl 1478 -> 1451 (-1.83%) go/parser.(*parser).parseFuncTypeOrLit 498 -> 495 (-0.60%) go/parser.(*parser).parseValue 375 -> 371 (-1.07%) go/parser.(*parser).parseElementList 594 -> 593 (-0.17%) go/parser.(*parser).parseResult 593 -> 583 (-1.69%) go/parser.(*parser).parseElement 506 -> 504 (-0.40%) go/parser.(*parser).parseImportSpec 1110 -> 1108 (-0.18%) go/parser.(*parser).parseStructType 741 -> 735 (-0.81%) go/parser.(*parser).parseTypeSpec 1054 -> 1048 (-0.57%) go/parser.(*parser).parseIdentList 625 -> 623 (-0.32%) go/parser.(*parser).parseOperand 1221 -> 1199 (-1.80%) go/parser.(*parser).parseIndexOrSliceOrInstance 2713 -> 2694 (-0.70%) go/parser.(*parser).parseSwitchStmt 1458 -> 1447 (-0.75%) go/parser.(*parser).parseArrayFieldOrTypeInstance 1865 -> 1861 (-0.21%) go/parser.(*parser).parseExpr 307 -> 305 (-0.65%) go/parser.(*parser).parseSelector 427 -> 425 (-0.47%) go/parser.(*parser).parseTypeInstance 1433 -> 1420 (-0.91%) go/parser.(*parser).parseCaseClause 629 -> 626 (-0.48%) go/parser.(*parser).parseParameterList 4212 -> 4189 (-0.55%) go/parser.(*parser).parsePointerType 393 -> 391 (-0.51%) go/parser.(*parser).parseFuncType 465 -> 463 (-0.43%) go/parser.(*parser).parseTypeAssertion 559 -> 557 (-0.36%) go/parser.(*parser).parseSimpleStmt 2443 -> 2388 (-2.25%) go/parser.(*parser).parseCallOrConversion 1093 -> 1087 (-0.55%) go/parser.(*parser).parseForStmt 2168 -> 2159 (-0.42%) go/parser.(*parser).embeddedTerm 657 -> 649 (-1.22%) go/parser.(*parser).parseCommClause 1509 -> 1501 (-0.53%) cmd/internal/objfile cmd/internal/objfile.(*goobjFile).symbols 5299 -> 5274 (-0.47%) net net.initConfVal 378 -> 374 (-1.06%) net.(*conf).hostLookupOrder 269 -> 267 (-0.74%) net.(*conf).addrLookupOrder 261 -> 255 (-2.30%) cmd/internal/obj/loong64 cmd/internal/obj/loong64.(*ctxt0).oplook 1829 -> 1813 (-0.87%) cmd/internal/obj/mips cmd/internal/obj/mips.(*ctxt0).oplook 1428 -> 1400 (-1.96%) go/types go/types.(*typeWriter).signature 605 -> 601 (-0.66%) go/types.(*Checker).instantiateSignature 1469 -> 1467 (-0.14%) go/parser [cmd/compile] go/parser.(*parser).parseSwitchStmt 1458 -> 1447 (-0.75%) go/parser.(*parser).parseDotsType 393 -> 391 (-0.51%) go/parser.(*parser).embeddedElem 633 -> 626 (-1.11%) go/parser.(*parser).parseTypeAssertion 559 -> 557 (-0.36%) go/parser.(*parser).parseCommClause 1509 -> 1501 (-0.53%) go/parser.(*parser).parseCaseClause 629 -> 626 (-0.48%) go/parser.(*parser).parseImportSpec 1110 -> 1108 (-0.18%) go/parser.(*parser).parseTypeSpec 1054 -> 1048 (-0.57%) go/parser.(*parser).parseElementList 594 -> 593 (-0.17%) go/parser.(*parser).parseParamDecl 1478 -> 1451 (-1.83%) go/parser.(*parser).parseType 463 -> 457 (-1.30%) go/parser.(*parser).parseSimpleStmt 2443 -> 2388 (-2.25%) go/parser.(*parser).parseIdentList 625 -> 623 (-0.32%) go/parser.(*parser).parseTypeInstance 1433 -> 1420 (-0.91%) go/parser.(*parser).parseResult 593 -> 583 (-1.69%) go/parser.(*parser).parseValue 375 -> 371 (-1.07%) go/parser.(*parser).parseFuncDecl 917 -> 914 (-0.33%) go/parser.(*parser).error 1061 -> 1054 (-0.66%) go/parser.(*parser).parseElement 506 -> 504 (-0.40%) go/parser.(*parser).parseFuncType 465 -> 463 (-0.43%) go/parser.(*parser).parsePointerType 393 -> 391 (-0.51%) go/parser.(*parser).parseTypeName 537 -> 532 (-0.93%) go/parser.(*parser).parseExpr 307 -> 305 (-0.65%) go/parser.(*parser).parseFuncTypeOrLit 498 -> 495 (-0.60%) go/parser.(*parser).parseStructType 741 -> 735 (-0.81%) go/parser.(*parser).parseOperand 1221 -> 1199 (-1.80%) go/parser.(*parser).parseIndexOrSliceOrInstance 2713 -> 2694 (-0.70%) go/parser.(*parser).parseForStmt 2168 -> 2159 (-0.42%) go/parser.(*parser).parseParameterList 4212 -> 4189 (-0.55%) go/parser.(*parser).parseArrayFieldOrTypeInstance 1865 -> 1861 (-0.21%) go/parser.(*parser).parseSelector 427 -> 425 (-0.47%) go/parser.(*parser).parseCallOrConversion 1093 -> 1087 (-0.55%) go/parser.(*parser).embeddedTerm 657 -> 649 (-1.22%) crypto/tls crypto/tls.(*Conn).clientHandshake 3430 -> 3421 (-0.26%) cmd/internal/obj/mips [cmd/compile] cmd/internal/obj/mips.(*ctxt0).oplook 1428 -> 1400 (-1.96%) cmd/internal/obj/loong64 [cmd/compile] cmd/internal/obj/loong64.(*ctxt0).oplook 1829 -> 1813 (-0.87%) cmd/compile/internal/types2 cmd/compile/internal/types2.(*typeWriter).signature 605 -> 601 (-0.66%) cmd/compile/internal/types2.(*Checker).infer 10646 -> 10614 (-0.30%) cmd/compile/internal/types2.(*Checker).instantiateSignature 1567 -> 1561 (-0.38%) cmd/compile/internal/types2 [cmd/compile] cmd/compile/internal/types2.(*Checker).instantiateSignature 1567 -> 1561 (-0.38%) cmd/compile/internal/types2.(*typeWriter).signature 605 -> 601 (-0.66%) cmd/compile/internal/types2.(*Checker).infer 10718 -> 10654 (-0.60%) cmd/vendor/golang.org/x/arch/s390x/s390xasm cmd/vendor/golang.org/x/arch/s390x/s390xasm.GoSyntax 36778 -> 36682 (-0.26%) net/http net/http.(*Client).do 4202 -> 4170 (-0.76%) net/http.(*http2clientStream).writeRequest 3692 -> 3686 (-0.16%) cmd/vendor/github.com/ianlancetaylor/demangle cmd/vendor/github.com/ianlancetaylor/demangle.(*rustState).genericArgs 466 -> 463 (-0.64%) cmd/compile/internal/devirtualize cmd/compile/internal/devirtualize.ProfileGuided.func1 1364 -> 1357 (-0.51%) cmd/compile/internal/inline/interleaved cmd/compile/internal/inline/interleaved.DevirtualizeAndInlinePackage.func2 533 -> 526 (-1.31%) cmd/compile/internal/devirtualize [cmd/compile] cmd/compile/internal/devirtualize.ProfileGuided.func1 1343 -> 1332 (-0.82%) cmd/compile/internal/inline/interleaved [cmd/compile] cmd/compile/internal/inline/interleaved.DevirtualizeAndInlinePackage.func2 533 -> 526 (-1.31%) cmd/link/internal/ld cmd/link/internal/ld.mustLinkExternal 2739 -> 2674 (-2.37%) cmd/compile/internal/ssa cmd/compile/internal/ssa.(*poset).Ordered 391 -> 389 (-0.51%) cmd/compile/internal/ssa.(*poset).Equal 318 -> 313 (-1.57%) cmd/compile/internal/ssa.(*poset).Undo 1842 -> 1832 (-0.54%) cmd/compile/internal/ssa.(*expandState).decomposeAsNecessary 4587 -> 4555 (-0.70%) cmd/compile/internal/ssa.(*poset).OrderedOrEqual 390 -> 389 (-0.26%) cmd/compile/internal/ssa.(*poset).NonEqual 613 -> 606 (-1.14%) cmd/compile/internal/ssa [cmd/compile] cmd/compile/internal/ssa.(*poset).OrderedOrEqual 368 -> 365 (-0.82%) cmd/compile/internal/ssa.(*poset).Equal 318 -> 313 (-1.57%) cmd/compile/internal/ssa.(*expandState).decomposeAsNecessary 4952 -> 4938 (-0.28%) cmd/compile/internal/ssa.(*poset).NonEqual 613 -> 606 (-1.14%) cmd/compile/internal/ssa.(*poset).SetEqual 2533 -> 2505 (-1.11%) cmd/compile/internal/ssa.(*poset).SetNonEqual 785 -> 777 (-1.02%) cmd/compile/internal/ssa.(*poset).Ordered 370 -> 366 (-1.08%) cmd/compile/internal/gc [cmd/compile] cmd/compile/internal/gc.Main.DevirtualizeAndInlinePackage.func2 492 -> 489 (-0.61%) file before after Δ % crypto/internal/sysrand.s 1553 1545 -8 -0.515% internal/zstd.s 49179 49190 +11 +0.022% testing.s 115197 115188 -9 -0.008% image/png.s 36109 36107 -2 -0.006% vendor/golang.org/x/crypto/cryptobyte.s 30980 30978 -2 -0.006% crypto/internal/sysrand [cmd/compile].s 1553 1545 -8 -0.515% go/parser.s 112638 112354 -284 -0.252% cmd/internal/objfile.s 49994 49969 -25 -0.050% net.s 299558 299546 -12 -0.004% cmd/internal/obj/loong64.s 71651 71635 -16 -0.022% cmd/internal/obj/mips.s 59681 59653 -28 -0.047% go/types.s 558839 558833 -6 -0.001% cmd/compile/internal/types.s 71305 71306 +1 +0.001% go/parser [cmd/compile].s 112749 112465 -284 -0.252% crypto/tls.s 388859 388850 -9 -0.002% cmd/internal/obj/mips [cmd/compile].s 59792 59764 -28 -0.047% cmd/internal/obj/loong64 [cmd/compile].s 71762 71746 -16 -0.022% cmd/compile/internal/types2.s 540608 540566 -42 -0.008% cmd/compile/internal/types2 [cmd/compile].s 577428 577354 -74 -0.013% cmd/vendor/golang.org/x/arch/s390x/s390xasm.s 267664 267568 -96 -0.036% net/http.s 620704 620666 -38 -0.006% cmd/vendor/github.com/ianlancetaylor/demangle.s 299991 299988 -3 -0.001% cmd/compile/internal/devirtualize.s 21452 21445 -7 -0.033% cmd/compile/internal/inline/interleaved.s 8358 8351 -7 -0.084% cmd/compile/internal/devirtualize [cmd/compile].s 20994 20983 -11 -0.052% cmd/compile/internal/inline/interleaved [cmd/compile].s 8328 8321 -7 -0.084% cmd/link/internal/ld.s 641802 641737 -65 -0.010% cmd/compile/internal/ssa.s 3552939 3552957 +18 +0.001% cmd/compile/internal/ssa [cmd/compile].s 3752191 3752197 +6 +0.000% cmd/compile/internal/ssagen.s 405780 405786 +6 +0.001% cmd/compile/internal/ssagen [cmd/compile].s 434472 434496 +24 +0.006% cmd/compile/internal/gc [cmd/compile].s 38499 38496 -3 -0.008% total 36185267 36184243 -1024 -0.003% Change-Id: I867222b0f907b29d32b2676e55c6b5789ec56511 Reviewed-on: https://go-review.googlesource.com/c/go/+/642716 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org>