aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/export_test.go
AgeCommit message (Collapse)Author
2017-02-28cmd/compile: fix merging of s390x conditional moves into branch conditionsMichael Munday
A type conversion inserted between MOVD{LT,LE,GT,GE,EQ,NE} and CMPWconst by CL 36256 broke the rewrite rule designed to merge the two. This results in simple for loops (e.g. for i := 0; i < N; i++ {}) emitting two comparisons instead of one, plus a conditional move. This CL explicitly types the input to CMPWconst so that the type conversion can be omitted. It also adds a test to check that conditional moves aren't emitted for loops with 'less than' conditions (i.e. i < N) on s390x. Fixes #19227. Change-Id: Ia39e806ed723791c3c755951aef23f957828ea3e Reviewed-on: https://go-review.googlesource.com/37334 Reviewed-by: Keith Randall <khr@golang.org>
2017-02-06cmd/compile/internal/ssa: use obj.LSym instead of gc.SymMatthew Dempsky
Gc's Sym type represents a package-qualified identifier, which is a frontend concept and doesn't belong in SSA. Bonus: we can replace some interface{} types with *obj.LSym. Passes toolstash -cmp. Change-Id: I456eb9957207d80f99f6eb9b8eab4a1f3263e9ed Reviewed-on: https://go-review.googlesource.com/36415 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2017-01-09[dev.inline] cmd/internal/src: introduce compact source position representationRobert Griesemer
XPos is a compact (8 instead of 16 bytes on a 64bit machine) source position representation. There is a 1:1 correspondence between each XPos and each regular Pos, translated via a global table. In some sense this brings back the LineHist, though positions can track line and column information; there is a O(1) translation between the representations (no binary search), and the translation is factored out. The size increase with the prior change is brought down again and the compiler speed is in line with the master repo (measured on the same "quiet" machine as for prior change): name old time/op new time/op delta Template 256ms ± 1% 262ms ± 2% ~ (p=0.063 n=5+4) Unicode 132ms ± 1% 135ms ± 2% ~ (p=0.063 n=5+4) GoTypes 891ms ± 1% 871ms ± 1% -2.28% (p=0.016 n=5+4) Compiler 3.84s ± 2% 3.89s ± 2% ~ (p=0.413 n=5+4) MakeBash 47.1s ± 1% 46.2s ± 2% ~ (p=0.095 n=5+5) name old user-ns/op new user-ns/op delta Template 309M ± 1% 314M ± 2% ~ (p=0.111 n=5+4) Unicode 165M ± 1% 172M ± 9% ~ (p=0.151 n=5+5) GoTypes 1.14G ± 2% 1.12G ± 1% ~ (p=0.063 n=5+4) Compiler 5.00G ± 1% 4.96G ± 1% ~ (p=0.286 n=5+4) Change-Id: Icc570cc60ab014d8d9af6976f1f961ab8828cc47 Reviewed-on: https://go-review.googlesource.com/34506 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-12-08[dev.inline] cmd/compile: introduce cmd/internal/src.Pos type for line numbersRobert Griesemer
This is a step toward chosing a different position representation. By introducing an explicit type, it will be easier to make the transition step-wise while ensuring everything keeps running. This has been reviewed via https://go-review.googlesource.com/#/c/34025/. Change-Id: Ibceddcd62d8f346321ac3250e3940e9c436ed684 Reviewed-on: https://go-review.googlesource.com/34132 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Lazar <lazard@golang.org>
2016-12-05cmd/compile: find last StoreWB explicitlyCherry Zhang
In writebarrier phase, a chain of StoreWBs is rewritten to branchy code to invoke write barriers, and the last store in the chain is spliced into a Phi op to join the memory of the two branches. We must find the last store explicitly, since the values are not scheduled and they may not come in dependency order. Fixes #18169. Change-Id: If547e3c562ef0669bc5622c1bb711904dc36314d Reviewed-on: https://go-review.googlesource.com/33915 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2016-10-31cmd/compile: make [0]T and [1]T SSAable typesKeith Randall
We used to have to keep on-stack copies of these types. Now they can be registerized. [0]T is kind of trivial but might as well handle it. This change enables another change I'm working on to improve how x.(T) expressions are handled (#17405). This CL helps because now all types that are direct interface types are registerizeable (e.g. [1]*byte). No higher-degree arrays for now because non-constant indexes are hard. Update #17405 Change-Id: I2399940965d17b3969ae66f6fe447a8cefdd6edd Reviewed-on: https://go-review.googlesource.com/32416 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2016-10-25cmd/compile: add a writebarrier phase in SSACherry Zhang
When the compiler insert write barriers, the frontend makes conservative decisions at an early stage. This may have false positives which result in write barriers for stack writes. A new phase, writebarrier, is added to the SSA backend, to delay the decision and eliminate false positives. The frontend still makes conservative decisions. When building SSA, instead of emitting runtime calls directly, it emits WB ops (StoreWB, MoveWB, etc.), which will be expanded to branches and runtime calls in writebarrier phase. Writes to static locations on stack are detected and write barriers are removed. All write barriers of stack writes found by the script from issue #17330 are eliminated (except two false positives). Fixes #17330. Change-Id: I9bd66333da9d0ceb64dcaa3c6f33502798d1a0f8 Reviewed-on: https://go-review.googlesource.com/31131 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2016-10-04cmd/compile: layout stack frame during SSAMatthew Dempsky
Identify live stack variables during SSA and compute the stack frame layout earlier so that we can emit instructions with the correct offsets upfront. Passes toolstash/buildall. Change-Id: I191100dba274f1e364a15bdcfdc1d1466cdd1db5 Reviewed-on: https://go-review.googlesource.com/30216 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2016-09-14cmd/compile: make ssa compilation unconditionalKeith Randall
Rip out the code that allows SSA to be used conditionally. No longer exists: ssa=0 flag GOSSAHASH GOSSAPKG SSATEST GOSSAFUNC now only controls the printing of the IR/html. Still need to rip out all of the old backend. It should no longer be callable after this CL. Update #16357 Change-Id: Ib30cc18fba6ca52232c41689ba610b0a94aa74f5 Reviewed-on: https://go-review.googlesource.com/29155 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-06-02[dev.ssa] cmd/compile: decompose 64-bit integer on ARMCherry Zhang
Introduce dec64 rules to (generically) decompose 64-bit integer on 32-bit architectures. 64-bit integer is composed/decomposed with Int64Make/Hi/Lo ops, as for complex types. The idea of dealing with Add64 is the following: (Add64 (Int64Make xh xl) (Int64Make yh yl)) -> (Int64Make (Add32withcarry xh yh (Select0 (Add32carry xl yl))) (Select1 (Add32carry xl yl))) where Add32carry returns a tuple (flags,uint32). Select0 and Select1 read the first and the second component of the tuple, respectively. The two Add32carry will be CSE'd. Similarly for multiplication, Mul32uhilo returns a tuple (hi, lo). Also add support of KeepAlive, to fix build after merge. Tests addressed_ssa.go, array_ssa.go, break_ssa.go, chan_ssa.go, cmp_ssa.go, ctl_ssa.go, map_ssa.go, and string_ssa.go in cmd/compile/internal/gc/testdata passed. Progress on SSA for ARM. Still not complete. Updates #15365. Change-Id: I7867c76785a456312de5d8398a6b3f7ca5a4f7ec Reviewed-on: https://go-review.googlesource.com/23213 Reviewed-by: Keith Randall <khr@golang.org>
2016-04-28cmd/compile: reorg copyelim to avoid O(n^2) problemKeith Randall
Make sure we don't do O(n^2) work to eliminate a chain of n copies. benchmark old ns/op new ns/op delta BenchmarkCopyElim1-8 1418 1406 -0.85% BenchmarkCopyElim10-8 5289 5162 -2.40% BenchmarkCopyElim100-8 52618 41684 -20.78% BenchmarkCopyElim1000-8 2473878 424339 -82.85% BenchmarkCopyElim10000-8 269373954 6367971 -97.64% BenchmarkCopyElim100000-8 31272781165 104357244 -99.67% Change-Id: I680f906f70f2ee1a8615cb1046bc510c77d59284 Reviewed-on: https://go-review.googlesource.com/22535 Reviewed-by: Alexandru Moșoi <alexandru@mosoi.ro>
2016-04-11cmd/compile: fix naming of decomposed structsKeith Randall
When a struct is SSAable, we will name its component parts by their field names. For example, type T struct { a, b, c int } If we ever need to spill a variable x of type T, we will spill its individual components to variables named x.a, x.b, and x.c. Change-Id: I857286ff1f2597f2c4bbd7b4c0b936386fb37131 Reviewed-on: https://go-review.googlesource.com/21389 Reviewed-by: David Chase <drchase@google.com>
2016-03-31cmd/compile: better job of naming compound typesKeith Randall
Compound AUTO types weren't named previously. That was because live variable analysis (plive.go) doesn't handle spilling to compound types. It can't handle them because there is no valid place to put VARDEFs when regalloc is spilling compound types. compound types = multiword builtin types: complex, string, slice, and interface. Instead, we split named AUTOs into individual one-word variables. For example, a string s gets split into a byte ptr s.ptr and an integer s.len. Those two variables can be spilled to / restored from independently. As a result, live variable analysis can handle them because they are one-word objects. This CL will change how AUTOs are described in DWARF information. Consider the code: func f(s string, i int) int { x := s[i:i+5] g() return lookup(x) } The old compiler would spill x to two consecutive slots on the stack, both named x (at offsets 0 and 8). The new compiler spills the pointer of x to a slot named x.ptr. It doesn't spill x.len at all, as it is a constant (5) and can be rematerialized for the call to lookup. So compound objects may not be spilled in their entirety, and even if they are they won't necessarily be contiguous. Such is the price of optimization. Re-enable live variable analysis tests. One test remains disabled, it fails because of #14904. Change-Id: I8ef2b5ab91e43a0d2136bfc231c05d100ec0b801 Reviewed-on: https://go-review.googlesource.com/21233 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2016-03-14cmd/compile: change the type of ssa Warnl line numberTodd Neal
Line numbers are always int32, so the Warnl function should take the line number as an int32 as well. This matches gc.Warnl and removes a cast every place it's used. Change-Id: I5d6201e640d52ec390eb7174f8fd8c438d4efe58 Reviewed-on: https://go-review.googlesource.com/20662 Run-TryBot: Todd Neal <todd@tneal.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2016-01-29[dev.ssa] cmd/compile: exposed do-log boolean to reduce allocationsDavid Chase
From memory profiling, about 3% reduction in allocation count. Change-Id: I4b662d55b8a94fe724759a2b22f05a08d0bf40f8 Reviewed-on: https://go-review.googlesource.com/19103 Reviewed-by: Keith Randall <khr@golang.org>
2016-01-28[dev.ssa] cmd/compile: make cse fasterKeith Randall
It is one of the slowest compiler phases right now, and we run two of them. Instead of using a map to make the initial partition, use a sort. It is much less memory intensive. Do a few optimizations to avoid work for size-1 equivalence classes. Implement -N. Change-Id: I1d2d85d3771abc918db4dd7cc30b0b2d854b15e1 Reviewed-on: https://go-review.googlesource.com/19024 Reviewed-by: David Chase <drchase@google.com>
2016-01-20[dev.ssa] cmd/compile: optimize phi opsKeith Randall
Redo how we keep track of forward references when building SSA. When the forward reference is resolved, update the Value node in place. Improve the phi elimination pass so it can simplify phis of phis. Give SSA package access to decoded line numbers. Fix line numbers for constant booleans. Change-Id: I3dc9896148d260be2f3dd14cbe5db639ec9fa6b7 Reviewed-on: https://go-review.googlesource.com/18674 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Keith Randall <khr@golang.org>
2016-01-19[dev.ssa] cmd/compile: report better line numbers for Unimplemented/FatalKeith Randall
If a failure occurs in SSA processing, we always report the last line of the function we're compiling. Modify the callbacks from SSA to the GC compiler so we can pass a line number back and use it in Fatalf. Change-Id: Ifbfad50d5e167e997e0a96f0775bcc369f5c397e Reviewed-on: https://go-review.googlesource.com/18599 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com>
2015-10-30[dev.ssa] cmd/compile: default compile+test with SSADavid Chase
Some tests disabled, some bifurcated into _ssa and not, with appropriate logging added to compiler. "tests/live.go" in particular needs attention. SSA-specific testing removed, since it's all SSA now. Added "-run_skips" option to tests/run.go to simplify checking whether a test still fails (or how it fails) on a skipped platform. The compiler now compiles with SSA by default. If you don't want SSA, specify GOSSAHASH=n (or N) as an environment variable. Function names ending in "_ssa" are always SSA-compiled. GOSSAFUNC=fname retains its "SSA for fname, log to ssa.html" GOSSAPKG=pkg only has an effect when GOSSAHASH=n GOSSAHASH=10101 etc retains its name-hash-matching behavior for purposes of debugging. See #13068 Change-Id: I8217bfeb34173533eaeb391b5f6935483c7d6b43 Reviewed-on: https://go-review.googlesource.com/16299 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: David Chase <drchase@google.com>
2015-10-28[dev.ssa] cmd/compile: remember names of valuesKeith Randall
For debugging, spill values to named variables instead of autotmp_ variables if possible. We do this by keeping a name -> value map for each function, keep it up-to-date during deadcode elim, and use it to override spill decisions in stackalloc. It might even make stack frames a bit smaller, as it makes it easy to identify a set of spills which are likely not to interfere. This just works for one-word variables for now. Strings/slices will be a separate CL. Change-Id: Ie89eba8cab16bcd41b311c479ec46dd7e64cdb67 Reviewed-on: https://go-review.googlesource.com/16336 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com>
2015-10-23[dev.ssa] cmd/compile: repair ssa testing build and testDavid Chase
Calls to NewConfig required an extra parameter that sometimes could not be nil. Change-Id: I806dd53c045056a0c2d30d641a20fe27fb790539 Reviewed-on: https://go-review.googlesource.com/16272 Reviewed-by: Keith Randall <khr@golang.org>
2015-09-19[dev.ssa] cmd/compile: move un-SSAable objectsKeith Randall
We need to move any objects whose types are not SSA-able. Fixes the "not lowered: Load ARRAY PTR64 mem" errors. Change-Id: I7a0b609f917d7fb34bc9215fee4da15f9961cf6c Reviewed-on: https://go-review.googlesource.com/14753 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-09-05[dev.ssa] cmd/runtime: generate gc bitmaps for SSA-compiled codeKeith Randall
This change is all about leveraging the gc bitmap generation that is already done by the current compiler. We rearrange how stack allocation is done so that we generate a variable declaration for each spill. We also reorganize how args/locals are recorded during SSA. Then we can use the existing allocauto/defframe to allocate the stack frame and liveness to make the gc bitmaps. With this change, stack copying works correctly and we no longer need hacks in runtime/stack*.go to make tests work. GC is close to working, it just needs write barriers. Change-Id: I990fb4e3fbe98850c6be35c3185a1c85d9e1a6ba Reviewed-on: https://go-review.googlesource.com/13894 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-28[dev.ssa] cmd/compile: add compose/decompose for complex, phi, constantsDavid Chase
Still to do: arithmetic Change-Id: I31fd23b34980c9ed4b4e304b8597134b2ba6ca5c Reviewed-on: https://go-review.googlesource.com/14024 Reviewed-by: Keith Randall <khr@golang.org>
2015-07-30[dev.ssa] cmd/compile: move most types outside SSAJosh Bleecher Snyder
The only types that remain in the ssa package are special compiler-only types. Change-Id: If957abf128ec0778910d67666c297f97f183b7ee Reviewed-on: https://go-review.googlesource.com/12933 Reviewed-by: Keith Randall <khr@golang.org>
2015-07-24[dev.ssa] cmd/compile: use string contents instead of offset from string headerJosh Bleecher Snyder
This generates more efficient code. Before: 0x003a 00058 (rr.go:7) LEAQ go.string.hdr."="(SB), BX 0x0041 00065 (rr.go:7) LEAQ 16(BX), BP 0x0045 00069 (rr.go:7) MOVQ BP, 16(SP) After: 0x003a 00058 (rr.go:7) LEAQ go.string."="(SB), BX 0x0041 00065 (rr.go:7) MOVQ BX, 16(SP) It also matches the existing backend and is more robust to other changes, such as CL 11698, which I believe broke the current code. This CL fixes the encoding/base64 tests, as run with: GOGC=off GOSSAPKG=base64 go test -a encoding/base64 Change-Id: I3c475bed1dd3335cc14e13309e11d23f0ed32c17 Reviewed-on: https://go-review.googlesource.com/12654 Reviewed-by: Keith Randall <khr@golang.org>
2015-06-29[dev.ssa] cmd/compile/ssa: add nilcheckelim benchmarksJosh Bleecher Snyder
These benchmarks demonstrate that the nilcheckelim pass is roughly O(n^2): BenchmarkNilCheckDeep1 2000000 741 ns/op 1.35 MB/s BenchmarkNilCheckDeep10 1000000 2237 ns/op 4.47 MB/s BenchmarkNilCheckDeep100 20000 60713 ns/op 1.65 MB/s BenchmarkNilCheckDeep1000 200 7925198 ns/op 0.13 MB/s BenchmarkNilCheckDeep10000 1 1220104252 ns/op 0.01 MB/s Profiling suggests that building the dominator tree is also O(n^2), and before size factors take over, considerably more expensive than nilcheckelim. Change-Id: If966b38ec52243a25f355dab871300d29db02e16 Reviewed-on: https://go-review.googlesource.com/11520 Reviewed-by: Keith Randall <khr@golang.org>
2015-06-24[dev.ssa] cmd/compile/ssa: add -f suffix to logging methodsJosh Bleecher Snyder
Requested in CL 11380. Change-Id: Icf0d23fb8d383c76272401e363cc9b2169d11403 Reviewed-on: https://go-review.googlesource.com/11450 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-21[dev.ssa] cmd/compile/ssa: separate logging, work in progress, and fatal errorsJosh Bleecher Snyder
The SSA implementation logs for three purposes: * debug logging * fatal errors * unimplemented features Separating these three uses lets us attempt an SSA implementation for all functions, not just _ssa functions. This turns the entire standard library into a compilation test, and makes it easy to figure out things like "how much coverage does SSA have now" and "what should we do next to get more coverage?". Functions called _ssa are still special. They log profusely by default and the output of the SSA implementation is used. For all other functions, logging is off, and the implementation is built and discarded, due to lack of support for the runtime. While we're here, fix a few minor bugs and add some extra Unimplementeds to allow all.bash to pass. As of now, SSA handles 20.79% of the functions in the standard library (689 of 3314). The top missing features are: 10.03% 2597 SSA unimplemented: zero for type error not implemented 7.79% 2016 SSA unimplemented: addr: bad op DOTPTR 7.33% 1898 SSA unimplemented: unhandled expr EQ 6.10% 1579 SSA unimplemented: unhandled expr OROR 4.91% 1271 SSA unimplemented: unhandled expr NE 4.49% 1163 SSA unimplemented: unhandled expr LROT 4.00% 1036 SSA unimplemented: unhandled expr LEN 3.56% 923 SSA unimplemented: unhandled stmt CALLFUNC 2.37% 615 SSA unimplemented: zero for type []byte not implemented 1.90% 492 SSA unimplemented: unhandled stmt CALLMETH 1.74% 450 SSA unimplemented: unhandled expr CALLINTER 1.74% 450 SSA unimplemented: unhandled expr DOT 1.71% 444 SSA unimplemented: unhandled expr ANDAND 1.65% 426 SSA unimplemented: unhandled expr CLOSUREVAR 1.54% 400 SSA unimplemented: unhandled expr CALLMETH 1.51% 390 SSA unimplemented: unhandled stmt SWITCH 1.47% 380 SSA unimplemented: unhandled expr CONV 1.33% 345 SSA unimplemented: addr: bad op * 1.30% 336 SSA unimplemented: unhandled OLITERAL 6 Change-Id: I4ca07951e276714dc13c31de28640aead17a1be7 Reviewed-on: https://go-review.googlesource.com/11160 Reviewed-by: Keith Randall <khr@golang.org>
2015-06-04[dev.ssa] cmd/compile/internal/ssa: Add dummy frontend for testing.Keith Randall
Change-Id: Ica26c0297ac7afeb0b5b668cf5f5cd1667c6cc43 Reviewed-on: https://go-review.googlesource.com/10699 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-05-30[dev.ssa] cmd/compile/internal/ssa: Implement block rewriting rulesKeith Randall
Change-Id: I47e5349e34fc18118c4d35bf433f875b958cc3e5 Reviewed-on: https://go-review.googlesource.com/10495 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-28[dev.ssa] Merge remote-tracking branch 'origin/master' into mergebranchKeith Randall
Semi-regular merge of tip to dev.ssa. Complicated a bit by the move of cmd/internal/* to cmd/compile/internal/*. Change-Id: I1c66d3c29bb95cce4a53c5a3476373aa5245303d