Keith Randall [Thu, 3 Sep 2015 16:09:59 +0000 (09:09 -0700)]
[dev.ssa] cmd/compile/internal/ssa: distinguish exit and return blocks
It is confusing to have exceptional edges jump back into
real code. Distinguish return blocks, which execute acutal
code, and the exit block, which is a merge point for the regular
and exceptional return flow.
Prevent critical edge insertion from adding blocks on edges
into the exit block. These added blocks serve no purpose and
add a bunch of dead jumps to the assembly output. Furthermore,
live variable analysis is confused by these jumps.
Change-Id: Ifd69e6c00e90338ed147e7cb351b5100dc0364df
Reviewed-on: https://go-review.googlesource.com/14254 Reviewed-by: David Chase <drchase@google.com>
Todd Neal [Sat, 29 Aug 2015 20:41:57 +0000 (15:41 -0500)]
[dev.ssa] cmd/compile: fix rare issue caused by liblink rewrite
liblink rewrites MOV $0, reg into XOR reg, reg. Make MOVxconst clobber
flags so we don't generate invalid code in the unlikely case that it
matters. In testing, this change leads to no additional regenerated
flags due to a scheduling fix in CL14042.
Change-Id: I7bc1cfee94ef83beb2f97c31ec6a97e19872fb89
Reviewed-on: https://go-review.googlesource.com/14043 Reviewed-by: Keith Randall <khr@golang.org>
David Chase [Fri, 28 Aug 2015 18:24:10 +0000 (14:24 -0400)]
[dev.ssa] cmd/compile: add complex arithmetic
Still to do:
details, more testing corner cases. (e.g. negative zero)
Includes small cleanups for previous CL.
Note: complex division is currently done in the runtime,
so the division code here is apparently not yet necessary
and also not tested. Seems likely better to open code
division and expose the widening/narrowing to optimization.
Complex64 multiplication and division is done in wide
format to avoid cancellation errors; for division, this
also happens to be compatible with pre-SSA practice
(which uses a single complex128 division function).
It would-be-nice to widen for complex128 multiplication
intermediates as well, but that is trickier to implement
without a handy wider-precision format.
Change-Id: I595a4300f68868fb7641852a54674c6b2b78855e
Reviewed-on: https://go-review.googlesource.com/14028 Reviewed-by: Keith Randall <khr@golang.org>
Keith Randall [Tue, 1 Sep 2015 16:16:58 +0000 (09:16 -0700)]
[dev.ssa] cmd/compile/internal/ssa: allow ops to have a default type
Specifying types in rewrites for all subexpressions gets verbose
quickly. Allow opcodes to specify a default type which is used when
none is supplied explicitly.
Provide default types for a few easy opcodes. There are probably more
we can do, but this is a good start.
Keith Randall [Fri, 28 Aug 2015 23:45:17 +0000 (16:45 -0700)]
[dev.ssa] cmd/compile/internal/ssa: handle dead code a different way
Instead of trying to delete dead code as soon as we find it, just
mark it as dead using a PlainAndDead block kind. The deadcode pass
will do the real removal.
This way is somewhat more efficient because we don't need to mess
with successor and predecessor lists of all the dead blocks.
The old backend doesn't like ideal types,
and we want to reuse its stackmap generation.
OOROR and OANDAND expressions have ideal type.
The old backend didn't care,
because those expressions got rewritten away into
jumps before stackmap generation.
Keith Randall [Tue, 25 Aug 2015 21:02:30 +0000 (14:02 -0700)]
[dev.ssa] cmd/compile/internal/ssa: add more critical edges
Add blocks to remove critical edges, even when it looks like
there's no phi that requires it. Regalloc still likes to have
critical-edge-free graphs for other reasons.
Ulrich Kunitz [Thu, 20 Aug 2015 16:56:18 +0000 (18:56 +0200)]
cmd/compile: fix register allocation for == operator
The issue 12226 has been caused by the allocation of the same register
for the equality check of two byte values. The code in cgen.go freed the
register for the second operand before the allocation of the register
for the first operand.
Keith Randall [Tue, 25 Aug 2015 06:52:03 +0000 (23:52 -0700)]
[dev.ssa] cmd/compile: implement OSLICESTR
Add a new function and generic operation to handle
bounds checking for slices. Unlike the index
bounds checking the index can be equal to the upper
bound.
Do gc-friendly slicing that generates proper code for
0-length result slices.
This is a takeover of Alexandru's original change,
(https://go-review.googlesource.com/#/c/12764/)
submittable now that the decompose phase is in.
Change-Id: I17d164cf42ed7839f84ca949c6ad3289269c9160
Reviewed-on: https://go-review.googlesource.com/13903 Reviewed-by: David Chase <drchase@google.com>
Austin Clements [Mon, 24 Aug 2015 17:35:49 +0000 (13:35 -0400)]
cmd/compile: fix uninitialized memory in compare of interface value
A comparison of the form l == r where l is an interface and r is
concrete performs a type assertion on l to convert it to r's type.
However, the compiler fails to zero the temporary where the result of
the type assertion is written, so if the type is a pointer type and a
stack scan occurs while in the type assertion, it may see an invalid
pointer on the stack.
Fix this by zeroing the temporary. This is equivalent to the fix for
type switches from c4092ac.
Keith Randall [Mon, 24 Aug 2015 04:14:25 +0000 (21:14 -0700)]
[dev.ssa] cmd/compile: make sure to keep offset and sym of MOV opcodes.
MOVXload and MOVXstore opcodes have both an auxint offset
and an aux offset (a symbol name, like a local or arg or global).
Make sure we keep those values during rewrites.
Shenghou Ma [Tue, 25 Aug 2015 01:24:23 +0000 (21:24 -0400)]
runtime: add a missing hex conversion
gobuf.g is a guintptr, so without hex(), it will be printed as
a decimal, which is not very helpful and inconsistent with how
other pointers are printed.
Change-Id: I7c0432e9709e90a5c3b3e22ce799551a6242d017
Reviewed-on: https://go-review.googlesource.com/13879 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Didier Spezia [Sun, 23 Aug 2015 13:59:00 +0000 (13:59 +0000)]
debug/elf: map/slice literals janitoring
Simplify slice/map literal expressions.
Caught with gofmt -d -s, fixed with gofmt -w -s
Reformatted some expressions to improve readability.
Change-Id: Iaf123e6bd49162ec45c59297ad3b002ca59443bc
Reviewed-on: https://go-review.googlesource.com/13850 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Shenghou Ma [Tue, 25 Aug 2015 01:17:04 +0000 (21:17 -0400)]
cmd/go: skip test using external linking on linux/ppc64 too
While we're at it, also fix a typo.
Change-Id: Id436f33cffa5683e2a8450cce5b545960cf2877e
Reviewed-on: https://go-review.googlesource.com/13878 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This aids in making sense of the aggregate set of work outstanding.
Interest in the details of any particular implementation failure
is better handled locally anyway.
In my local tree, running make.bash after this CL yields:
14.85% 1811 SSA unimplemented: unhandled expr SLICEARR
13.84% 1687 SSA unimplemented: unhandled expr CALLINTER
11.84% 1444 SSA unimplemented: unhandled stmt RETJMP
10.24% 1249 SSA unimplemented: unhandled expr EFACE
8.52% 1039 SSA unimplemented: unhandled expr SLICE
4.92% 600 SSA unimplemented: local variable with class PAUTO,heap unimplemented
4.90% 598 SSA unimplemented: unhandled expr SLICESTR
3.91% 477 SSA unimplemented: local variable with class PFUNC unimplemented
3.45% 421 SSA unimplemented: not lowered: IMake INTER PTR64 PTR64
3.42% 417 SSA unimplemented: unhandled expr APPEND
3.21% 391 SSA unimplemented: unhandled expr CLOSUREVAR
3.06% 373 SSA unimplemented: unhandled stmt DEFER
3.04% 371 SSA unimplemented: unhandled stmt AS2DOTTYPE
1.61% 196 SSA unimplemented: unhandled expr DOTTYPE
1.56% 190 SSA unimplemented: not lowered: Load STRUCT PTR64 mem
0.79% 96 SSA unimplemented: not lowered: StringMake STRING PTR64 UINTPTR
0.69% 84 SSA unimplemented: unhandled binary op NE FLOAT64
0.53% 65 SSA unimplemented: unhandled expr STRUCTLIT
0.50% 61 SSA unimplemented: not lowered: SliceMake ARRAY PTR64 UINTPTR UINTPTR
0.45% 55 SSA unimplemented: zero for type float64 not implemented
0.44% 54 SSA unimplemented: unhandled addr CLOSUREVAR
0.38% 46 SSA unimplemented: unhandled binary op EQ FLOAT64
0.35% 43 SSA unimplemented: unhandled binary op LT FLOAT64
0.34% 42 SSA unimplemented: unhandled len(map)
0.33% 40 SSA unimplemented: unhandled stmt FALL
0.23% 28 SSA unimplemented: CONVNOP closure
0.21% 25 SSA unimplemented: local variable with class PPARAM,heap unimplemented
0.21% 25 SSA unimplemented: unhandled binary op GT FLOAT64
0.18% 22 SSA unimplemented: unhandled OCONV FLOAT32 -> FLOAT64
0.18% 22 SSA unimplemented: unhandled expr REAL
0.16% 20 SSA unimplemented: unhandled stmt PROC
0.16% 19 SSA unimplemented: unhandled closure arg
0.15% 18 SSA unimplemented: unhandled OCONV INT64 -> FLOAT64
0.12% 15 SSA unimplemented: unhandled expr CFUNC
0.10% 12 SSA unimplemented: unhandled OCONV UINT64 -> FLOAT64
0.09% 11 SSA unimplemented: unhandled OLITERAL 4
0.09% 11 SSA unimplemented: unhandled expr IMAG
0.07% 9 SSA unimplemented: unhandled binary op GE FLOAT64
0.07% 9 SSA unimplemented: unhandled binary op MINUS FLOAT64
0.06% 7 SSA unimplemented: unhandled OCONV FLOAT64 -> FLOAT32
0.06% 7 SSA unimplemented: unhandled binary op NE FLOAT32
0.06% 7 SSA unimplemented: variable address class 5 not implemented
0.05% 6 SSA unimplemented: not lowered: Load COMPLEX128 PTR64 mem
0.05% 6 SSA unimplemented: unhandled expr SLICE3ARR
0.04% 5 SSA unimplemented: unhandled binary op LE FLOAT64
0.03% 4 SSA unimplemented: unhandled OCONV UINTPTR -> FLOAT64
0.03% 4 SSA unimplemented: unhandled binary op EQ COMPLEX128
0.03% 4 SSA unimplemented: unhandled binary op EQ FLOAT32
0.03% 4 SSA unimplemented: unhandled expr COMPLEX
0.02% 3 SSA unimplemented: local variable with class PPARAMOUT,heap unimplemented
0.02% 3 SSA unimplemented: not lowered: Load ARRAY PTR64 mem
0.02% 3 SSA unimplemented: unhandled OCONV INT32 -> FLOAT64
0.02% 3 SSA unimplemented: unhandled OCONV INT64 -> FLOAT32
0.02% 3 SSA unimplemented: unhandled expr SLICE3
0.02% 2 SSA unimplemented: unhandled OCONV COMPLEX64 -> COMPLEX128
0.02% 2 SSA unimplemented: unhandled OCONV FLOAT64 -> INT64
0.02% 2 SSA unimplemented: unhandled OCONV FLOAT64 -> UINT64
0.02% 2 SSA unimplemented: unhandled OCONV INT -> FLOAT64
0.02% 2 SSA unimplemented: unhandled OCONV UINT64 -> FLOAT32
0.02% 2 SSA unimplemented: unhandled binary op EQ COMPLEX64
0.02% 2 SSA unimplemented: unhandled binary op MINUS FLOAT32
0.02% 2 SSA unimplemented: zero for type complex128 not implemented
0.02% 2 SSA unimplemented: zero for type complex64 not implemented
0.02% 2 SSA unimplemented: zero for type float32 not implemented
0.01% 1 SSA unimplemented: not lowered: EqFat BOOL INTER INTER
0.01% 1 SSA unimplemented: not lowered: Store mem UINTPTR COMPLEX128 mem
0.01% 1 SSA unimplemented: unhandled OCONV UINT32 -> FLOAT64
0.01% 1 SSA unimplemented: unhandled cap(chan)
0.01% 1 SSA unimplemented: unhandled expr ARRAYLIT
0.01% 1 SSA unimplemented: unhandled expr PLUS
0.01% 1 SSA unimplemented: unhandled stmt CHECKNIL
Change-Id: I43474fe6d6ec22a9f57239090136f6e97eebfdf2
Reviewed-on: https://go-review.googlesource.com/13848 Reviewed-by: Keith Randall <khr@golang.org>
[dev.ssa] cmd/compile: support spilling and loading flags
This CL takes a simple approach to spilling and loading flags.
We never spill. When a load is needed, we recalculate,
loading the arguments as needed.
This is simple and architecture-independent.
It is not very efficient, but as of this CL,
there are fewer than 200 flag spills during make.bash.
This was tested by manually reverting CLs 13813 and 13843,
causing SETcc, MOV, and LEA instructions to clobber flags,
which dramatically increases the number of flags spills.
With that done, all stdlib tests that used to pass
still pass.
For future reference, here are some other, more efficient
amd64-only schemes that we could adapt in the future if needed.
(1) Spill exactly the flags needed.
For example, if we know that the flags will be needed
by a SETcc or Jcc op later, we could use SETcc to
extract just the relevant flag. When needed,
we could use TESTB and change the op to JNE/SETNE.
(Alternatively, we could leave the op unaltered
and prepare an appropriate CMPB instruction
to produce the desired flag.)
However, this requires separate handling for every
instruction that uses the flags register,
including (say) SBBQcarrymask.
We could enable this on an ad hoc basis for common cases
and fall back to recalculation for other cases.
(2) Spill all flags with PUSHF and POPF
This modifies SP, which the runtime won't like.
It also requires coordination with stackalloc to
make sure that we have a stack slot ready for use.
(3) Spill almost all flags with LAHF, SETO, and SAHF
See http://blog.freearrow.com/archives/396
for details. This would handle all the flags we currently
use. However, LAHF and SAHF are not universally available
and it requires arranging for AX to be free.
Change-Id: Ie36600fd8e807ef2bee83e2e2ae3685112a7f276
Reviewed-on: https://go-review.googlesource.com/13844 Reviewed-by: Keith Randall <khr@golang.org>
Ingo Oeser [Sat, 9 May 2015 15:55:05 +0000 (17:55 +0200)]
html: speed up UnescapeString
Add benchmarks for for sparsely escaped and densely escaped strings.
Then speed up the sparse unescaping part heavily by using IndexByte and
copy to skip the parts containing no escaping very fast.
Unescaping densely escaped strings slower because of
the new function call overhead. But sparsely encoded strings are seen
more often in the utf8 enabled web.
We win part of the speed back by looking up entityName differently.
Justin Nuß [Sun, 31 May 2015 11:17:59 +0000 (13:17 +0200)]
time: Use AppendFormat in Marshal[Text|JSON]
The current implementations of MarshalJSON and MarshalText use
time.Format which returns a string (converted from a byte slice),
only to convert it back to a byte slice.
Avoid the conversion (and thus an allocation) by directly appending
the formatted time to a preallocated byte slice, using the new
AppendFormat function, introduced in golang.org/cl/1760.
This reduces the allocations done in Marshal[Text|JSON] by 50%.
benchmark old ns/op new ns/op delta
BenchmarkMarshalJSON 626 507 -19.01%
BenchmarkMarshalText 598 511 -14.55%
benchmark old allocs new allocs delta
BenchmarkMarshalJSON 2 1 -50.00%
BenchmarkMarshalText 2 1 -50.00%
benchmark old bytes new bytes delta
BenchmarkMarshalJSON 96 48 -50.00%
BenchmarkMarshalText 96 48 -50.00%
This updates the big package used by the compiler to match the
public big package which contains some updates and bug fixes.
Obtained by running vendor.bash in the internal/big directory.
No manual changes.
Change-Id: I299aecc6599d4a745a721ce48def32449640dbb2
Reviewed-on: https://go-review.googlesource.com/13815 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Robert Griesemer [Fri, 21 Aug 2015 18:30:19 +0000 (11:30 -0700)]
math/big: fix TestBytes test
Fixes #12231.
Change-Id: I1f07c444623cd864667e21b2fee534eacdc193bb
Reviewed-on: https://go-review.googlesource.com/13814 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Alberto Donizetti [Fri, 21 Aug 2015 17:17:18 +0000 (19:17 +0200)]
math/big: correctly handle large exponent in SetString
Even though the umul/uquo functions expect two valid, finite big.Floats
arguments, SetString was calling them with possibly Inf values, which
resulted in bogus return values.
Replace umul and udiv calls with Mul and Quo calls to fix this. Also,
fix two wrong tests.
See relevant issue on issue tracker for a detailed explanation.
Fixes #11341
Change-Id: Ie35222763a57a2d712a5f5f7baec75cab8189a53
Reviewed-on: https://go-review.googlesource.com/13778 Reviewed-by: Robert Griesemer <gri@golang.org>
Hyang-Ah (Hana) Kim [Thu, 13 Aug 2015 13:05:22 +0000 (09:05 -0400)]
runtime/cgo: remove __stack_chk_fail_local
I cannot find where it's being used.
This addresses a duplicate symbol issue encountered in golang/go#9327.
Change-Id: I8efda45a006ad3e19423748210c78bd5831215e0
Reviewed-on: https://go-review.googlesource.com/13615 Reviewed-by: Ian Lance Taylor <iant@golang.org>
runtime, syscall: remove unused bits from Solaris implementation
CL 9184 changed the runtime and syscall packages to link Solaris binaries
directly instead of using dlopen/dlsym but did not remove the unused (and
now broken) references to dlopen, dlclose, and dlsym.
Dominik Honnef [Sun, 21 Jun 2015 18:07:29 +0000 (20:07 +0200)]
os/user: don't depend on _SC_GETPW_R_SIZE_MAX on Linux
Even Linux systems may not have _SC_GETPW_R_SIZE_MAX if using a
different libc than glibc (e.g. musl). Instead of having special-cases
for the BSDs, handle -1 correctly by always using a default buffer size.
Keith Randall [Tue, 18 Aug 2015 17:26:28 +0000 (10:26 -0700)]
[dev.ssa] cmd/compile: add decompose pass
Decompose breaks compound objects up into pieces that can be
operated on by the target architecture. The decompose pass only
does phi ops, the rest is done by the rewrite rules in generic.rules.
Compound objects include strings,slices,interfaces,structs,arrays.
Arrays aren't decomposed because of indexing (we could support
constant indexes, but dynamic indexes can't be handled using SSA).
Structs will come in a subsequent CL.
TODO: after this pass we have lost the association between, e.g.,
a string's pointer and its size. It would be nice if we could keep
that information around for debugging info somehow.
Keith Randall [Tue, 18 Aug 2015 21:17:30 +0000 (14:17 -0700)]
[dev.ssa] cmd/compile: used Bounded field to fix empty range loops
for i, v := range a {
}
Walk converts this to a regular for loop, like this:
for i := 0, p := &a[0]; i < len(a); i++, p++ {
v := *p
}
Unfortunately, &a[0] fails its bounds check when a is
the empty slice (or string). The old compiler gets around this
by marking &a[0] as Bounded, meaning "don't emit bounds checks
for this index op". This change makes SSA honor that same mark.
The SSA compiler hasn't implemented bounds check panics yet,
so the failed bounds check just causes the current routine
to return immediately.
Russ Cox [Wed, 19 Aug 2015 02:50:12 +0000 (22:50 -0400)]
net: respect go vs cgo resolver selection in all lookup routines
This is especially important for LookupAddr, which used to be pure Go
(lightweight, one goroutine per call) and without this CL is now
unconditionally cgo (heavy, one thread per call).
Russ Cox [Wed, 19 Aug 2015 02:19:58 +0000 (22:19 -0400)]
net: force LookupAddr results to be rooted DNS paths when using cgo
Go 1.4 and before have always returned DNS names with a trailing dot
for reverse lookups, as they do for basically all other routines returning
DNS names. Go 1.4 and before always implemented LookupAddr using
pure Go (not C library calls).
Go 1.5 added the ability to make a C library call to implement LookupAddr.
Unfortunately the C library call returns a DNS name without a trailing dot
(an unrooted name), meaning that if turn off cgo during make.bash then
you still get the rooted name but with cgo on you get an unrooted name.
The unrooted name is inconsistent with the pure Go implementation
and with all previous Go releases, so change it to a rooted name.
Fixes #12189.
Change-Id: I3d6b72277c121fe085ea6af30e5fe8019fc490ad
Reviewed-on: https://go-review.googlesource.com/13697 Reviewed-by: Rob Pike <r@golang.org>