aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/prove.go
AgeCommit message (Collapse)Author
2023-01-24Revert "cmd/compile: teach prove about bitwise OR operation"Keith Randall
This reverts commit 3680b5e9c4f42fcf9155aa42b3b344d1fbe19571. Reason for revert: causes long compile times on certain functions. See issue #57959 Change-Id: Ie9e881ca8abbc79a46de2bfeaed0b9d6c416ed42 Reviewed-on: https://go-review.googlesource.com/c/go/+/463295 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2023-01-23cmd/compile: teach prove about unsigned division, modulus and rshJorropo
Fixes: #57077 Change-Id: Icffcac42e28622eadecdba26e3cd7ceca6c4aacc Reviewed-on: https://go-review.googlesource.com/c/go/+/455095 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com>
2022-11-18all: add missing periods in commentscui fliter
Change-Id: I69065f8adf101fdb28682c55997f503013a50e29 Reviewed-on: https://go-review.googlesource.com/c/go/+/449757 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-10cmd/compile: teach prove about signed domain relations of constant integer Phi'sJakub Ciolek
Implement extracting signed domain relations for OpPhi's composed entirely of integer constants. darwin/arm benches (M1 Pro): EqIfaceConcrete-10 0.83ns ± 0% 0.78ns ± 0% -6.52% p=0.000 n=8+9 ) ConvT2EByteSized/bool-10 1.33ns ± 0% 1.25ns ± 0% -6.4% ( p=0.000 n=9+8 ) ConvT2EByteSized/uint8-10 1.27ns ± 1% 1.25ns ± 0% -1.82%( p=0.000 n=8+8 ) ConvT2ESmall-10 2.18ns ± 0% 2.14ns ± 1% -1.97%( p=0.000 n=9+9 ) compilecmp linux/amd64 reports a 1.4% reduction in total size: file before after Δ % unicode/utf8.s 4251 4317 +66 +1.553% runtime/internal/sys.s 599 593 -6 -1.002% sync/atomic.s 2277 1695 -582 -25.560% internal/cpu.s 5412 5249 -163 -3.012% internal/abi.s 1006 1045 +39 +3.877% container/list.s 4821 4858 +37 +0.767% unicode/utf16.s 1162 868 -294 -25.301% hash/maphash.s 2525 2625 +100 +3.960% image/color.s 7414 7045 -369 -4.977% math.s 37278 37246 -32 -0.086% math/cmplx.s 8868 8876 +8 +0.090% runtime.s 496893 486910 -9983 -2.009% runtime/metrics.s 1145 1165 +20 +1.747% sync.s 14257 15049 +792 +5.555% internal/singleflight.s 2557 2576 +19 +0.743% internal/reflectlite.s 59715 21713 -38002 -63.639% math/rand.s 10153 9980 -173 -1.704% path.s 6007 6091 +84 +1.398% sort.s 20704 20717 +13 +0.063% io.s 19708 18899 -809 -4.105% container/heap.s 1922 1932 +10 +0.520% cmd/vendor/golang.org/x/mod/semver.s 8013 7922 -91 -1.136% strconv.s 50530 49955 -575 -1.138% vendor/golang.org/x/net/dns/dnsmessage.s 79054 80314 +1260 +1.594% bytes.s 31195 31448 +253 +0.811% text/tabwriter.s 8952 9037 +85 +0.950% strings.s 43052 41627 -1425 -3.310% crypto/internal/nistec/fiat.s 124219 123197 -1022 -0.823% syscall.s 85224 84600 -624 -0.732% hash/adler32.s 1224 1221 -3 -0.245% encoding/ascii85.s 4131 4149 +18 +0.436% hash/crc32.s 6304 6347 +43 +0.682% encoding/base32.s 8466 8473 +7 +0.083% vendor/golang.org/x/text/transform.s 15633 16050 +417 +2.667% bufio.s 24464 22091 -2373 -9.700% reflect.s 258373 164941 -93432 -36.162% internal/syscall/unix.s 1730 1299 -431 -24.913% go/build/constraint.s 12959 13581 +622 +4.800% hash/crc64.s 3604 3673 +69 +1.915% hash/fnv.s 4482 4609 +127 +2.834% compress/bzip2.s 9586 9891 +305 +3.182% time.s 92081 89953 -2128 -2.311% regexp/syntax.s 78123 78293 +170 +0.218% internal/saferio.s 1746 1635 -111 -6.357% html.s 4228 4233 +5 +0.118% encoding/binary.s 31383 31282 -101 -0.322% image.s 37513 38082 +569 +1.517% internal/poll.s 45486 43956 -1530 -3.364% context.s 11096 10804 -292 -2.632% io/fs.s 16921 18609 +1688 +9.976% regexp.s 58983 58790 -193 -0.327% crypto/cipher.s 18686 18718 +32 +0.171% crypto/internal/edwards25519/field.s 9473 9488 +15 +0.158% crypto/sha1.s 6477 6537 +60 +0.926% encoding/base64.s 10615 10215 -400 -3.768% vendor/golang.org/x/crypto/internal/poly1305.s 4522 4567 +45 +0.995% cmd/internal/sys.s 4729 4965 +236 +4.990% os.s 53819 53697 -122 -0.227% embed.s 6428 6437 +9 +0.140% crypto/des.s 5770 5762 -8 -0.139% encoding/pem.s 6425 6467 +42 +0.654% crypto/internal/edwards25519.s 31850 31948 +98 +0.308% image/draw.s 28660 28594 -66 -0.230% image/jpeg.s 32246 32385 +139 +0.431% index/suffixarray.s 38665 38627 -38 -0.098% crypto/hmac.s 2546 2437 -109 -4.281% fmt.s 70412 71396 +984 +1.397% crypto/sha256.s 5708 5683 -25 -0.438% crypto/sha512.s 8346 8313 -33 -0.395% crypto/aes.s 11586 11231 -355 -3.064% path/filepath.s 16499 16438 -61 -0.370% crypto/internal/nistec.s 65640 65713 +73 +0.111% internal/lazyregexp.s 2389 2284 -105 -4.395% internal/intern.s 2988 3266 +278 +9.304% os/user.s 12166 12106 -60 -0.493% compress/lzw.s 7292 7264 -28 -0.384% encoding/hex.s 5431 5405 -26 -0.479% compress/flate.s 46812 47932 +1120 +2.393% net/url.s 26853 26638 -215 -0.801% crypto/ecdh.s 10015 12228 +2213 +22.097% vendor/golang.org/x/sys/cpu.s 5877 5599 -278 -4.730% database/sql/driver.s 16553 16671 +118 +0.713% net/netip.s 39077 40164 +1087 +2.782% debug/plan9obj.s 6765 6679 -86 -1.271% math/big.s 160530 161099 +569 +0.354% archive/tar.s 59285 59692 +407 +0.687% debug/dwarf.s 117589 116367 -1222 -1.039% compress/gzip.s 8288 8255 -33 -0.398% archive/zip.s 51813 49835 -1978 -3.818% compress/zlib.s 6206 6209 +3 +0.048% runtime/debug.s 11995 12212 +217 +1.809% database/sql.s 91280 90859 -421 -0.461% crypto/dsa.s 4816 4784 -32 -0.664% net.s 272116 271353 -763 -0.280% crypto/elliptic.s 30485 32898 +2413 +7.915% encoding/asn1.s 47189 48186 +997 +2.113% crypto/rand.s 3812 3801 -11 -0.289% debug/macho.s 30712 27800 -2912 -9.482% debug/pe.s 23198 23542 +344 +1.483% debug/elf.s 50653 50335 -318 -0.628% internal/xcoff.s 18330 18578 +248 +1.353% debug/gosym.s 37011 34275 -2736 -7.392% encoding/csv.s 11440 11497 +57 +0.498% encoding/json.s 95650 92269 -3381 -3.535% vendor/golang.org/x/crypto/cryptobyte.s 31261 31418 +157 +0.502% encoding/gob.s 131648 132481 +833 +0.633% crypto/x509/pkix.s 9030 9285 +255 +2.824% crypto/rsa.s 25753 25620 -133 -0.516% debug/buildinfo.s 7329 7360 +31 +0.423% log.s 12153 12554 +401 +3.300% encoding/xml.s 90630 91544 +914 +1.008% net/textproto.s 17674 15707 -1967 -11.129% vendor/golang.org/x/text/unicode/norm.s 66104 66296 +192 +0.290% vendor/golang.org/x/net/http2/hpack.s 23542 24291 +749 +3.182% mime/quotedprintable.s 5074 5106 +32 +0.631% mime.s 32982 32673 -309 -0.937% net/http/internal.s 5765 4748 -1017 -17.641% flag.s 25247 25434 +187 +0.741% vendor/golang.org/x/text/unicode/bidi.s 30444 30707 +263 +0.864% go/token.s 13689 14075 +386 +2.820% go/doc/comment.s 49201 47717 -1484 -3.016% internal/buildcfg.s 10468 9949 -519 -4.958% text/scanner.s 9812 9814 +2 +0.020% os/exec.s 34367 29498 -4869 -14.168% mime/multipart.s 17568 17083 -485 -2.761% image/gif.s 22965 22826 -139 -0.605% crypto/x509.s 142551 139844 -2707 -1.899% text/template/parse.s 82771 94885 +12114 +14.636% go/scanner.s 17306 17321 +15 +0.087% internal/dag.s 13123 13368 +245 +1.867% go/constant.s 29736 32872 +3136 +10.546% image/png.s 37126 37013 -113 -0.304% internal/goroot.s 3080 3212 +132 +4.286% internal/diff.s 7561 7909 +348 +4.603% vendor/golang.org/x/net/idna.s 22454 22493 +39 +0.174% go/ast.s 63945 68792 +4847 +7.580% internal/pkgbits.s 19638 19838 +200 +1.018% text/template.s 107139 100338 -6801 -6.348% runtime/trace.s 2844 2762 -82 -2.883% internal/txtar.s 2495 2483 -12 -0.481% internal/profile.s 117110 118516 +1406 +1.201% log/syslog.s 6615 6625 +10 +0.151% vendor/golang.org/x/net/http/httpguts.s 3558 3580 +22 +0.618% crypto/tls.s 298298 292244 -6054 -2.030% internal/trace.s 69626 67477 -2149 -3.086% vendor/golang.org/x/net/http/httpproxy.s 8164 7942 -222 -2.719% go/doc.s 69092 71449 +2357 +3.411% go/internal/typeparams.s 1465 1338 -127 -8.669% go/printer.s 90427 82948 -7479 -8.271% html/template.s 91720 90853 -867 -0.945% runtime/pprof.s 70261 69793 -468 -0.666% testing.s 107098 98982 -8116 -7.578% net/internal/socktest.s 15715 15469 -246 -1.565% net/mail.s 17762 18044 +282 +1.588% net/smtp.s 11295 11484 +189 +1.673% os/signal.s 7647 7779 +132 +1.726% go/parser.s 111336 116170 +4834 +4.342% testing/iotest.s 13339 13379 +40 +0.300% testing/quick.s 8493 8516 +23 +0.271% cmd/internal/bio.s 11994 8754 -3240 -27.014% internal/testenv.s 7067 6779 -288 -4.075% vendor/golang.org/x/net/nettest.s 27692 27770 +78 +0.282% cmd/internal/objabi.s 15031 14718 -313 -2.082% cmd/internal/src.s 14507 14515 +8 +0.055% cmd/vendor/golang.org/x/arch/arm/armasm.s 33278 33864 +586 +1.761% go/format.s 4517 4725 +208 +4.605% go/build.s 67444 70250 +2806 +4.160% testing/fstest.s 53785 52941 -844 -1.569% cmd/vendor/golang.org/x/arch/arm64/arm64asm.s 86346 87156 +810 +0.938% cmd/internal/goobj.s 12262 12327 +65 +0.530% internal/fuzz.s 88446 89608 +1162 +1.314% cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.s 36435 37026 +591 +1.622% cmd/internal/dwarf.s 28919 29476 +557 +1.926% cmd/internal/edit.s 3375 3428 +53 +1.570% cmd/vendor/golang.org/x/arch/x86/x86asm.s 70465 70187 -278 -0.395% cmd/internal/pkgpath.s 4922 4422 -500 -10.158% net/http.s 548512 541160 -7352 -1.340% cmd/internal/archive.s 11103 11111 +8 +0.072% testing/internal/testdeps.s 6384 6427 +43 +0.674% cmd/internal/quoted.s 2374 2708 +334 +14.069% cmd/compile/internal/abt.s 15188 14795 -393 -2.588% cmd/internal/gcprog.s 6090 6131 +41 +0.673% cmd/internal/codesign.s 4395 4406 +11 +0.250% go/types.s 478152 479038 +886 +0.185% cmd/internal/obj.s 121049 114662 -6387 -5.276% cmd/compile/internal/syntax.s 157912 156897 -1015 -0.643% expvar.s 8906 8586 -320 -3.593% net/http/cgi.s 17411 17782 +371 +2.131% net/http/cookiejar.s 13763 13931 +168 +1.221% net/http/httptest.s 16213 16785 +572 +3.528% net/http/pprof.s 14556 14739 +183 +1.257% net/http/httputil.s 43808 44406 +598 +1.365% net/rpc.s 32868 30581 -2287 -6.958% go/internal/gccgoimporter.s 45024 45409 +385 +0.855% go/internal/gcimporter.s 58540 53044 -5496 -9.388% go/internal/srcimporter.s 10011 10451 +440 +4.395% net/http/fcgi.s 18344 18039 -305 -1.663% cmd/internal/objfile.s 45853 46153 +300 +0.654% cmd/api.s 34943 35806 +863 +2.470% cmd/internal/obj/arm.s 61126 61156 +30 +0.049% net/rpc/jsonrpc.s 5601 5271 -330 -5.892% cmd/internal/obj/loong64.s 45594 45335 -259 -0.568% cmd/internal/obj/arm64.s 140572 140006 -566 -0.403% cmd/internal/obj/mips.s 53672 53637 -35 -0.065% go/importer.s 1989 2169 +180 +9.050% cmd/internal/obj/riscv.s 56721 56877 +156 +0.275% cmd/addr2line.s 1930 1906 -24 -1.244% cmd/internal/obj/ppc64.s 137317 115306 -22011 -16.029% cmd/internal/obj/wasm.s 34091 34162 +71 +0.208% cmd/internal/obj/s390x.s 110244 110444 +200 +0.181% cmd/asm/internal/flags.s 2234 2351 +117 +5.237% cmd/internal/obj/x86.s 86811 87534 +723 +0.833% cmd/internal/buildid.s 17303 17156 -147 -0.850% cmd/compile/internal/base.s 29582 29675 +93 +0.314% cmd/compile/internal/logopt.s 9859 9943 +84 +0.852% cmd/cgo.s 198958 203063 +4105 +2.063% cmd/internal/browser.s 1751 1803 +52 +2.970% cmd/vendor/golang.org/x/tools/cover.s 9752 9759 +7 +0.072% cmd/asm/internal/lex.s 22668 21352 -1316 -5.806% cmd/asm/internal/arch.s 27642 29863 +2221 +8.035% cmd/compile/internal/bitvec.s 5535 5542 +7 +0.126% cmd/compile/internal/types.s 74646 74488 -158 -0.212% cmd/dist.s 185287 184450 -837 -0.452% cmd/compile/internal/types2.s 477270 470783 -6487 -1.359% cmd/cover.s 29563 31341 +1778 +6.014% cmd/doc.s 54013 53299 -714 -1.322% cmd/go/internal/fsys.s 16751 16944 +193 +1.152% cmd/fix.s 64367 65866 +1499 +2.329% cmd/asm/internal/asm.s 60266 60767 +501 +0.831% cmd/compile/internal/ir.s 252952 187941 -65011 -25.701% cmd/go/internal/str.s 3582 3690 +108 +3.015% cmd/go/internal/lockedfile/internal/filelock.s 2062 1960 -102 -4.947% cmd/go/internal/cfg.s 11331 11253 -78 -0.688% cmd/asm.s 2461 2474 +13 +0.528% cmd/compile/internal/deadcode.s 5576 5812 +236 +4.232% cmd/compile/internal/objw.s 5553 5450 -103 -1.855% cmd/go/internal/par.s 4473 4378 -95 -2.124% cmd/compile/internal/abi.s 19219 19382 +163 +0.848% cmd/go/internal/lockedfile.s 22412 14422 -7990 -35.651% cmd/go/internal/auth.s 2218 2250 +32 +1.443% cmd/vendor/golang.org/x/mod/internal/lazyregexp.s 2389 2284 -105 -4.395% cmd/go/internal/base.s 10079 10177 +98 +0.972% cmd/go/internal/imports.s 16417 16159 -258 -1.572% cmd/go/internal/trace.s 4888 4895 +7 +0.143% cmd/go/internal/web.s 12130 12007 -123 -1.014% cmd/vendor/golang.org/x/mod/sumdb/tlog.s 27662 28441 +779 +2.816% cmd/vendor/golang.org/x/mod/module.s 20503 20758 +255 +1.244% cmd/vendor/golang.org/x/mod/sumdb/dirhash.s 3599 3601 +2 +0.056% cmd/go/internal/cache.s 23949 24705 +756 +3.157% cmd/go/internal/cmdflag.s 3769 3748 -21 -0.557% cmd/go/internal/search.s 15584 15917 +333 +2.137% cmd/vendor/golang.org/x/mod/sumdb/note.s 14260 14347 +87 +0.610% cmd/internal/test2json.s 8706 8575 -131 -1.505% cmd/go/internal/tool.s 2762 2756 -6 -0.217% cmd/vendor/golang.org/x/mod/zip.s 36841 37335 +494 +1.341% cmd/go/internal/mvs.s 27581 30511 +2930 +10.623% cmd/go/internal/modfetch/codehost.s 80858 76219 -4639 -5.737% cmd/go/internal/version.s 3050 3046 -4 -0.131% cmd/vendor/golang.org/x/mod/modfile.s 99002 98074 -928 -0.937% cmd/go/internal/test/internal/genflags.s 2025 2032 +7 +0.346% cmd/vendor/golang.org/x/sync/semaphore.s 2220 2210 -10 -0.450% cmd/go/internal/vcs.s 43959 45346 +1387 +3.155% cmd/vendor/golang.org/x/mod/sumdb.s 27952 28265 +313 +1.120% cmd/go/internal/modindex.s 79377 82223 +2846 +3.585% cmd/compile/internal/typecheck.s 317102 310352 -6750 -2.129% cmd/link/internal/benchmark.s 3621 3680 +59 +1.629% cmd/link/internal/sym.s 1816 1805 -11 -0.606% cmd/go/internal/modconv.s 14909 14895 -14 -0.094% cmd/gofmt.s 29575 29779 +204 +0.690% cmd/link/internal/dwtest.s 3879 3909 +30 +0.773% cmd/vendor/golang.org/x/sys/unix.s 118975 119232 +257 +0.216% cmd/nm.s 4675 4718 +43 +0.920% cmd/go/internal/modfetch.s 111400 112088 +688 +0.618% cmd/compile/internal/compare.s 11311 10693 -618 -5.464% cmd/compile/internal/staticdata.s 14014 14277 +263 +1.877% cmd/compile/internal/devirtualize.s 2548 2144 -404 -15.856% cmd/compile/internal/inline.s 37591 37993 +402 +1.069% cmd/compile/internal/escape.s 69777 68692 -1085 -1.555% cmd/compile/internal/importer.s 52920 48544 -4376 -8.269% cmd/internal/osinfo.s 501 698 +197 +39.321% cmd/link/internal/loader.s 79034 75315 -3719 -4.706% cmd/pack.s 8512 8600 +88 +1.034% cmd/vendor/github.com/google/pprof/internal/elfexec.s 5636 5711 +75 +1.331% cmd/vendor/github.com/google/pprof/profile.s 143898 145834 +1936 +1.345% cmd/compile/internal/reflectdata.s 80184 81399 +1215 +1.515% cmd/vendor/golang.org/x/term.s 24431 24478 +47 +0.192% cmd/go/internal/modload.s 273375 282247 +8872 +3.245% cmd/link/internal/loadpe.s 19813 17572 -2241 -11.311% cmd/link/internal/loadmacho.s 20848 20767 -81 -0.389% cmd/link/internal/loadelf.s 24458 23896 -562 -2.298% cmd/link/internal/loadxcoff.s 11183 8913 -2270 -20.299% cmd/vendor/github.com/ianlancetaylor/demangle.s 264095 268313 +4218 +1.597% cmd/compile/internal/staticinit.s 13176 13292 +116 +0.880% cmd/go/internal/help.s 5180 5320 +140 +2.703% cmd/go/internal/workcmd.s 17702 17368 -334 -1.887% cmd/test2json.s 1581 1427 -154 -9.741% cmd/vendor/github.com/google/pprof/internal/measurement.s 8449 8700 +251 +2.971% cmd/go/internal/load.s 123087 125064 +1977 +1.606% cmd/vendor/golang.org/x/tools/internal/analysisinternal.s 11481 12506 +1025 +8.928% cmd/vendor/golang.org/x/tools/internal/typeparams.s 15239 15796 +557 +3.655% cmd/vendor/github.com/google/pprof/internal/symbolz.s 4760 4805 +45 +0.945% cmd/vendor/github.com/google/pprof/internal/binutils.s 37975 37526 -449 -1.182% cmd/vendor/github.com/google/pprof/internal/graph.s 47850 47968 +118 +0.247% cmd/go/internal/fmtcmd.s 2319 2373 +54 +2.329% cmd/vendor/github.com/google/pprof/internal/symbolizer.s 10195 10268 +73 +0.716% cmd/vendor/golang.org/x/tools/go/analysis.s 5790 6021 +231 +3.990% cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil.s 2246 2519 +273 +12.155% cmd/vendor/golang.org/x/tools/go/types/objectpath.s 15720 16601 +881 +5.604% cmd/vendor/golang.org/x/tools/go/ast/inspector.s 4537 5777 +1240 +27.331% cmd/go/internal/modcmd.s 47192 47738 +546 +1.157% cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags.s 13575 14348 +773 +5.694% cmd/vendor/github.com/google/pprof/internal/report.s 79257 80089 +832 +1.050% cmd/link/internal/ld.s 553166 554375 +1209 +0.219% cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl.s 29123 29957 +834 +2.864% cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect.s 638 818 +180 +28.213% cmd/vendor/golang.org/x/tools/go/analysis/internal/facts.s 12934 13735 +801 +6.193% cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag.s 6903 7148 +245 +3.549% cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall.s 7953 8549 +596 +7.494% cmd/go/internal/work.s 271866 275488 +3622 +1.332% cmd/trace.s 98068 98671 +603 +0.615% cmd/vendor/github.com/google/pprof/internal/driver.s 145066 145844 +778 +0.536% cmd/link/internal/amd64.s 15589 15625 +36 +0.231% cmd/link/internal/arm.s 16490 16541 +51 +0.309% cmd/link/internal/arm64.s 31835 31684 -151 -0.474% cmd/go/internal/envcmd.s 21012 20787 -225 -1.071% cmd/go/internal/clean.s 9306 9233 -73 -0.784% cmd/go/internal/fix.s 1906 2086 +180 +9.444% cmd/go/internal/generate.s 10509 10758 +249 +2.369% cmd/go/internal/get.s 13782 14075 +293 +2.126% cmd/go/internal/run.s 4852 4914 +62 +1.278% cmd/go/internal/list.s 19576 19097 -479 -2.447% cmd/go/internal/bug.s 6253 5720 -533 -8.524% cmd/go/internal/modget.s 58449 59583 +1134 +1.940% cmd/go/internal/vet.s 7384 7228 -156 -2.113% cmd/go/internal/test.s 59654 60193 +539 +0.904% cmd/link/internal/riscv64.s 9856 9931 +75 +0.761% cmd/link/internal/ppc64.s 28471 27046 -1425 -5.005% cmd/link/internal/s390x.s 15081 15524 +443 +2.937% cmd/link/internal/wasm.s 16770 16817 +47 +0.280% cmd/link/internal/x86.s 14008 14093 +85 +0.607% cmd/vendor/github.com/google/pprof/driver.s 8046 8124 +78 +0.969% cmd/vendor/golang.org/x/tools/go/analysis/passes/assign.s 2010 2193 +183 +9.104% cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic.s 2132 2335 +203 +9.522% cmd/go.s 6341 6546 +205 +3.233% cmd/vendor/golang.org/x/tools/go/analysis/passes/bools.s 6078 6348 +270 +4.442% cmd/vendor/golang.org/x/tools/go/analysis/passes/composite.s 4457 4789 +332 +7.449% cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock.s 8814 9375 +561 +6.365% cmd/link.s 3829 4373 +544 +14.207% cmd/vendor/golang.org/x/tools/go/analysis/passes/framepointer.s 2007 2265 +258 +12.855% cmd/pprof.s 9881 10052 +171 +1.731% cmd/vendor/golang.org/x/tools/go/cfg.s 26215 27546 +1331 +5.077% cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse.s 3500 4205 +705 +20.143% cmd/vendor/golang.org/x/tools/go/analysis/passes/ifaceassert.s 4790 5407 +617 +12.881% cmd/vendor/golang.org/x/tools/go/ast/astutil.s 50786 55269 +4483 +8.827% cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc.s 1754 2033 +279 +15.906% cmd/vendor/golang.org/x/tools/go/analysis/passes/shift.s 4514 5262 +748 +16.571% cmd/vendor/golang.org/x/tools/go/analysis/passes/sigchanyzer.s 3455 3687 +232 +6.715% cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods.s 8064 8249 +185 +2.294% cmd/vendor/golang.org/x/tools/go/analysis/passes/stringintconv.s 4547 4900 +353 +7.763% cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag.s 6975 7584 +609 +8.731% cmd/vendor/golang.org/x/tools/go/analysis/passes/testinggoroutine.s 3375 3670 +295 +8.741% cmd/vendor/golang.org/x/tools/go/types/typeutil.s 12924 13870 +946 +7.320% cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr.s 3251 3557 +306 +9.412% cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable.s 6121 7575 +1454 +23.754% cmd/vendor/golang.org/x/tools/go/analysis/passes/tests.s 13925 14409 +484 +3.476% cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult.s 2953 3159 +206 +6.976% cmd/vendor/golang.org/x/tools/go/analysis/unitchecker.s 11563 11962 +399 +3.451% cmd/vendor/golang.org/x/tools/go/analysis/passes/errorsas.s 1735 1933 +198 +11.412% cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow.s 4241 4486 +245 +5.777% cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure.s 3107 3460 +353 +11.361% cmd/vendor/golang.org/x/tools/go/analysis/passes/unmarshal.s 1879 2141 +262 +13.944% cmd/vendor/golang.org/x/tools/go/analysis/passes/printf.s 28740 29317 +577 +2.008% cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel.s 7188 7930 +742 +10.323% cmd/vet.s 1374 1554 +180 +13.100% cmd/compile/internal/ssa.s 3631074 3571680 -59394 -1.636% cmd/compile/internal/liveness.s 40423 40726 +303 +0.750% cmd/compile/internal/ssagen.s 361816 362743 +927 +0.256% cmd/compile/internal/mips64.s 16298 16330 +32 +0.196% cmd/compile/internal/loong64.s 17376 17440 +64 +0.368% cmd/compile/internal/mips.s 16121 16153 +32 +0.198% cmd/compile/internal/arm64.s 29294 29346 +52 +0.178% cmd/compile/internal/arm.s 26850 26882 +32 +0.119% cmd/compile/internal/amd64.s 30945 31034 +89 +0.288% cmd/compile/internal/dwarfgen.s 34464 35065 +601 +1.744% cmd/compile/internal/ppc64.s 31621 31733 +112 +0.354% cmd/compile/internal/wasm.s 11851 11889 +38 +0.321% cmd/compile/internal/s390x.s 24168 24183 +15 +0.062% cmd/compile/internal/x86.s 18090 18079 -11 -0.061% cmd/compile/internal/walk.s 295003 295945 +942 +0.319% cmd/compile/internal/noder.s 405458 403775 -1683 -0.415% cmd/compile/internal/pkginit.s 30757 31951 +1194 +3.882% cmd/compile/internal/gc.s 18788 18880 +92 +0.490% total 20334984 20041049 -293935 -1.445% package runtime/race/internal/amd64v3 was deleted package runtime/race/internal/amd64v1 was deleted Change-Id: Ibcd71480da1b53cfec4fa16c20f222b9a195e6da Reviewed-on: https://go-review.googlesource.com/c/go/+/431797 Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Jakub Ciolek <jakub@ciolek.dev> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-16cmd/compile: make isConstDelta compute delta for 8 and 16 bit arithmeticJakub Ciolek
Use the delta for computing min and max values. This elides a few bounds checks: compilecmp linux/amd64: regexp/syntax regexp/syntax.Op.String 271 -> 249 (-8.12%) compress/bzip2 compress/bzip2.(*reader).readBlock 2991 -> 2973 (-0.60%) cmd/internal/objabi cmd/internal/objabi.RelocType.String 240 -> 220 (-8.33%) cmd/vendor/golang.org/x/arch/ppc64/ppc64asm cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.CondReg.String 421 -> 400 (-4.99%) cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.gnuArg changed cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.plan9Arg 1868 -> 1836 (-1.71%) cmd/internal/objfile cmd/internal/objfile.(*machoFile).symbols 1457 -> 1423 (-2.33%) cmd/internal/objfile.loadPETable changed cmd/internal/obj/wasm cmd/internal/obj/wasm.assemble changed cmd/internal/obj/ppc64 cmd/internal/obj/ppc64.type_vsrdbi changed cmd/internal/obj/ppc64.type_vmsumcud changed cmd/link/internal/loadpe cmd/link/internal/loadpe.Load 10634 -> 10602 (-0.30%) cmd/link/internal/loadpe.(*peLoaderState).readpesym changed Change-Id: I439facd13e3d2695abadfe1d3f7faebfd0d7df74 Reviewed-on: https://go-review.googlesource.com/c/go/+/431237 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2022-08-31cmd/compile: teach prove about bitwise OR operationWayne Zuo
Fixes #45928. Change-Id: Ifbb0effbca4ab7c0eb56069fee40edb564553c35 Reviewed-on: https://go-review.googlesource.com/c/go/+/410336 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-31cmd/compile: derive relation between x+delta and x in proveWayne Zuo
If x+delta cannot overflow/underflow, we can derive: x+delta < x if delta<0 (this CL included) x+delta > x if delta>0 (this CL not included due to a recursive stack overflow) Remove 95 bounds checks during ./make.bat Fixes #51622 Change-Id: I60d9bd84c5d7e81bbf808508afd09be596644f09 Reviewed-on: https://go-review.googlesource.com/c/go/+/406175 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-08-18cmd/compile: remove OFORUNTILKeith Randall
Not used any more. Fixes #53860 Change-Id: Id0b1c3ed30b576d6c5f08f064d1262de337262b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/418374 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-08cmd/compile: teach prove about and operationWayne Zuo
For this code: z &= 63 _ = x<<z | x>>(64-z) Now can prove 'x<<z' in bound. In ppc64 lowering pass, it will not produce an extra '(ANDconst <typ.Int64> [63] z)' causing codegen/rotate.go failed. Just remove the type check in rewrite rules as the workaround. Removes 32 bounds checks during make.bat. Fixes #52563. Change-Id: I14ed2c093ff5638dfea7de9bc7649c0f756dd71a Reviewed-on: https://go-review.googlesource.com/c/go/+/404315 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Keith Randall <khr@golang.org> Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-04cmd/compile: fold constants found by proveJorropo
It is hit ~70k times building go. This make the go binary, 0.04% smaller. I didn't included benchmarks because this is just constant foldings and is hard to mesure objectively. For example, this enable rewriting things like: if x == 20 { return x + 30 + z } Into: if x == 20 { return 50 + z } It's not just fixing programer's code, the ssa generator generate code like this sometimes. Change-Id: I0861f342b27f7227b5f1c34d8267fa0057b1bbbc GitHub-Last-Rev: 4c2f9b521692bc61acff137a269917895f4da08a GitHub-Pull-Request: golang/go#52669 Reviewed-on: https://go-review.googlesource.com/c/go/+/403735 Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com>
2022-04-14cmd/compile: modify switches of strings to use jump table for lengthsKeith Randall
Reorganize the way we rewrite expression switches on strings, so that jump tables are naturally used for the outer switch on the string length. The changes to the prove pass in this CL are required so as to not repeat the test for string length in each case. name old time/op new time/op delta SwitchStringPredictable 2.28ns ± 9% 2.08ns ± 5% -9.04% (p=0.000 n=10+10) SwitchStringUnpredictable 10.5ns ± 1% 9.5ns ± 1% -9.08% (p=0.000 n=9+10) Update #5496 Update #34381 Change-Id: Ie6846b1dd27f3e472f7c30dfcc598c68d440b997 Reviewed-on: https://go-review.googlesource.com/c/go/+/395714 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: fix various doc comment formatting nitsRuss Cox
A run of lines that are indented with any number of spaces or tabs format as a <pre> block. This commit fixes various doc comments that format badly according to that (standard) rule. For example, consider: // - List item. // Second line. // - Another item. Because the - lines are unindented, this is actually two paragraphs separated by a one-line <pre> block. This CL rewrites it to: // - List item. // Second line. // - Another item. Today, that will format as a single <pre> block. In a future release, we hope to format it as a bulleted list. Various other minor fixes as well, all in preparation for reformatting. For #51082. Change-Id: I95cf06040d4186830e571cd50148be3bf8daf189 Reviewed-on: https://go-review.googlesource.com/c/go/+/384257 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-27cmd/compile: upgrade prove pass to know results of math/bits ops are nonnegativeKeith Randall
Fixes #51963 Change-Id: Ib9e0521222e6fc41e787f3150b254e058a19addc Reviewed-on: https://go-review.googlesource.com/c/go/+/396036 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jakub Ciolek <jakub@ciolek.dev> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Eric Fang <eric.fang@arm.com>
2021-04-28cmd/compile/ssa: optimize the derivable known branch of If blockeric fang
When the control value of a If block is known for a particular inbound edge because its value can be inferred from the control value of its predecessor, then this inbound edge can be redirected to the known successor directly, This CL optimizes this kind of cases to eliminate unnecessary comparision. For example, the following piece of code comes from runtime.atoi, if !neg && un > uint(maxInt) { return 0, false } if neg && un > uint(maxInt)+1 { return 0, false } Before this optimization, if the first "if" statement does not return, both conditions of the second "if" statement will be checked. But obviously the value of neg is known through the first "if" statement, and there is no need to check neg repeatedly. After this optimization, this redundancy check is eliminated, and the execution logic becomes as follows. if !neg { if un > uint(maxInt) { return 0, false } } else { if un > uint(maxInt)+1 { return 0, false } } This CL does not bring significant performance changes, but it makes the code structure look more reasonable. Statistical data from tool compilecmp on Linux/amd64: name old time/op new time/op delta Template 380ms ± 4% 385ms ± 3% +1.16% (p=0.000 n=50+49) Unicode 168ms ± 9% 169ms ± 9% ~ (p=0.421 n=49+46) GoTypes 1.99s ± 4% 2.02s ± 4% +1.48% (p=0.000 n=49+49) Compiler 188ms ± 8% 188ms ± 9% ~ (p=0.997 n=49+50) SSA 11.8s ± 2% 12.0s ± 2% +1.24% (p=0.000 n=48+50) Flate 242ms ± 6% 244ms ± 9% ~ (p=0.307 n=46+49) GoParser 361ms ± 3% 366ms ± 4% +1.23% (p=0.000 n=48+49) Reflect 836ms ± 3% 842ms ± 3% +0.70% (p=0.004 n=48+48) Tar 335ms ± 3% 340ms ± 4% +1.47% (p=0.000 n=49+46) XML 432ms ± 4% 437ms ± 4% +1.11% (p=0.002 n=49+49) LinkCompiler 701ms ± 4% 704ms ± 5% ~ (p=0.278 n=49+50) ExternalLinkCompiler 1.83s ± 3% 1.84s ± 3% +0.51% (p=0.034 n=48+49) LinkWithoutDebugCompiler 436ms ± 6% 438ms ± 6% ~ (p=0.419 n=48+49) [Geo mean] 612ms 617ms +0.84% name old alloc/op new alloc/op delta Template 38.7MB ± 1% 39.1MB ± 1% +1.19% (p=0.000 n=50+50) Unicode 28.1MB ± 0% 28.1MB ± 0% +0.20% (p=0.000 n=49+45) GoTypes 168MB ± 1% 170MB ± 1% +1.05% (p=0.000 n=48+49) Compiler 23.0MB ± 1% 23.1MB ± 1% +0.63% (p=0.000 n=50+50) SSA 1.54GB ± 1% 1.55GB ± 1% +0.85% (p=0.000 n=50+50) Flate 23.6MB ± 1% 23.9MB ± 1% +1.36% (p=0.000 n=43+46) GoParser 35.0MB ± 1% 35.3MB ± 1% +0.94% (p=0.000 n=50+50) Reflect 84.7MB ± 1% 86.1MB ± 1% +1.72% (p=0.000 n=49+49) Tar 34.5MB ± 1% 34.9MB ± 1% +1.07% (p=0.000 n=47+48) XML 44.2MB ± 3% 44.6MB ± 3% +0.70% (p=0.003 n=50+49) LinkCompiler 128MB ± 0% 128MB ± 0% +0.01% (p=0.004 n=49+50) ExternalLinkCompiler 120MB ± 0% 120MB ± 0% +0.01% (p=0.000 n=49+50) LinkWithoutDebugCompiler 77.3MB ± 0% 77.3MB ± 0% +0.02% (p=0.000 n=50+50) [Geo mean] 69.1MB 69.6MB +0.75% file before after Δ % addr2line 4049276 4051308 +2032 +0.050% api 5248940 5248996 +56 +0.001% asm 4868093 4868037 -56 -0.001% buildid 2627666 2626026 -1640 -0.062% cgo 4614432 4615040 +608 +0.013% compile 23298888 23301267 +2379 +0.010% cover 4591609 4591161 -448 -0.010% dist 3449638 3450254 +616 +0.018% doc 3925667 3926363 +696 +0.018% fix 3322936 3323464 +528 +0.016% link 6628632 6629560 +928 +0.014% nm 3991753 3996497 +4744 +0.119% objdump 4396119 4395615 -504 -0.011% pack 2399719 2399535 -184 -0.008% pprof 13616418 13622866 +6448 +0.047% test2json 2646121 2646081 -40 -0.002% trace 10233087 10226359 -6728 -0.066% vet 7117994 7121066 +3072 +0.043% total 111026988 111039495 +12507 +0.011% On linux arm64: name old time/op new time/op delta Template 284ms ± 1% 286ms ± 1% +0.70% (p=0.000 n=49+50) Unicode 125ms ± 3% 125ms ± 2% ~ (p=0.548 n=50+50) GoTypes 1.69s ± 1% 1.71s ± 1% +1.02% (p=0.000 n=49+49) Compiler 125ms ± 1% 124ms ± 2% -0.35% (p=0.020 n=50+50) SSA 12.7s ± 1% 12.8s ± 1% +1.21% (p=0.000 n=49+49) Flate 172ms ± 1% 173ms ± 1% +0.20% (p=0.047 n=50+50) GoParser 265ms ± 1% 266ms ± 1% +0.64% (p=0.000 n=50+50) Reflect 651ms ± 1% 650ms ± 1% ~ (p=0.079 n=48+48) Tar 246ms ± 1% 246ms ± 1% ~ (p=0.202 n=50+46) XML 328ms ± 1% 332ms ± 1% +1.28% (p=0.000 n=50+49) LinkCompiler 600ms ± 1% 599ms ± 1% ~ (p=0.264 n=50+50) ExternalLinkCompiler 1.88s ± 1% 1.90s ± 0% +1.36% (p=0.000 n=50+50) LinkWithoutDebugCompiler 365ms ± 1% 365ms ± 1% ~ (p=0.602 n=50+46) [Geo mean] 490ms 492ms +0.47% name old alloc/op new alloc/op delta Template 38.8MB ± 1% 39.1MB ± 1% +0.92% (p=0.000 n=44+42) Unicode 28.4MB ± 0% 28.4MB ± 0% +0.22% (p=0.000 n=44+45) GoTypes 169MB ± 1% 171MB ± 1% +1.12% (p=0.000 n=50+50) Compiler 23.2MB ± 1% 23.3MB ± 1% +0.56% (p=0.000 n=42+43) SSA 1.55GB ± 0% 1.56GB ± 0% +0.91% (p=0.000 n=48+49) Flate 23.7MB ± 2% 24.0MB ± 1% +1.20% (p=0.000 n=50+50) GoParser 35.3MB ± 1% 35.6MB ± 1% +0.88% (p=0.000 n=50+50) Reflect 85.0MB ± 0% 86.5MB ± 0% +1.70% (p=0.000 n=49+48) Tar 34.5MB ± 1% 34.9MB ± 1% +1.03% (p=0.000 n=47+50) XML 43.8MB ± 2% 44.0MB ± 0% +0.41% (p=0.002 n=49+38) LinkCompiler 136MB ± 0% 136MB ± 0% +0.01% (p=0.006 n=50+49) ExternalLinkCompiler 127MB ± 0% 127MB ± 0% +0.02% (p=0.000 n=49+50) LinkWithoutDebugCompiler 84.1MB ± 0% 84.1MB ± 0% ~ (p=0.534 n=50+50) [Geo mean] 70.4MB 70.9MB +0.69% file before after Δ % addr2line 4006004 4004556 -1448 -0.036% api 5029716 5028828 -888 -0.018% asm 4936863 4934943 -1920 -0.039% buildid 2594947 2594099 -848 -0.033% cgo 4399702 4399502 -200 -0.005% compile 22233139 22230486 -2653 -0.012% cover 4443681 4443881 +200 +0.005% dist 3365902 3365486 -416 -0.012% doc 3776175 3776151 -24 -0.001% fix 3218624 3218600 -24 -0.001% link 6365001 6361409 -3592 -0.056% nm 3923345 3923065 -280 -0.007% objdump 4295473 4296673 +1200 +0.028% pack 2390561 2389393 -1168 -0.049% pprof 12866419 12865115 -1304 -0.010% test2json 2587113 2585561 -1552 -0.060% trace 9609814 9610846 +1032 +0.011% vet 6790272 6789760 -512 -0.008% total 106832751 106818354 -14397 -0.013% Update: #37608 Change-Id: I2831238b12e3af5aef2261f64f804bf0a8b43f86 Reviewed-on: https://go-review.googlesource.com/c/go/+/244737 Reviewed-by: eric fang <eric.fang@arm.com> Reviewed-by: Keith Randall <khr@golang.org> Trust: eric fang <eric.fang@arm.com> Run-TryBot: eric fang <eric.fang@arm.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-02-23cmd/compile: use transitive relations for slice len/cap in posetCuong Manh Le
Currently, we keep track of slice len by mapping from slice ID to len/cap SSA value. However, slice len/cap can have multiple SSA values, so when updating fact table for slice len/cap, we only update in one place. Instead, we can take advantage of the transitive relations provided by poset. So all duplicated slice lens are set as equal to one another. When updating fact table for one, that fact will be reflected to all others. The same mechanism is applied for slice cap. Removes 15 bounds checks from std/cmd. Fixes #42603 Change-Id: I32c07968824cc33765b1e441b3ae2c4b5f5997c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/273670 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-11-07cmd/compile: check indirect connection between if block and phi block in ↵Cholerae Hu
addLocalInductiveFacts CL 244579 added guard clauses to prevent a faulty state that was possible under the incorrect logic of the uniquePred loop in addLocalInductiveFacts. That faulty state was still making the intended optimization, but not for the correct reason. Removing the faulty state also removed the overly permissive application of the optimization, and therefore made these two tests fail. We disabled the tests of this optimization in CL 244579 to allow us to quickly apply the fix in the CL. This CL now corrects the logic of the uniquePred loop in order to apply the optimization correctly. The comment above the uniquePred loop says that it will follow unique predecessors until it reaches a join point. Without updating the child node on each iteration, it cannot follow the chain of unique predecessors more than one step. Adding the update to the child node on each iteration of the loop allows the logic to follow the chain of unique predecessors until reaching a join point (because a non-unique predecessor will signify a join point). Updates #40502. Change-Id: I23d8367046a2ab3ce4be969631f9ba15dc533e6c Reviewed-on: https://go-review.googlesource.com/c/go/+/246157 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-08-13cmd/compile: correct type of CvtBoolToUint8 valuesJosh Bleecher Snyder
Fixes #40746 Change-Id: I539f07d1f958dacee87d846171a8889d03182d25 Reviewed-on: https://go-review.googlesource.com/c/go/+/248397 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-07-30cmd/compile: don't addLocalInductiveFacts if there is no direct edge from if ↵Cholerae Hu
block to phi block Currently in addLocalInductiveFacts, we only check whether direct edge from if block to phi block exists. If not, the following logic will treat the phi block as the first successor, which is wrong. This patch makes prove pass more conservative, so we disable some cases in test/prove.go. We will do some optimization in the following CL and enable these cases then. Fixes #40367. Change-Id: I27cf0248f3a82312a6f7dabe11c79a1a34cf5412 Reviewed-on: https://go-review.googlesource.com/c/go/+/244579 Reviewed-by: Zach Jones <zachj1@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-11cmd/compile: in prove, zero right shifts of positive int by #bits - 1Keith Randall
Taking over Zach's CL 212277. Just cleaned up and added a test. For a positive, signed integer, an arithmetic right shift of count (bit-width - 1) equals zero. e.g. int64(22) >> 63 -> 0. This CL makes prove replace these right shifts with a zero-valued constant. These shifts may arise in source code explicitly, but can also be created by the generic rewrite of signed division by a power of 2. // Signed divide by power of 2. // n / c = n >> log(c) if n >= 0 // = (n+c-1) >> log(c) if n < 0 // We conditionally add c-1 by adding n>>63>>(64-log(c)) (first shift signed, second shift unsigned). (Div64 <t> n (Const64 [c])) && isPowerOfTwo(c) -> (Rsh64x64 (Add64 <t> n (Rsh64Ux64 <t> (Rsh64x64 <t> n (Const64 <typ.UInt64> [63])) (Const64 <typ.UInt64> [64-log2(c)]))) (Const64 <typ.UInt64> [log2(c)])) If n is known to be positive, this rewrite includes an extra Add and 2 extra Rsh. This CL will allow prove to replace one of the extra Rsh with a 0. That replacement then allows lateopt to remove all the unneccesary fixups from the generic rewrite. There is a rewrite rule to handle this case directly: (Div64 n (Const64 [c])) && isNonNegative(n) && isPowerOfTwo(c) -> (Rsh64Ux64 n (Const64 <typ.UInt64> [log2(c)])) But this implementation of isNonNegative really only handles constants and a few special operations like len/cap. The division could be handled if the factsTable version of isNonNegative were available. Unfortunately, the first opt pass happens before prove even has a chance to deduce the numerator is non-negative, so the generic rewrite has already fired and created the extra Ops discussed above. Fixes #36159 By Printf count, this zeroes 137 right shifts when building std and cmd. Change-Id: Iab486910ac9d7cfb86ace2835456002732b384a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/232857 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-03-09cmd/compile: use only bit patterns in isNonNegativeJosh Bleecher Snyder
CL 212777 added a check to isNonNegative to return true for unsigned values. However, the SSA backend isn't type safe enough for that to be sound. The other checks in isNonNegative look only at the pattern of bits. Remove the type-based check. Updates #37753 Change-Id: I059d0e86353453133f2a160dce53af299f42e533 Reviewed-on: https://go-review.googlesource.com/c/go/+/222620 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-02-27cmd/compile: ignore div/mod in prove on non-x86 architecturesJosh Bleecher Snyder
Instead of writing AuxInt during prove and then zeroing it during lower, just don't write it in the first place. Passes toolstash-check -all. Change-Id: Iea4b555029a9d69332e835536f9cf3a42b8223db Reviewed-on: https://go-review.googlesource.com/c/go/+/220682 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-02-27cmd/compile: handle more cases in isNonNegativeJosh Bleecher Snyder
The gains from this aren't particularly impressive. Still, it is cheap and easy, and it will keep me from wondering about whether it might help to add X every time I look at this function. This updated function is pretty exhaustive; I examined every op encountered in a call to isNonNegative when compiling all the stuff hanging around in my GOPATH, for both 386 and amd64. (32 bit architectures were somewhat neglected before.) Object file size impact, 64 bit: file before after Δ % archive/zip.a 359352 359284 -68 -0.019% cmd/compile/internal/ssa.a 30715960 30717526 +1566 +0.005% cmd/internal/obj/arm64.a 2972532 2972440 -92 -0.003% cmd/internal/obj/riscv.a 297714 297672 -42 -0.014% debug/dwarf.a 656336 655346 -990 -0.151% debug/gosym.a 183352 183122 -230 -0.125% encoding/gob.a 901130 900798 -332 -0.037% image/gif.a 171884 171890 +6 +0.003% internal/trace.a 506930 507270 +340 +0.067% math.a 233506 233490 -16 -0.007% reflect.a 1431740 1431476 -264 -0.018% runtime.a 3854480 3854332 -148 -0.004% unicode/utf16.a 8920 8980 +60 +0.673% total 133000610 133000400 -210 -0.000% Object file size impact, 32 bit: file before after Δ % archive/zip.a 330794 329640 -1154 -0.349% cmd/compile/internal/gc.a 8090204 8090026 -178 -0.002% cmd/compile/internal/ssa.a 29392460 29393890 +1430 +0.005% cmd/internal/goobj2.a 189512 189492 -20 -0.011% cmd/internal/obj/arm64.a 2444942 2444860 -82 -0.003% cmd/internal/obj/riscv.a 272848 272806 -42 -0.015% cmd/link/internal/loader.a 388548 388544 -4 -0.001% cmd/link/internal/loadpe.a 158776 158684 -92 -0.058% cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.a 511824 511316 -508 -0.099% cmd/vendor/golang.org/x/arch/x86/x86asm.a 512812 512704 -108 -0.021% cmd/vendor/golang.org/x/sys/unix.a 942422 942218 -204 -0.022% compress/bzip2.a 88768 88680 -88 -0.099% crypto/tls.a 1655542 1655396 -146 -0.009% debug/dwarf.a 608520 605822 -2698 -0.443% debug/gosym.a 168282 168276 -6 -0.004% debug/pe.a 173146 173108 -38 -0.022% encoding/gob.a 797978 797724 -254 -0.032% encoding/hex.a 44080 44020 -60 -0.136% image/gif.a 152142 152148 +6 +0.004% internal/xcoff.a 186480 185834 -646 -0.346% math.a 257866 257854 -12 -0.005% net/http.a 3588246 3588150 -96 -0.003% net/textproto.a 162384 162120 -264 -0.163% reflect.a 1316204 1316058 -146 -0.011% regexp.a 373346 373248 -98 -0.026% runtime/pprof.a 345318 345088 -230 -0.067% runtime.a 3513902 3513714 -188 -0.005% syscall.a 781406 781018 -388 -0.050% time.a 483814 483750 -64 -0.013% unicode/utf16.a 8394 8364 -30 -0.357% vendor/golang.org/x/crypto/cryptobyte.a 287100 286706 -394 -0.137% vendor/golang.org/x/net/route.a 175042 174724 -318 -0.182% total 121677354 121670234 -7120 -0.006% Change-Id: Ie672752feb5e94dd151836f852181980710e820d Reviewed-on: https://go-review.googlesource.com/c/go/+/212777 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-02-26cmd/compile: remove Greater* and Geq* generic integer opsMichael Munday
The generic Greater and Geq ops can always be replaced with the Less and Leq ops. This CL therefore removes them. This simplifies the compiler since it reduces the number of operations that need handling in both code and in rewrite rules. This will be especially true when adding control flow optimizations such as the integer-in-range optimizations in CL 165998. Change-Id: If0648b2b19998ac1bddccbf251283f3be4ec3040 Reviewed-on: https://go-review.googlesource.com/c/go/+/220417 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-02-21cmd/compile: clarify division bounds check optimizationJosh Bleecher Snyder
The name of the function should mention division. Eliminate double negatives from the comment describing it. Change-Id: Icef1a5139b3a91b86acb930af97938f5160f7342 Reviewed-on: https://go-review.googlesource.com/c/go/+/217001 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-05cmd/compile: fix liveness for open-coded defer args for infinite loopsDan Scales
Once defined, a stack slot holding an open-coded defer arg should always be marked live, since it may be used at any time if there is a panic. These stack slots are typically kept live naturally by the open-defer code inlined at each return/exit point. However, we need to do extra work to make sure that they are kept live if a function has an infinite loop or a panic exit. For this fix, only in the case of a function that is using open-coded defers, we compute the set of blocks (most often empty) that cannot reach a return or a BlockExit (panic) because of an infinite loop. Then, for each block b which cannot reach a return or BlockExit or is a BlockExit block, we mark each defer arg slot as live, as long as the definition of the defer arg slot dominates block b. For this change, had to export (*Func).sdom (-> Sdom) and SparseTree.isAncestorEq (-> IsAncestorEq) Updates #35277 Change-Id: I7b53c9bd38ba384a3794386dd0eb94e4cbde4eb1 Reviewed-on: https://go-review.googlesource.com/c/go/+/204802 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2019-10-20cmd/compile: in prove, give a different name to each posetGiovanni Bajo
Instead of using a two-slot array and having to remember which index is the signed poset, and which is the unsigned one, just use two different variables. Change-Id: Ic7f7676436c51bf43a182e999a926f8b7f69434b Reviewed-on: https://go-review.googlesource.com/c/go/+/196678 Reviewed-by: Keith Randall <khr@golang.org>
2019-10-04cmd/compile: attempt to preserve statements when prove removes codeDavid Chase
This was a cause of some statements being lost. Change-Id: I81c95dcf3df6ed8a03b7578a27f9b21d33b3cf39 Reviewed-on: https://go-review.googlesource.com/c/go/+/198484 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2019-10-02cmd/compile: allow multiple SSA block control valuesMichael Munday
Control values are used to choose which successor of a block is jumped to. Typically a control value takes the form of a 'flags' value that represents the result of a comparison. Some architectures however use a variable in a register as a control value. Up until now we have managed with a single control value per block. However some architectures (e.g. s390x and riscv64) have combined compare-and-branch instructions that take two variables in registers as parameters. To generate these instructions we need to support 2 control values per block. This CL allows up to 2 control values to be used in a block in order to support the addition of compare-and-branch instructions. I have implemented s390x compare-and-branch instructions in a different CL. Passes toolstash-check -all. Results of compilebench: name old time/op new time/op delta Template 208ms ± 1% 209ms ± 1% ~ (p=0.289 n=20+20) Unicode 83.7ms ± 1% 83.3ms ± 3% -0.49% (p=0.017 n=18+18) GoTypes 748ms ± 1% 748ms ± 0% ~ (p=0.460 n=20+18) Compiler 3.47s ± 1% 3.48s ± 1% ~ (p=0.070 n=19+18) SSA 11.5s ± 1% 11.7s ± 1% +1.64% (p=0.000 n=19+18) Flate 130ms ± 1% 130ms ± 1% ~ (p=0.588 n=19+20) GoParser 160ms ± 1% 161ms ± 1% ~ (p=0.211 n=20+20) Reflect 465ms ± 1% 467ms ± 1% +0.42% (p=0.007 n=20+20) Tar 184ms ± 1% 185ms ± 2% ~ (p=0.087 n=18+20) XML 253ms ± 1% 253ms ± 1% ~ (p=0.377 n=20+18) LinkCompiler 769ms ± 2% 774ms ± 2% ~ (p=0.070 n=19+19) ExternalLinkCompiler 3.59s ±11% 3.68s ± 6% ~ (p=0.072 n=20+20) LinkWithoutDebugCompiler 446ms ± 5% 454ms ± 3% +1.79% (p=0.002 n=19+20) StdCmd 26.0s ± 2% 26.0s ± 2% ~ (p=0.799 n=20+20) name old user-time/op new user-time/op delta Template 238ms ± 5% 240ms ± 5% ~ (p=0.142 n=20+20) Unicode 105ms ±11% 106ms ±10% ~ (p=0.512 n=20+20) GoTypes 876ms ± 2% 873ms ± 4% ~ (p=0.647 n=20+19) Compiler 4.17s ± 2% 4.19s ± 1% ~ (p=0.093 n=20+18) SSA 13.9s ± 1% 14.1s ± 1% +1.45% (p=0.000 n=18+18) Flate 145ms ±13% 146ms ± 5% ~ (p=0.851 n=20+18) GoParser 185ms ± 5% 188ms ± 7% ~ (p=0.174 n=20+20) Reflect 534ms ± 3% 538ms ± 2% ~ (p=0.105 n=20+18) Tar 215ms ± 4% 211ms ± 9% ~ (p=0.079 n=19+20) XML 295ms ± 6% 295ms ± 5% ~ (p=0.968 n=20+20) LinkCompiler 832ms ± 4% 837ms ± 7% ~ (p=0.707 n=17+20) ExternalLinkCompiler 1.58s ± 8% 1.60s ± 4% ~ (p=0.296 n=20+19) LinkWithoutDebugCompiler 478ms ±12% 489ms ±10% ~ (p=0.429 n=20+20) name old object-bytes new object-bytes delta Template 559kB ± 0% 559kB ± 0% ~ (all equal) Unicode 216kB ± 0% 216kB ± 0% ~ (all equal) GoTypes 2.03MB ± 0% 2.03MB ± 0% ~ (all equal) Compiler 8.07MB ± 0% 8.07MB ± 0% -0.06% (p=0.000 n=20+20) SSA 27.1MB ± 0% 27.3MB ± 0% +0.89% (p=0.000 n=20+20) Flate 343kB ± 0% 343kB ± 0% ~ (all equal) GoParser 441kB ± 0% 441kB ± 0% ~ (all equal) Reflect 1.36MB ± 0% 1.36MB ± 0% ~ (all equal) Tar 487kB ± 0% 487kB ± 0% ~ (all equal) XML 632kB ± 0% 632kB ± 0% ~ (all equal) name old export-bytes new export-bytes delta Template 18.5kB ± 0% 18.5kB ± 0% ~ (all equal) Unicode 7.92kB ± 0% 7.92kB ± 0% ~ (all equal) GoTypes 35.0kB ± 0% 35.0kB ± 0% ~ (all equal) Compiler 109kB ± 0% 110kB ± 0% +0.72% (p=0.000 n=20+20) SSA 137kB ± 0% 138kB ± 0% +0.58% (p=0.000 n=20+20) Flate 4.89kB ± 0% 4.89kB ± 0% ~ (all equal) GoParser 8.49kB ± 0% 8.49kB ± 0% ~ (all equal) Reflect 11.4kB ± 0% 11.4kB ± 0% ~ (all equal) Tar 10.5kB ± 0% 10.5kB ± 0% ~ (all equal) XML 16.7kB ± 0% 16.7kB ± 0% ~ (all equal) name old text-bytes new text-bytes delta HelloSize 761kB ± 0% 761kB ± 0% ~ (all equal) CmdGoSize 10.8MB ± 0% 10.8MB ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 10.7kB ± 0% 10.7kB ± 0% ~ (all equal) CmdGoSize 312kB ± 0% 312kB ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 122kB ± 0% 122kB ± 0% ~ (all equal) CmdGoSize 146kB ± 0% 146kB ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 1.13MB ± 0% 1.13MB ± 0% ~ (all equal) CmdGoSize 15.1MB ± 0% 15.1MB ± 0% ~ (all equal) Change-Id: I3cc2f9829a109543d9a68be4a21775d2d3e9801f Reviewed-on: https://go-review.googlesource.com/c/go/+/196557 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Keith Randall <khr@golang.org>
2019-09-26cmd/compile: in prove, learn facts from OpSliceMakeGiovanni Bajo
Now that OpSliceMake is called by runtime.makeslice callers, prove can see and record the actual length and cap of each slice being constructed. This small patch is enough to remove 260 additional bound checks from cmd+std. Thanks to Martin Möhrmann for pointing me to CL141822 that I had missed. Updates #24660 Change-Id: I14556850f285392051f3f07d13b456b608b64eb9 Reviewed-on: https://go-review.googlesource.com/c/go/+/196784 Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2019-08-27cmd/compile: handle sign/zero extensions in prove, via update methodzdjones
Array accesses with index types smaller than the machine word size may involve a sign or zero extension of the index value before bounds checking. Currently, this defeats prove because the facts about the original index value don't flow through the sign/zero extension. This CL fixes this by looking back through value-preserving sign/zero extensions when adding facts via Update and, where appropriate, applying the same facts using the pre-extension value. This fix is enhanced by also looking back through value-preserving extensions within ft.isNonNegative to infer whether the extended value is known to be non-negative. Without this additional isNonNegative enhancement, this logic is rendered significantly less effective by the limitation discussed in the next paragraph. In Update, the application of facts to pre-extension values is limited to cases where the domain of the new fact is consistent with the type of the pre-extension value. There may be cases where this cross-domain passing of facts is valid, but distinguishing them from the invalid cases is difficult for me to reason about and to implement. Assessing which cases to allow requires details about the context and inferences behind the fact being applied which are not available within Update. Additional difficulty arises from the fact that the SSA does not curently differentiate extensions added by the compiler for indexing operations, extensions added by the compiler for implicit conversions, or explicit extensions from the source. Examples of some cases that would need to be filtered correctly for cross-domain facts: (1) A uint8 is zero-extended to int for indexing (a value-preserving zeroExt). When, if ever, can signed domain facts learned about the int be applied to the uint8? (2) An int8 is sign-extended to int16 (value-preserving) for an equality comparison. Equality comparison facts are currently always learned in both the signed and unsigned domains. When, if ever, can the unsigned facts learned about the int16, from the int16 != int16 comparison, be applied to the original int8? This is an alternative to CL 122695 and CL 174309. Compared to CL 122695, this CL differs in that the facts added about the pre-extension value will pass through the Update method, where additional inferences are processed (e.g. fence-post implications, see #29964). CL 174309 is limited to bounds checks, so is narrower in application, and makes the code harder to read. Fixes #26292. Fixes #29964. Fixes #15074 Removes 238 bounds checks from std/cmd. Change-Id: I1f87c32ee672bfb8be397b27eab7a4c2f304893f Reviewed-on: https://go-review.googlesource.com/c/go/+/174704 Run-TryBot: Zach Jones <zachj1@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Giovanni Bajo <rasky@develer.com>
2019-06-12cmd/compile: fix range analysis of small signed integersMatthew Dempsky
For int8, int16, and int32, comparing their unsigned value to MaxInt64 to determine non-negativity doesn't make sense, because they have negative values whose unsigned representation is smaller than that. Fix is simply to compare with the appropriate upper bound based on the value type's size. Fixes #32560. Change-Id: Ie7afad7a56af92bd890ba5ff33c86d1df06cfd9a Reviewed-on: https://go-review.googlesource.com/c/go/+/181797 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-31cmd/compile: update stale comment in provezdjones
This is a follow-up CL to https://golang.org/cl/170118, updating a comment made incorrect by that CL. Change-Id: I5a29cfae331fbbbb36c96d96f9e4949393a5942d Reviewed-on: https://go-review.googlesource.com/c/go/+/170123 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-30cmd/compile: make prove learn index >= 0 from successful bounds checkszdjones
When branching at a bounds check for indexing or slicing ops, prove currently only learns from the upper bound. On the positive branch, we currently learn i < len(a) (or i <= len(a)) in both the signed and unsigned domains. This CL makes prove also learn from the lower bound. Specifically, on the positive branch from index or slicing ops, prove will now ALSO learn i >= 0 in the signed domain (this fact is of no value in the unsigned domain). The substantive change itself is only an additional call to addRestrictions, though I've also inverted the nested switch statements around that call for the sake of clarity. This CL removes 92 bounds checks from std and cmd. It passes all tests and shows no deltas on compilecmp. Fixes #28885 Change-Id: I13eccc36e640eb599fa6dc5aa3be3c7d7abd2d9e Reviewed-on: https://go-review.googlesource.com/c/go/+/170121 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Giovanni Bajo <rasky@develer.com>
2019-03-29cmd/compile: preempt repeated checks for the zero constant in provezdjones
Prove requires access to a zero-valued constant in multiple heavily-used code paths. Currently, prove is checking for the existence of the constant on every iteration of these paths, and creating it if not found. This CL preempts all of these checks by finding or creating the zero constant Value, just once, when the factsTable is initialised on entry to prove(). The Method used to initialise the zero constant, func.ConstInt64(), finds an existing constant if present, or creates one in the entry block otherwise. Fixes #31141 Change-Id: Ic9a2fd9d79b67025e24d4483f6e87cf8213ead24 Reviewed-on: https://go-review.googlesource.com/c/go/+/170118 Reviewed-by: Giovanni Bajo <rasky@develer.com> Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-29cmd/compile: make prove use poset to check non-negativeszdjones
Prove currently fails to remove bounds checks of the form: if i >= 0 { // hint that i is non-negative for i < len(data) { // i becomes Phi in the loop SSA _ = data[i] // data[Phi]; bounds check!! i++ } } addIndVarRestrictions fails to identify that the loop induction variable, (Phi), is non-negative. As a result, the restrictions, i <= Phi < len(data), are only added for the signed domain. When testing the bounds check, addBranchRestrictions is similarly unable to infer that Phi is non-negative. As a result, the restriction, Phi >= len(data), is only added/tested for the unsigned domain. This CL changes the isNonNegative method to utilise the factTable's partially ordered set (poset). It also adds field factTable.zero to allow isNonNegative to query the poset using the zero(0) constant found or created early in prove. Fixes #28956 Change-Id: I792f886c652eeaa339b0d57d5faefbf5922fe44f Reviewed-on: https://go-review.googlesource.com/c/go/+/161437 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Giovanni Bajo <rasky@develer.com>
2019-01-02cmd/compile: fix deriving from x+d >= w on overflow in prove passCherry Zhang
In the case of x+d >= w, where d and w are constants, we are deriving x is within the bound of min=w-d and max=maxInt-d. When there is an overflow (min >= max), we know only one of x >= min or x <= max is true, and we derive this by excluding the other. When excluding x >= min, we did not consider the equal case, so we could incorrectly derive x <= max when x == min. Fixes #29502. Change-Id: Ia9f7d814264b1a3ddf78f52e2ce23377450e6e8a Reviewed-on: https://go-review.googlesource.com/c/156019 Reviewed-by: David Chase <drchase@google.com>
2018-10-23cmd/compile: use proved bounds to remove signed division fix-upsChrisALiles
prove is able to find 94 occurrences in std cmd where a divisor can't have the value -1. The change removes the extraneous fix-up code for these cases. Fixes #25239 Change-Id: Ic184de971f47cc57c702eb72805b8e291c14035d Reviewed-on: https://go-review.googlesource.com/c/130215 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2018-09-24cmd/compile/internal/ssa: fix a typoBrad Fitzpatrick
Change-Id: Ie3a8c54fe5e1b94f506cc0e6f650aab441d28a75 Reviewed-on: https://go-review.googlesource.com/137115 Reviewed-by: Keith Randall <khr@golang.org>
2018-08-31cmd/compile: in prove, fix fence-post implications for unsigned domainGiovanni Bajo
Fence-post implications of the form "x-1 >= w && x > min ⇒ x > w" were not correctly handling unsigned domain, by always checking signed limits. This bug was uncovered once we taught prove that len(x) is always >= 0 in the signed domain. In the code being miscompiled (s[len(s)-1]), prove checks whether len(s)-1 >= len(s) in the unsigned domain; if it proves that this is always false, it can remove the bound check. Notice that len(s)-1 >= len(s) can be true for len(s) = 0 because of the wrap-around, so this is something prove should not be able to deduce. But because of the bug, the gate condition for the fence-post implication was len(s) > MinInt64 instead of len(s) > 0; that condition would be good in the signed domain but not in the unsigned domain. And since in CL105635 we taught prove that len(s) >= 0, the condition incorrectly triggered (len(s) >= 0 > MinInt64) and things were going downfall. Fixes #27251 Fixes #27289 Change-Id: I3dbcb1955ac5a66a0dcbee500f41e8d219409be5 Reviewed-on: https://go-review.googlesource.com/132495 Reviewed-by: Keith Randall <khr@golang.org>
2018-05-22cmd/compile: detect OFORUNTIL inductive facts in proveAustin Clements
Currently, we compile range loops into for loops with the obvious initialization and update of the index variable. In this form, the prove pass can see that the body is dominated by an i < len condition, and findIndVar can detect that i is an induction variable and that 0 <= i < len. GOEXPERIMENT=preemptibleloops compiles range loops to OFORUNTIL and we're preparing to unconditionally switch to a variation of this for #24543. OFORUNTIL moves the increment and condition *after* the body, which makes the bounds on the index variable much less obvious. With OFORUNTIL, proving anything about the index variable requires understanding the phi that joins the index values at the top of the loop body block. This interferes with both prove's ability to see that i < len (this is true on both paths that enter the body, but from two different conditional checks) and with findIndVar's ability to detect the induction pattern. Fix this by teaching prove to detect that the index in the pattern constructed by OFORUNTIL is an induction variable and add both bounds to the facts table. Currently this is done separately from findIndVar because it depends on prove's factsTable, while findIndVar runs before visiting blocks and building the factsTable. Without any GOEXPERIMENT, this has no effect on std or cmd. However, with GOEXPERIMENT=preemptibleloops, this change becomes necessary to prove 90 conditions in std and cmd. Change-Id: Ic025d669f81b53426309da5a6e8010e5ccaf4f49 Reviewed-on: https://go-review.googlesource.com/102603 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2018-05-22cmd/compile: derive len/cap relations in factsTable.updateAustin Clements
Currently, the prove pass derives implicit relations between len and cap in the code that adds branch conditions. This is fine right now because that's the only place we can encounter len and cap, but we're about to add a second way to add assertions to the facts table that can also produce facts involving len and cap. Prepare for this by moving the fact derivation from updateRestrictions (where it only applies on branches) to factsTable.update, which can derive these facts no matter where the root facts come from. Passes toolstash -cmp. Change-Id: If09692d9eb98ffaa93f4cfa58ed2d8ba0887c111 Reviewed-on: https://go-review.googlesource.com/102602 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2018-05-22cmd/compile: teach prove about relations between constantsAustin Clements
Currently, we never add a relation between two constants to prove's fact table because these are eliminated before prove runs, so it currently doesn't handle facts like this very well even though they're easy to prove. We're about to start asserting some conditions that don't appear in the SSA, but are constructed from existing SSA values that may both be constants. Hence, improve the fact table to understand relations between constants by initializing the constant bounds of constant values to the value itself, rather than noLimit. Passes toolstash -cmp. Change-Id: I71f8dc294e59f19433feab1c10b6d3c99b7f1e26 Reviewed-on: https://go-review.googlesource.com/102601 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2018-05-14cmd/compile: reduce allocations in prove by reusing posetsGiovanni Bajo
In prove, reuse posets between different functions by storing them in the per-worker cache. Allocation count regression caused by prove improvements is down from 5% to 3% after this CL. Updates #25179 Change-Id: I6d14003109833d9b3ef5165fdea00aa9c9e952e8 Reviewed-on: https://go-review.googlesource.com/110455 Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2018-05-01cmd/compile: recognize some OpRsh64Ux64 Values as non-negativeJosh Bleecher Snyder
Proves IsSliceInBounds one additional time building std+cmd, at encoding/hex/hex.go:187:8. The code is: if numAvail := len(d.in) / 2; len(p) > numAvail { p = p[:numAvail] } Previously we were unable to prove that numAvail >= 0. Change-Id: Ie74e0aef809f9194c45e129ee3dae60bc3eae02f Reviewed-on: https://go-review.googlesource.com/109415 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Giovanni Bajo <rasky@develer.com>
2018-04-30cmd/compile: use AuxInt to store shift boundednessJosh Bleecher Snyder
Fixes ssacheck build. Change-Id: Idf1d2ea9a971a1f17f2fca568099e870bb5d913f Reviewed-on: https://go-review.googlesource.com/110122 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2018-04-29cmd/compile: simplify shifts using bounds from prove passJosh Bleecher Snyder
The prove pass sometimes has bounds information that later rewrite passes do not. Use this information to mark shifts as bounded, and then use that information to generate better code on amd64. It may prove to be helpful on other architectures, too. While here, coalesce the existing shift lowering rules. This triggers 35 times building std+cmd. The full list is below. Here's an example from runtime.heapBitsSetType: if nb < 8 { b |= uintptr(*p) << nb p = add1(p) } else { nb -= 8 } We now generate better code on amd64 for that left shift. Updates #25087 vendor/golang_org/x/crypto/curve25519/mont25519_amd64.go:48:20: Proved Rsh8Ux64 bounded runtime/mbitmap.go:1252:22: Proved Lsh64x64 bounded runtime/mbitmap.go:1265:16: Proved Lsh64x64 bounded runtime/mbitmap.go:1275:28: Proved Lsh64x64 bounded runtime/mbitmap.go:1645:25: Proved Lsh64x64 bounded runtime/mbitmap.go:1663:25: Proved Lsh64x64 bounded runtime/mbitmap.go:1808:41: Proved Lsh64x64 bounded runtime/mbitmap.go:1831:49: Proved Lsh64x64 bounded syscall/route_bsd.go:227:23: Proved Lsh32x64 bounded syscall/route_bsd.go:295:23: Proved Lsh32x64 bounded syscall/route_darwin.go:40:23: Proved Lsh32x64 bounded compress/bzip2/bzip2.go:384:26: Proved Lsh64x16 bounded vendor/golang_org/x/net/route/address.go:370:14: Proved Lsh64x64 bounded compress/flate/inflate.go:201:54: Proved Lsh64x64 bounded math/big/prime.go:50:25: Proved Lsh64x64 bounded vendor/golang_org/x/crypto/cryptobyte/asn1.go:464:43: Proved Lsh8x8 bounded net/ip.go:87:21: Proved Rsh8Ux64 bounded cmd/internal/goobj/read.go:267:23: Proved Lsh64x64 bounded cmd/vendor/golang.org/x/arch/arm64/arm64asm/decode.go:534:27: Proved Lsh32x32 bounded cmd/vendor/golang.org/x/arch/arm64/arm64asm/decode.go:544:27: Proved Lsh32x32 bounded cmd/internal/obj/arm/asm5.go:1044:16: Proved Lsh32x64 bounded cmd/internal/obj/arm/asm5.go:1065:10: Proved Lsh32x32 bounded cmd/internal/obj/mips/obj0.go:1311:21: Proved Lsh32x64 bounded cmd/compile/internal/syntax/scanner.go:352:23: Proved Lsh64x64 bounded go/types/expr.go:222:36: Proved Lsh64x64 bounded crypto/x509/x509.go:1626:9: Proved Rsh8Ux64 bounded cmd/link/internal/loadelf/ldelf.go:823:22: Proved Lsh8x64 bounded net/http/h2_bundle.go:1470:17: Proved Lsh8x8 bounded net/http/h2_bundle.go:1477:46: Proved Lsh8x8 bounded net/http/h2_bundle.go:1481:31: Proved Lsh64x8 bounded cmd/compile/internal/ssa/rewriteARM64.go:18759:17: Proved Lsh64x64 bounded cmd/compile/internal/ssa/sparsemap.go:70:23: Proved Lsh32x64 bounded cmd/compile/internal/ssa/sparsemap.go:73:45: Proved Lsh32x64 bounded Change-Id: I58bb72f3e6f12f6ac69be633ea7222c245438142 Reviewed-on: https://go-review.googlesource.com/109776 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Giovanni Bajo <rasky@develer.com>
2018-04-29cmd/compile: teach prove to handle expressions like len(s)-deltaGiovanni Bajo
When a loop has bound len(s)-delta, findIndVar detected it and returned len(s) as (conservative) upper bound. This little lie allowed loopbce to drop bound checks. It is obviously more generic to teach prove about relations like x+d<w for non-constant "w"; we already handled the case for constant "w", so we just want to learn that if d<0, then x+d<w proves that x<w. To be able to remove the code from findIndVar, we also need to teach prove that len() and cap() are always non-negative. This CL allows to prove 633 more checks in cmd+std. Most of them are cases where the code was already testing before accessing a slice but the compiler didn't know it. For instance, take strings.HasSuffix: func HasSuffix(s, suffix string) bool { return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix } When suffix is a literal string, the compiler now understands that the explicit check is enough to not emit a slice check. I also found a loopbce test that was incorrectly written to detect an overflow but had a off-by-one (on the conservative side), so it unexpectly passed with this CL; I changed it to really trigger the overflow as intended. Change-Id: Ib5abade337db46b8811425afebad4719b6e46c4a Reviewed-on: https://go-review.googlesource.com/105635 Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2018-04-29cmd/compile: in prove, detect loops with negative incrementsGiovanni Bajo
To be effective, this also requires being able to relax constraints on min/max bound inclusiveness; they are now exposed through a flags, and prove has been updated to handle it correctly. Change-Id: I3490e54461b7b9de8bc4ae40d3b5e2fa2d9f0556 Reviewed-on: https://go-review.googlesource.com/104041 Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2018-04-29cmd/compile: implement loop BCE in proveGiovanni Bajo
Reuse findIndVar to discover induction variables, and then register the facts we know about them into the facts table when entering the loop block. Moreover, handle "x+delta > w" while updating the facts table, to be able to prove accesses to slices with constant offsets such as slice[i-10]. Change-Id: I2a63d050ed58258136d54712ac7015b25c893d71 Reviewed-on: https://go-review.googlesource.com/104038 Run-TryBot: Giovanni Bajo <rasky@develer.com> Reviewed-by: David Chase <drchase@google.com>