aboutsummaryrefslogtreecommitdiff
path: root/test
AgeCommit message (Collapse)Author
2021-03-31[release-branch.go1.15] cmd/compile: disable shortcircuit optimization for ↵Keith Randall
intertwined phi values We need to be careful that when doing value graph surgery, we not re-substitute a value that has already been substituted. That can lead to confusing a previous iteration's value with the current iteration's value. The simple fix in this CL just aborts the optimization if it detects intertwined phis (a phi which is the argument to another phi). It might be possible to keep the optimization with a more complicated CL, but: 1) This CL is clearly safe to backport. 2) There were no instances of this abort triggering in all.bash, prior to the test introduced in this CL. Fixes #45187 Change-Id: I2411dca03948653c053291f6829a76bec0c32330 Reviewed-on: https://go-review.googlesource.com/c/go/+/304251 Trust: Keith Randall <khr@golang.org> Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> (cherry picked from commit 771c57e68ed5ef2bbb0eafc0d48419f59d143932) Reviewed-on: https://go-review.googlesource.com/c/go/+/304529
2021-03-01[release-branch.go1.15] cmd/compile: fix escape analysis of heap-allocated ↵Matthew Dempsky
results One of escape analysis's responsibilities is to summarize whether/how each function parameter flows to the heap so we can correctly incorporate those flows into callers' escape analysis data flow graphs. As an optimization, we separately record when parameters flow to result parameters, so that we can more precisely analyze parameter flows based on how the results are used at the call site. However, if a named result parameter itself needs to be heap allocated, this optimization isn't safe and the parameter needs to be recorded as flowing to heap rather than flowing to result. Escape analysis used to get this correct because it conservatively rewalked the data-flow graph multiple times. So even though it would incorrectly record the result parameter flow, it would separately find a flow to the heap. However, CL 196811 (specifically, case 3) optimized the walking logic to reduce unnecessary rewalks causing us to stop finding the extra heap flow. This CL fixes the issue by correcting location.leakTo to be sensitive to sink.escapes and not record result-flows when the result parameter escapes to the heap. Fixes #44658. Change-Id: I48742ed35a6cab591094e2d23a439e205bd65c50 Reviewed-on: https://go-review.googlesource.com/c/go/+/297289 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/297291
2021-03-01[release-branch.go1.15] cmd/compile: do not assume TST and TEQ set V on armJason A. Donenfeld
These replacement rules assume that TST and TEQ set V. But TST and TEQ do not set V. This is a problem because instructions like LT are actually checking for N!=V. But with TST and TEQ not setting V, LT doesn't do anything meaningful. It's possible to construct trivial miscompilations from this, such as: package main var x = [4]int32{-0x7fffffff, 0x7fffffff, 2, 4} func main() { if x[0] > x[1] { panic("fail 1") } if x[2]&x[3] < 0 { panic("fail 2") // Fails here } } That first comparison sets V, via the CMP that subtracts the values causing the overflow. Then the second comparison operation thinks that it uses the result of TST, when it actually uses the V from CMP. Before this fix: TST R0, R1 BLT loc_6C164 After this fix: TST R0, R1 BMI loc_6C164 The BMI instruction checks the N flag, which TST sets. This commit fixes the issue by using [LG][TE]noov instead of vanilla [LG][TE], and also adds a test case for the direct issue. Updates #42876. Fixes #42930. Change-Id: I13c62c88d18574247ad002b671b38d2d0b0fc6fa Reviewed-on: https://go-review.googlesource.com/c/go/+/282432 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-01-21[release-branch.go1.15] cmd/compile: don't short-circuit copies whose source ↵Keith Randall
is volatile Current optimization: When we copy a->b and then b->c, we might as well copy a->c instead of b->c (then b might be dead and go away). *Except* if a is a volatile location (might be clobbered by a call). In that case, we really do want to copy a immediately, because there might be a call before we can do the a->c copy. User calls can't happen in between, because the rule matches up the memory states. But calls inserted for memory barriers, particularly runtime.typedmemmove, can. (I guess we could introduce a register-calling-convention version of runtime.typedmemmove, but that seems a bigger change than this one.) Fixes #43575 Change-Id: Ifa518bb1a6f3a8dd46c352d4fd54ea9713b3eb1a Reviewed-on: https://go-review.googlesource.com/c/go/+/282492 Trust: Keith Randall <khr@golang.org> Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> (cherry picked from commit 304f769ffc68e64244266b3aadbf91e6738c0064) Reviewed-on: https://go-review.googlesource.com/c/go/+/282558 Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-12-03[release-branch.go1.15] cmd/compile: sign extend consant folding properlyKeith Randall
MOVLconst must have a properly sign-extended auxint constant. The bit operations in these rules don't enforce that invariant. The easiest fix is just to turn on properly typed auxint fields (which is what fixed this issue at tip). Fixes #42753 Change-Id: I264245fad45067a6ade65326f7fe681feb5f3739 Reviewed-on: https://go-review.googlesource.com/c/go/+/272028 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2020-10-27[release-branch.go1.15] cmd/compile: fix storeType to handle pointers to ↵Keith Randall
go:notinheap types storeType splits compound stores up into a scalar parts and a pointer parts. The scalar part happens unconditionally, and the pointer part happens under the guard of a write barrier check. Types which are declared as pointers, but are represented as scalars because they might have "bad" values, were not handled correctly here. They ended up not getting stored in either set. Fixes #42151 Change-Id: I46f6600075c0c370e640b807066247237f93c7ac Reviewed-on: https://go-review.googlesource.com/c/go/+/264300 Trust: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> (cherry picked from commit 933721b8c7f981229974e2603850c2e9a7ffc5a1) Reviewed-on: https://go-review.googlesource.com/c/go/+/265719 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-27[release-branch.go1.15] cmd/compile, runtime: store pointers to go:notinheap ↵Keith Randall
types indirectly pointers to go:notinheap types should be treated as scalars. That means they shouldn't be stored directly in interfaces, or directly in reflect.Value.ptr. Also be sure to use uintpr to compare such pointers in reflect.DeepEqual. Fixes #42169 Change-Id: I53735f6d434e9c3108d4940bd1bae14c61ef2a74 Reviewed-on: https://go-review.googlesource.com/c/go/+/264480 Trust: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> (cherry picked from commit 009d71409821a6ac4f1b32aaae2c856c20a29f92) Reviewed-on: https://go-review.googlesource.com/c/go/+/265720 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-14[release-branch.go1.15] cmd/compile: fix left shift constant folding ruleKeith Randall
The 32-bit left shift constant folding rule should keep its result properly sign extended. Fixes #41720 Fixes #41711 Change-Id: I0fc74444d444274e911952e1725dab0b7737a846 Reviewed-on: https://go-review.googlesource.com/c/go/+/258817 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-09[release-branch.go1.15] cmd/compile: propagate go:notinheap implicitlyKeith Randall
//go:notinheap type T int type U T We already correctly propagate the notinheap-ness of T to U. But we have an assertion in the typechecker that if there's no explicit //go:notinheap associated with U, then report an error. Get rid of that error so that implicit propagation is allowed. Adjust the tests so that we make sure that uses of types like U do correctly report an error when U is used in a context that might cause a Go heap allocation. Update #41432 Change-Id: I1692bc7cceff21ebb3f557f3748812a40887118d Reviewed-on: https://go-review.googlesource.com/c/go/+/255637 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> (cherry picked from commit 22053790fa2c0944df53ea95df476ad2f855424f) Reviewed-on: https://go-review.googlesource.com/c/go/+/255697 Trust: Keith Randall <khr@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2020-10-09[release-branch.go1.15] cmd/compile: make go:notinheap error message ↵Keith Randall
friendlier for cgo Update #40954 Change-Id: Ifaab7349631ccb12fc892882bbdf7f0ebf3d845f Reviewed-on: https://go-review.googlesource.com/c/go/+/251158 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/255338 Reviewed-by: Austin Clements <austin@google.com>
2020-10-09[release-branch.go1.15] cmd/cgo: use go:notinheap for anonymous structsKeith Randall
They can't reasonably be allocated on the heap. Not a huge deal, but it has an interesting and useful side effect. After CL 249917, the compiler and runtime treat pointers to go:notinheap types as uintptrs instead of real pointers (no write barrier, not processed during stack scanning, ...). That feature is exactly what we want for cgo to fix #40954. All the cases we have of pointers declared in C, but which might actually be filled with non-pointer data, are of this form (JNI's jobject heirarch, Darwin's CFType heirarchy, ...). Fixes #40954 Change-Id: I44a3b9bc2513d4287107e39d0cbbd0efd46a3aae Reviewed-on: https://go-review.googlesource.com/c/go/+/250940 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/255321
2020-10-09[release-branch.go1.15] cmd/compile: allow aliases to go:notinheap typesKeith Randall
The alias doesn't need to be marked go:notinheap. It gets its notinheap-ness from the target type. Without this change, the type alias test in the notinheap.go file generates these two errors: notinheap.go:62: misplaced compiler directive notinheap.go:63: type nih must be go:notinheap The first is a result of go:notinheap pragmas not applying to type alias declarations. The second is the result of then trying to match the notinheap-ness of the alias and the target type. Add a few more go:notinheap tests while we are here. Update #40954 Change-Id: I067ec47698df6e9e593e080d67796fd05a1d480f Reviewed-on: https://go-review.googlesource.com/c/go/+/250939 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Keith Randall <khr@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/255337 Trust: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Austin Clements <austin@google.com>
2020-10-09[release-branch.go1.15] cmd/compile: don't allow go:notinheap on the heap or ↵Keith Randall
stack Right now we just prevent such types from being on the heap. This CL makes it so they cannot appear on the stack either. The distinction between heap and stack is pretty vague at the language level (e.g. it is affected by -N), and we don't need the flexibility anyway. Once go:notinheap types cannot be in either place, we don't need to consider pointers to such types to be pointers, at least according to the garbage collector and stack copying. (This is the big win of this CL, in my opinion.) The distinction between HasPointers and HasHeapPointer no longer exists. There is only HasPointers. This CL is cleanup before possible use of go:notinheap to fix #40954. Update #13386 Change-Id: Ibd895aadf001c0385078a6d4809c3f374991231a Reviewed-on: https://go-review.googlesource.com/c/go/+/255320 Trust: Keith Randall <khr@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-10-05[release-branch.go1.15] cmd/compile: fix live variable computation for ↵Keith Randall
deferreturn Taking the live variable set from the last return point is problematic. See #40629 for details, but there may not be a return point, or it may be before the final defer. Additionally, keeping track of the last call as a *Value doesn't quite work. If it is dead-code eliminated, the storage for the Value is reused for some other random instruction. Its live variable information, if it is available at all, is wrong. Instead, just mark all the open-defer argument slots as live throughout the function. (They are already zero-initialized.) Fixes #40742 Change-Id: Ie456c7db3082d0de57eaa5234a0f32525a1cce13 Reviewed-on: https://go-review.googlesource.com/c/go/+/247522 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com> (cherry picked from commit 32a84c99e136ed5af0686dbedd31fd7dff40fb38) Reviewed-on: https://go-review.googlesource.com/c/go/+/248621 Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-08-21[release-branch.go1.15] cmd/compile: fix checkptr handling of &^Matthew Dempsky
checkptr has code to recognize &^ expressions, but it didn't take into account that "p &^ x" gets rewritten to "p & ^x" during walk, which resulted in false positive diagnostics. This CL changes walkexpr to mark OANDNOT expressions with Implicit when they're rewritten to OAND, so that walkCheckPtrArithmetic can still recognize them later. It would be slightly more idiomatic to instead mark the OBITNOT expression as Implicit (as it's a compiler-generated Node), but the OBITNOT expression might get constant folded. It's not worth the extra complexity/subtlety of relying on n.Right.Orig, so we set Implicit on the OAND node instead. To atone for this transgression, I add documentation for nodeImplicit. Updates #40917. Fixes #40934. Change-Id: I386304171ad299c530e151e5924f179e9a5fd5b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/249477 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> (cherry picked from commit e94544cf012535da6b3c9e735bc4026e2db1c99c) Reviewed-on: https://go-review.googlesource.com/c/go/+/249879 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-08-21cmd/compile: correct type of CvtBoolToUint8 valuesJosh Bleecher Snyder
Fixes #40772 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> Reviewed-on: https://go-review.googlesource.com/c/go/+/248401
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-07-27cmd/compile: add floating point load+op operations to addressing modes passKeith Randall
They were missed as part of the refactoring to use a separate addressing modes pass. Fixes #40426 Change-Id: Ie0418b2fac4ba1ffe720644ac918f6d728d5e420 Reviewed-on: https://go-review.googlesource.com/c/go/+/244859 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-07-20cmd/compile: add test for fixed ICE on untyped conversionAlberto Donizetti
The ICE reported as #33308 was fixed by a related CL; this change adds a regression test with the crasher. Fixes #33308 Change-Id: I3260075dbe3823b56b8825e6269e57a0fad185a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/243458 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-06-25cmd/compile: remove check that Zero's arg has the correct base typeKeith Randall
It doesn't have to. The type in the aux field is authoritative. There are cases involving casting from interface{} where pointers have a placeholder pointer type (because the type is not known when the IData op is generated). The check was introduced in CL 13447. Fixes #39459 Change-Id: Id77a57577806a271aeebd20bea5d92d08ee7aa6b Reviewed-on: https://go-review.googlesource.com/c/go/+/239817 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2020-06-19reflect: zero stack slots before writing to them with write barriersKeith Randall
reflect.assignTo writes to the target using write barriers. Make sure that the memory it is writing to is zeroed, so the write barrier does not read pointers from uninitialized memory. Fixes #39541 Change-Id: Ia64b2cacc193bffd0c1396bbce1dfb8182d4905b Reviewed-on: https://go-review.googlesource.com/c/go/+/238760 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18cmd/compile: mark s390x int <-> float conversions as clobbering flagsMichael Munday
These conversion instructions set the condition code and so should be marked as clobbering flags. Fixes #39651. Change-Id: I91cc9687ea70ef0551bb3139c1875071c349d43e Reviewed-on: https://go-review.googlesource.com/c/go/+/238628 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-06-15cmd/compile: fix ordering problems in struct equalityKeith Randall
Make sure that if a field comparison might panic, we evaluate (and short circuit if not equal) all previous fields, and don't evaluate any subsequent fields. Add a bunch more tests to the equality+panic checker. Update #8606 Change-Id: I6a159bbc8da5b2b7ee835c0cd1fc565575b58c46 Reviewed-on: https://go-review.googlesource.com/c/go/+/237919 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-10cmd/compile: always tighten and de-duplicate tuple selectorsMichael Munday
The scheduler assumes two special invariants that apply to tuple selectors (Select0 and Select1 ops): 1. There is only one tuple selector of each type per generator. 2. Tuple selectors and generators reside in the same block. Prior to this CL the assumption was that these invariants would only be broken by the CSE pass. The CSE pass therefore contained code to move and de-duplicate selectors to fix these invariants. However it is also possible to write relatively basic optimization rules that cause these invariants to be broken. For example: (A (Select0 (B))) -> (Select1 (B)) This rule could result in the newly added selector (Select1) being in a different block to the tuple generator (see issue #38356). It could also result in duplicate selectors if this rule matches multiple times for the same tuple generator (see issue #39472). The CSE pass will 'fix' these invariants. However it will only do so when optimizations are enabled (since disabling optimizations disables the CSE pass). This CL moves the CSE tuple selector fixup code into its own pass and makes it mandatory even when optimizations are disabled. This allows tuple selectors to be treated like normal ops for most of the compilation pipeline until after the new pass has run, at which point we need to be careful to maintain the invariant again. Fixes #39472. Change-Id: Ia3f79e09d9c65ac95f897ce37e967ee1258a080b Reviewed-on: https://go-review.googlesource.com/c/go/+/237118 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-06-09cmd/compile: ARM comparisons with 0 incorrect on overflowXiangdong Ji
Some ARM rewriting rules convert 'comparing to zero' conditions of if statements to a simplified version utilizing CMN and CMP instructions to branch over condition flags, in order to save one Add or Sub caculation. Such optimizations lead to wrong branching in case an overflow/underflow occurs when executing CMN or CMP. Fix the issue by introducing new block opcodes that don't honor the overflow/underflow flag: Block-Op Meaning ARM condition codes 1. LTnoov less than MI 2. GEnoov greater than or equal PL 3. LEnoov less than or equal MI || EQ 4. GTnoov greater than NEQ & PL The patch also adds a few test cases to cover scenarios that are specific to ARM and fine-tunes the code generation tests for 'x-const'. For more details please refer to the previous fix on 64-bit ARM: https://go-review.googlesource.com/c/go/+/233097 Go1 perf, 'old' is the non-optimized version, that is removing all concerned rewriting rules. name old time/op new time/op delta BinaryTree17-8 7.73s ± 0% 7.81s ± 0% +0.97% (p=0.000 n=7+8) Fannkuch11-8 7.06s ± 0% 7.00s ± 0% -0.83% (p=0.000 n=8+8) FmtFprintfEmpty-8 181ns ± 1% 183ns ± 1% +1.31% (p=0.001 n=8+8) FmtFprintfString-8 319ns ± 1% 325ns ± 2% +1.71% (p=0.009 n=7+8) FmtFprintfInt-8 358ns ± 1% 359ns ± 1% ~ (p=0.293 n=7+7) FmtFprintfIntInt-8 459ns ± 3% 456ns ± 1% ~ (p=0.869 n=8+8) FmtFprintfPrefixedInt-8 535ns ± 4% 538ns ± 4% ~ (p=0.572 n=8+8) FmtFprintfFloat-8 1.01µs ± 2% 1.01µs ± 2% ~ (p=0.625 n=8+8) FmtManyArgs-8 1.93µs ± 2% 1.93µs ± 1% ~ (p=0.979 n=8+7) GobDecode-8 16.1ms ± 1% 16.5ms ± 1% +2.32% (p=0.000 n=8+8) GobEncode-8 15.9ms ± 0% 15.8ms ± 1% -1.00% (p=0.000 n=8+7) Gzip-8 690ms ± 1% 670ms ± 0% -2.90% (p=0.000 n=8+8) Gunzip-8 109ms ± 1% 109ms ± 1% ~ (p=0.694 n=7+8) HTTPClientServer-8 149µs ± 3% 146µs ± 2% -1.70% (p=0.028 n=8+8) JSONEncode-8 50.5ms ± 1% 49.2ms ± 0% -2.60% (p=0.001 n=7+7) JSONDecode-8 135ms ± 2% 137ms ± 1% ~ (p=0.054 n=8+7) Mandelbrot200-8 951ms ± 0% 952ms ± 0% ~ (p=0.852 n=6+8) GoParse-8 9.47ms ± 1% 9.66ms ± 1% +2.01% (p=0.000 n=8+8) RegexpMatchEasy0_32-8 288ns ± 2% 277ns ± 2% -3.61% (p=0.000 n=8+8) RegexpMatchEasy0_1K-8 1.66µs ± 1% 1.69µs ± 2% +2.21% (p=0.001 n=7+7) RegexpMatchEasy1_32-8 334ns ± 1% 305ns ± 2% -8.86% (p=0.000 n=8+8) RegexpMatchEasy1_1K-8 2.14µs ± 2% 2.15µs ± 0% ~ (p=0.099 n=8+8) RegexpMatchMedium_32-8 13.3ns ± 1% 13.3ns ± 0% ~ (p=1.000 n=7+7) RegexpMatchMedium_1K-8 81.1µs ± 3% 80.7µs ± 1% ~ (p=0.955 n=7+8) RegexpMatchHard_32-8 4.26µs ± 0% 4.26µs ± 0% ~ (p=0.933 n=7+8) RegexpMatchHard_1K-8 124µs ± 0% 124µs ± 0% +0.31% (p=0.000 n=8+8) Revcomp-8 14.7ms ± 2% 14.5ms ± 1% -1.66% (p=0.003 n=8+8) Template-8 197ms ± 2% 200ms ± 3% +1.62% (p=0.021 n=8+8) TimeParse-8 1.33µs ± 1% 1.30µs ± 1% -1.86% (p=0.002 n=8+8) TimeFormat-8 3.04µs ± 1% 3.02µs ± 0% -0.60% (p=0.000 n=8+8) name old speed new speed delta GobDecode-8 47.6MB/s ± 1% 46.5MB/s ± 1% -2.28% (p=0.000 n=8+8) GobEncode-8 48.1MB/s ± 0% 48.6MB/s ± 1% +1.02% (p=0.000 n=8+7) Gzip-8 28.1MB/s ± 1% 29.0MB/s ± 0% +2.97% (p=0.000 n=8+8) Gunzip-8 178MB/s ± 1% 179MB/s ± 2% ~ (p=0.694 n=7+8) JSONEncode-8 38.4MB/s ± 1% 39.4MB/s ± 0% +2.67% (p=0.001 n=7+7) JSONDecode-8 14.3MB/s ± 2% 14.2MB/s ± 1% -0.81% (p=0.043 n=8+7) GoParse-8 6.12MB/s ± 1% 5.99MB/s ± 1% -2.00% (p=0.000 n=8+8) RegexpMatchEasy0_32-8 111MB/s ± 2% 115MB/s ± 2% +3.77% (p=0.000 n=8+8) RegexpMatchEasy0_1K-8 618MB/s ± 1% 604MB/s ± 2% -2.16% (p=0.001 n=7+7) RegexpMatchEasy1_32-8 95.7MB/s ± 1% 105.1MB/s ± 2% +9.76% (p=0.000 n=8+8) RegexpMatchEasy1_1K-8 479MB/s ± 2% 477MB/s ± 0% ~ (p=0.105 n=8+8) RegexpMatchMedium_32-8 75.2MB/s ± 1% 75.2MB/s ± 0% ~ (p=0.247 n=7+7) RegexpMatchMedium_1K-8 12.6MB/s ± 3% 12.7MB/s ± 1% ~ (p=0.538 n=7+8) RegexpMatchHard_32-8 7.52MB/s ± 0% 7.52MB/s ± 0% ~ (p=0.968 n=7+8) RegexpMatchHard_1K-8 8.26MB/s ± 0% 8.24MB/s ± 0% -0.30% (p=0.001 n=8+8) Revcomp-8 173MB/s ± 2% 176MB/s ± 1% +1.68% (p=0.003 n=8+8) Template-8 9.85MB/s ± 2% 9.69MB/s ± 3% -1.59% (p=0.021 n=8+8) Fixes #39303 Updates #38740 Change-Id: I0a5f87bfda679f66414c0041ace2ca2e28363f36 Reviewed-on: https://go-review.googlesource.com/c/go/+/236637 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-06-08all: treat all files as binary, but check in .bat with CRLFDmitri Shuralyov
This is a followup to CL 96495. It should be simpler and more robust to achieve .bat files having CRLF line endings by treating it as a binary file, like all other files, and checking it in with the desired CRLF line endings. A test is used to check the entire Go tree, short of directories starting with "." and named "testdata", for any .bat files that have anything other than strict CRLF line endings. This will help catch any accidental modifications to existing .bat files or check ins of new .bat files. Importantly, this is compatible with how Gerrit serves .tar.gz files, making it so that CRLF line endings are preserved. The Go project is supported on many different environments, some of which may have limited git implementations available, or none at all. Relying on fewer git features and special rules makes it easier to have confidence in the exact content of all files. Additionally, Go development started in Subversion, moved to Perforce, then Mercurial, and now uses Git.¹ Reducing its reliance on git-specific features will help if there will be another transition in the project's future. There are only 5 .bat files in the entire Go source tree, so a new one being added is a rare event, and we prefer to do things in Go instead. We still have the option of improving the experience for developers by adding a pre-commit converter for .bat files to the git-codereview tool. ¹ https://groups.google.com/d/msg/golang-dev/sckirqOWepg/YmyT7dWJiocJ Fixes #39391. For #37791. Change-Id: I6e202216322872f0307ac96f1b8d3f57cb901e6b Reviewed-on: https://go-review.googlesource.com/c/go/+/236437 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-06-04cmd/compile: add interface equality testsKeith Randall
Add interfaces which differ in type. Those used so far only differ in value, not type. These additional tests are needed to generate a failure before CL 236278 went in. Update #8606 Change-Id: Icdb7647b1973c2fff7e5afe2bd8b8c1b384f583e Reviewed-on: https://go-review.googlesource.com/c/go/+/236418 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-06-03cmd/compile: test that equality is evaluated in orderKeith Randall
Make sure that we compare fields of structs and elements of arrays in order, with proper short-circuiting. Update #8606 Change-Id: I0a66ad92ea0af7bcc56dfdb275dec2b8d7e8b4fe Reviewed-on: https://go-review.googlesource.com/c/go/+/236147 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-31runtime: fix race condition between timer and event handlerRichard Musiol
This change fixes a race condition between beforeIdle waking up the innermost event handler and a timer causing a different goroutine to wake up at the exact same moment. This messes up the wasm event handling and leads to memory corruption. The solution is to make beforeIdle return the goroutine that must run next and have findrunnable pick this goroutine without considering timers again. Fixes #38093 Fixes #38574 Change-Id: Iffbe99411d25c2730953d1c8b0741fd892f8e540 Reviewed-on: https://go-review.googlesource.com/c/go/+/230178 Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-05-29cmd/compile: fix incorrect rewriting to if conditionXiangdong Ji
Some ARM64 rewriting rules convert 'comparing to zero' conditions of if statements to a simplified version utilizing CMN and CMP instructions to branch over condition flags, in order to save one Add or Sub caculation. Such optimizations lead to wrong branching in case an overflow/underflow occurs when executing CMN or CMP. Fix the issue by introducing new block opcodes that don't honor the overflow/underflow flag, in the following categories: Block-Op Meaning ARM condition codes 1. LTnoov less than MI 2. GEnoov greater than or equal PL 3. LEnoov less than or equal MI || EQ 4. GTnoov greater than NEQ & PL The backend generates two consecutive branch instructions for 'LEnoov' and 'GTnoov' to model their expected behavior. A slight change to 'gc' and amd64/386 backends is made to unify the code generation. Add a test 'TestCondRewrite' as justification, it covers 32 incorrect rules identified on arm64, more might be needed on other arches, like 32-bit arm. Add two benchmarks profiling the aforementioned category 1&2 and category 3&4 separetely, we expect the first two categories will show performance improvement and the second will not result in visible regression compared with the non-optimized version. This change also updates TestFormats to support using %#x. Examples exhibiting where does the issue come from: 1: 'if x + 3 < 0' might be converted to: before: CMN $3, R0 BGE <else branch> // wrong branch is taken if 'x+3' overflows after: CMN $3, R0 BPL <else branch> 2: 'if y - 3 > 0' might be converted to: before: CMP $3, R0 BLE <else branch> // wrong branch is taken if 'y-3' underflows after: CMP $3, R0 BMI <else branch> BEQ <else branch> Benchmark data from different kinds of arm64 servers, 'old' is the non-optimized version (not the parent commit), generally the optimization version outperforms. S1: name old time/op new time/op delta CondRewrite/SoloJump 13.6ns ± 0% 12.9ns ± 0% -5.15% (p=0.000 n=10+10) CondRewrite/CombJump 13.8ns ± 1% 12.9ns ± 0% -6.32% (p=0.000 n=10+10) S2: name old time/op new time/op delta CondRewrite/SoloJump 11.6ns ± 0% 10.9ns ± 0% -6.03% (p=0.000 n=10+10) CondRewrite/CombJump 11.4ns ± 0% 10.8ns ± 1% -5.53% (p=0.000 n=10+10) S3: name old time/op new time/op delta CondRewrite/SoloJump 7.36ns ± 0% 7.50ns ± 0% +1.79% (p=0.000 n=9+10) CondRewrite/CombJump 7.35ns ± 0% 7.75ns ± 0% +5.51% (p=0.000 n=8+9) S4: name old time/op new time/op delta CondRewrite/SoloJump-224 11.5ns ± 1% 10.9ns ± 0% -4.97% (p=0.000 n=10+10) CondRewrite/CombJump-224 11.9ns ± 0% 11.5ns ± 0% -2.95% (p=0.000 n=10+10) S5: name old time/op new time/op delta CondRewrite/SoloJump 10.0ns ± 0% 10.0ns ± 0% -0.45% (p=0.000 n=9+10) CondRewrite/CombJump 9.93ns ± 0% 9.77ns ± 0% -1.53% (p=0.000 n=10+9) Go1 perf. data: name old time/op new time/op delta BinaryTree17 6.29s ± 1% 6.30s ± 1% ~ (p=1.000 n=5+5) Fannkuch11 5.40s ± 0% 5.40s ± 0% ~ (p=0.841 n=5+5) FmtFprintfEmpty 97.9ns ± 0% 98.9ns ± 3% ~ (p=0.937 n=4+5) FmtFprintfString 171ns ± 3% 171ns ± 2% ~ (p=0.754 n=5+5) FmtFprintfInt 212ns ± 0% 217ns ± 6% +2.55% (p=0.008 n=5+5) FmtFprintfIntInt 296ns ± 1% 297ns ± 2% ~ (p=0.516 n=5+5) FmtFprintfPrefixedInt 371ns ± 2% 374ns ± 7% ~ (p=1.000 n=5+5) FmtFprintfFloat 435ns ± 1% 439ns ± 2% ~ (p=0.056 n=5+5) FmtManyArgs 1.37µs ± 1% 1.36µs ± 1% ~ (p=0.730 n=5+5) GobDecode 14.6ms ± 4% 14.4ms ± 4% ~ (p=0.690 n=5+5) GobEncode 11.8ms ±20% 11.6ms ±15% ~ (p=1.000 n=5+5) Gzip 507ms ± 0% 491ms ± 0% -3.22% (p=0.008 n=5+5) Gunzip 73.8ms ± 0% 73.9ms ± 0% ~ (p=0.690 n=5+5) HTTPClientServer 116µs ± 0% 116µs ± 0% ~ (p=0.686 n=4+4) JSONEncode 21.8ms ± 1% 21.6ms ± 2% ~ (p=0.151 n=5+5) JSONDecode 104ms ± 1% 103ms ± 1% -1.08% (p=0.016 n=5+5) Mandelbrot200 9.53ms ± 0% 9.53ms ± 0% ~ (p=0.421 n=5+5) GoParse 7.55ms ± 1% 7.51ms ± 1% ~ (p=0.151 n=5+5) RegexpMatchEasy0_32 158ns ± 0% 158ns ± 0% ~ (all equal) RegexpMatchEasy0_1K 606ns ± 1% 608ns ± 3% ~ (p=0.937 n=5+5) RegexpMatchEasy1_32 143ns ± 0% 144ns ± 1% ~ (p=0.095 n=5+4) RegexpMatchEasy1_1K 927ns ± 2% 944ns ± 2% ~ (p=0.056 n=5+5) RegexpMatchMedium_32 16.0ns ± 0% 16.0ns ± 0% ~ (all equal) RegexpMatchMedium_1K 69.3µs ± 2% 69.7µs ± 0% ~ (p=0.690 n=5+5) RegexpMatchHard_32 3.73µs ± 0% 3.73µs ± 1% ~ (p=0.984 n=5+5) RegexpMatchHard_1K 111µs ± 1% 110µs ± 0% ~ (p=0.151 n=5+5) Revcomp 1.91s ±47% 1.77s ±68% ~ (p=1.000 n=5+5) Template 138ms ± 1% 138ms ± 1% ~ (p=1.000 n=5+5) TimeParse 787ns ± 2% 785ns ± 1% ~ (p=0.540 n=5+5) TimeFormat 729ns ± 1% 726ns ± 1% ~ (p=0.151 n=5+5) Updates #38740 Change-Id: I06c604874acdc1e63e66452dadee5df053045222 Reviewed-on: https://go-review.googlesource.com/c/go/+/233097 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org>
2020-05-14cmd/compile: add test for issue 37246Josh Bleecher Snyder
CL 233857 fixed the underlying issue for #37246, which had arisen again as #38916. Add the test case from #37246 to ensure it stays fixed. Fixes #37246 Change-Id: If7fd75a096d2ce4364dc15509253c3882838161d Reviewed-on: https://go-review.googlesource.com/c/go/+/233941 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Munday <mike.munday@ibm.com>
2020-05-14cmd/compile: fix tuple selector bug in CSE passMichael Munday
When tuple generators and selectors are eliminated as part of the CSE pass we may end up with tuple selectors that are in different blocks to the tuple generators that they correspond to. This breaks the invariant that tuple generators and their corresponding selectors must be in the same block. Therefore after CSE this situation must be corrected. Unfortunately the fixup code did not take into account that selectors could be eliminated by CSE. It assumed that only the tuple generators could be eliminated. In some situations this meant that it got into a state where it was replacing references to selectors with references to dead selectors in the wrong block. To fix this we move the fixup code after the CSE rewrites have been applied. This removes any difficult-to-reason-about interactions with the CSE rewriter. Fixes #38916. Change-Id: I2211982dcdba399d03299f0a819945b3eb93b291 Reviewed-on: https://go-review.googlesource.com/c/go/+/233857 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
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-05-08cmd/compile: improve error when setting unexported fieldsEmmanuel T Odeke
Improve the error user experience when users try to set/refer to unexported fields and methods of struct literals, by directly saying "cannot refer to unexported field or method" Fixes #31053 Change-Id: I6fd3caf64b7ca9f9d8ea60b7756875e340792d59 Reviewed-on: https://go-review.googlesource.com/c/go/+/201657 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-08cmd/compile: omit file:pos for non-existent errorsEmmanuel T Odeke
Omits printing the file:line:column when trying to open non-existent files Given: go tool compile x.go * Before: x.go:0: open x.go: no such file or directory * After: open x.go: no such file or directory Reverts the revert in CL 231043 by only fixing the case of non-existent errors which is what the original bug was about. The fix for "permission errors" will come later on when I have bandwidth to investigate the differences between running with root and why os.Open works for some builders and not others. Fixes #36437 Change-Id: I9c8a0981ad708b504bb43990a4105b42266fa41f Reviewed-on: https://go-review.googlesource.com/c/go/+/230941 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-05-07cmd/compile: optimize make+copy pattern to avoid memclrMartin Möhrmann
match: m = make([]T, x); copy(m, s) for pointer free T and x==len(s) rewrite to: m = mallocgc(x*elemsize(T), nil, false); memmove(&m, &s, x*elemsize(T)) otherwise rewrite to: m = makeslicecopy([]T, x, s) This avoids memclear and shading of pointers in the newly created slice before the copy. With this CL "s" is only be allowed to bev a variable and not a more complex expression. This restriction could be lifted in future versions of this optimization when it can be proven that "s" is not referencing "m". Triggers 450 times during make.bash.. Reduces go binary size by ~8 kbyte. name old time/op new time/op delta MakeSliceCopy/mallocmove/Byte 71.1ns ± 1% 65.8ns ± 0% -7.49% (p=0.000 n=10+9) MakeSliceCopy/mallocmove/Int 71.2ns ± 1% 66.0ns ± 0% -7.27% (p=0.000 n=10+8) MakeSliceCopy/mallocmove/Ptr 104ns ± 4% 99ns ± 1% -5.13% (p=0.000 n=10+10) MakeSliceCopy/makecopy/Byte 70.3ns ± 0% 68.0ns ± 0% -3.22% (p=0.000 n=10+9) MakeSliceCopy/makecopy/Int 70.3ns ± 0% 68.5ns ± 1% -2.59% (p=0.000 n=9+10) MakeSliceCopy/makecopy/Ptr 102ns ± 0% 99ns ± 1% -2.97% (p=0.000 n=9+9) MakeSliceCopy/nilappend/Byte 75.4ns ± 0% 74.9ns ± 2% -0.63% (p=0.015 n=9+9) MakeSliceCopy/nilappend/Int 75.6ns ± 0% 76.4ns ± 3% ~ (p=0.245 n=9+10) MakeSliceCopy/nilappend/Ptr 107ns ± 0% 108ns ± 1% +0.93% (p=0.005 n=9+10) Fixes #26252 Change-Id: Iec553dd1fef6ded16197216a472351c8799a8e71 Reviewed-on: https://go-review.googlesource.com/c/go/+/146719 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-06cmd/compile: do not emit code for discardable blank fieldsCuong Manh Le
Fixes #38690 Change-Id: I3544daf617fddc0f89636265c113001178d16b0c Reviewed-on: https://go-review.googlesource.com/c/go/+/230121 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-05-05cmd/compile: restrict bit test rewrite rulesKeith Randall
The {AND,OR,XOR}const ops can only take an int32 as an argument. Make sure that when rewriting a BTx op to one of these, the result has no high-order bits. Fixes #38746 Change-Id: Ia7c5f76952329f60974bc033c29a5433610f3b28 Reviewed-on: https://go-review.googlesource.com/c/go/+/231977 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-04-30cmd/compile: add indexed memory modification ops to amd64Keith Randall
name old time/op new time/op delta Modify-16 404ns ± 1% 365ns ± 1% -9.73% (p=0.000 n=10+10) ConstModify-16 407ns ± 0% 385ns ± 2% -5.56% (p=0.000 n=9+10) Seems to generally help generated code. Binary size change is in the noise. Change-Id: I57891bfaf0f7dfc5d143bb9f7ebafc7079d2614f Reviewed-on: https://go-review.googlesource.com/c/go/+/228098 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-04-30cmd/compile: add indexed load+op operations to amd64Keith Randall
name old time/op new time/op delta LoadAdd-16 545ns ± 0% 456ns ± 0% -16.31% (p=0.000 n=10+10) Update #36468 Change-Id: I84f390d55490648fa1f58cdbc24fd74c4f1bc8c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/227960 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-04-30Revert "cmd/compile: omit file:pos for non-existent, permission errors"Austin Clements
This reverts commit 4f7053c87f9ebf3acab7669d380f53bdfba0566b. Reason for revert: Newly added test is failing on several builders. Change-Id: I22dcbfebf2f57735b2f479886bbeb623f95b132f Reviewed-on: https://go-review.googlesource.com/c/go/+/231043 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-30cmd/compile: omit file:pos for non-existent, permission errorsEmmanuel T Odeke
Omits printing the file:line:column when trying to open either * non-existent files * files without permission Given: go tool compile x.go For either of x.go not existing, or if no read permissions: * Before: x.go:0: open x.go: no such file or directory x.go:0: open x.go: permission denied * After: open x.go: no such file or directory open x.go: permission denied While here, noticed an oddity with the Linux builders, that appear to always be running under root, hence the test for permission errors with 0222 -W-*-W-*-W- can't pass on linux-amd64 builders. The filed bug is #38608. Fixes #36437 Change-Id: I9645ef73177c286c99547e3a0f3719fa07b35cb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/229357 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-04-24cmd/compile: optimize Move with all-zero ro sym src to ZeroJosh Bleecher Snyder
We set up static symbols during walk that we later make copies of to initialize local variables. It is difficult to ascertain at that time exactly when copying a symbol is profitable vs locally initializing an autotmp. During SSA, we are much better placed to optimize. This change recognizes when we are copying from a global readonly all-zero symbol and replaces it with direct zeroing. This often allows the all-zero symbol to be deadcode eliminated at link time. This is not ideal--it makes for large object files, and longer link times--but it is the cleanest fix I could find. This makes the final binary for the program in #38554 shrink from >500mb to ~2.2mb. It also shrinks the standard binaries: file before after Δ % addr2line 4412496 4404304 -8192 -0.186% buildid 2893816 2889720 -4096 -0.142% cgo 4841048 4832856 -8192 -0.169% compile 19926480 19922432 -4048 -0.020% cover 5281816 5277720 -4096 -0.078% link 6734648 6730552 -4096 -0.061% nm 4366240 4358048 -8192 -0.188% objdump 4755968 4747776 -8192 -0.172% pprof 14653060 14612100 -40960 -0.280% trace 11805940 11777268 -28672 -0.243% vet 7185560 7181416 -4144 -0.058% total 113588440 113465560 -122880 -0.108% And not just by removing unnecessary symbols; the program text shrinks a bit as well. Fixes #38554 Change-Id: I8381ae6084ae145a5e0cd9410c451e52c0dc51c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/229704 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Keith Randall <khr@golang.org>
2020-04-23cmd/compile: use fixVariadicCall in escape analysisMatthew Dempsky
This CL uses fixVariadicCall before escape analyzing function calls. This has a number of benefits, though also some minor obstacles: Most notably, it allows us to remove ODDDARG along with the logic involved in setting it up, manipulating EscHoles, and later copying its escape analysis flags to the actual slice argument. Instead, we uniformly handle all variadic calls the same way. (E.g., issue31573.go is updated because now f() and f(nil...) are handled identically.) It also allows us to simplify handling of builtins and generic function calls. Previously handling of calls was hairy enough to require multiple dispatches on n.Op, whereas now the logic is uniform enough that we can easily handle it with a single dispatch. The downside is handling //go:uintptrescapes is now somewhat clumsy. (It used to be clumsy, but it still is, too.) The proper fix here is probably to stop using escape analysis tags for //go:uintptrescapes and unsafe-uintptr, and have an earlier pass responsible for them. Finally, note that while we now call fixVariadicCall in Escape, we still have to call it in Order, because we don't (yet) run Escape on all compiler-generated functions. In particular, the generated "init" function for initializing package-level variables can contain calls to variadic functions and isn't escape analyzed. Passes toolstash-check -race. Change-Id: I4cdb92a393ac487910aeee58a5cb8c1500eef881 Reviewed-on: https://go-review.googlesource.com/c/go/+/229759 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-04-23cmd/compile: optimize x & 1 != 0 to x & 1 on amd64Josh Bleecher Snyder
Triggers a handful of times in std+cmd. Change-Id: I9bb8ce9a5f8bae2547cb61157cd8f256e1b63e76 Reviewed-on: https://go-review.googlesource.com/c/go/+/229602 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-04-22cmd/compile: clean up codegen for branch-on-carry on s390xMichael Munday
This CL optimizes code that uses a carry from a function such as bits.Add64 as the condition in an if statement. For example: x, c := bits.Add64(a, b, 0) if c != 0 { panic("overflow") } Rather than converting the carry into a 0 or a 1 value and using that as an input to a comparison instruction the carry flag is now used as the input to a conditional branch directly. This typically removes an ADD LOGICAL WITH CARRY instruction when user code is doing overflow detection and is closer to the code that a user would expect to generate. Change-Id: I950431270955ab72f1b5c6db873b6abe769be0da Reviewed-on: https://go-review.googlesource.com/c/go/+/219757 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-04-21cmd/compile: more precise analysis of method valuesMatthew Dempsky
Previously for a method value "x.M", we always flowed x directly to the heap, which led to the receiver argument generally needing to be heap allocated. This CL changes it to flow x to the closure and M's receiver parameter. This allows receiver arguments to be stack allocated as long as (1) the closure never escapes, *and* (2) method doesn't leak its receiver parameter. Within the standard library, this allows a handful of objects to be stack allocated instead. Listed here are diagnostics that were previously emitted by "go build -gcflags=-m std cmd" that are no longer emitted: archive/tar/writer.go:118:6: moved to heap: f archive/tar/writer.go:208:6: moved to heap: f archive/tar/writer.go:248:6: moved to heap: f cmd/compile/internal/gc/initorder.go:252:2: moved to heap: d cmd/compile/internal/gc/initorder.go:75:2: moved to heap: s cmd/go/internal/generate/generate.go:206:7: &Generator literal escapes to heap cmd/internal/obj/arm64/asm7.go:910:2: moved to heap: c cmd/internal/obj/mips/asm0.go:415:2: moved to heap: c cmd/internal/obj/pcln.go:294:22: new(pcinlineState) escapes to heap cmd/internal/obj/s390x/asmz.go:459:2: moved to heap: c crypto/tls/handshake_server.go:56:2: moved to heap: hs Thanks to Cuong Manh Le for help coming up with this solution. Fixes #27557. Change-Id: I8c85d671d07fb9b53e11d2dd05949a34dbbd7e17 Reviewed-on: https://go-review.googlesource.com/c/go/+/228263 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-21cmd/compile: optimize comparisons with immediates on s390xMichael Munday
When generating code for unsigned equals (==) and not equals (!=) comparisons we currently, on s390x, always use signed comparisons. This mostly works well, however signed comparisons on s390x sign extend their immediates and unsigned comparisons zero extend them. For compare-and-branch instructions which can only have 8-bit immediates this significantly changes the range of immediate values we can represent: [-128, 127] for signed comparisons and [0, 255] for unsigned comparisons. When generating equals and not equals checks we don't neet to worry about whether the comparison is signed or unsigned. This CL therefore adds rules to allow us to switch signedness for such comparisons if it means that it brings a constant into range for an 8-bit immediate. For example, a signed equals with an integer in the range [128, 255] will now be implemented using an unsigned compare-and-branch instruction rather than separate compare and branch instructions. As part of this change I've also added support for adding a name to block control values using the same `x:(...)` syntax we use for value rules. Triggers 792 times when compiling cmd and std. Change-Id: I77fa80a128f0a8ce51a2888d1e384bd5e9b61a77 Reviewed-on: https://go-review.googlesource.com/c/go/+/228642 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-04-21cmd/compile: detect and diagnose invalid //go: directive placementRuss Cox
Thie CL changes cmd/compile/internal/syntax to give the gc half of the compiler more control over pragma handling, so that it can prepare better errors, diagnose misuse, and so on. Before, the API between the two was hard-coded as a uint16. Now it is an interface{}. This should set us up better for future directives. In addition to the split, this CL emits a "misplaced compiler directive" error for any directive that is in a place where it has no effect. I've certainly been confused in the past by adding comments that were doing nothing and not realizing it. This should help avoid that kind of confusion. The rule, now applied consistently, is that a //go: directive must appear on a line by itself immediately before the declaration specifier it means to apply to. See cmd/compile/doc.go for precise text and test/directive.go for examples. This may cause some code to stop compiling, but that code was broken. For example, this code formerly applied the //go:noinline to f (not c) but now will fail to compile: //go:noinline const c = 1 func f() {} Change-Id: Ieba9b8d90a27cfab25de79d2790a895cefe5296f Reviewed-on: https://go-review.googlesource.com/c/go/+/228578 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-04-21test/codegen, runtime/pprof, runtime: apply fmtalex-semenyuk
Change-Id: Ife4e065246729319c39e57a4fbd8e6f7b37724e1 GitHub-Last-Rev: e71803eaeb366c00f6c156de0b0b2c50927a0e82 GitHub-Pull-Request: golang/go#38527 Reviewed-on: https://go-review.googlesource.com/c/go/+/228901 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>