diff options
author | Michael Munday <mike.munday@ibm.com> | 2019-09-17 07:29:31 -0700 |
---|---|---|
committer | Michael Munday <mike.munday@ibm.com> | 2019-10-08 10:03:04 +0000 |
commit | 6ec4c71eef730d56169255515fea3490c8a32650 (patch) | |
tree | f458a868bc4cbbc0f48c5cf2d4d93d7d2dd887c5 /src/cmd/compile/internal/s390x | |
parent | 77f5adba554c80dc536f3076b2fa882d2cf0e992 (diff) | |
download | go-6ec4c71eef730d56169255515fea3490c8a32650.tar.gz go-6ec4c71eef730d56169255515fea3490c8a32650.zip |
cmd/compile: add SSA rules for s390x compare-and-branch instructions
This commit adds SSA rules for the s390x combined compare-and-branch
instructions. These have a shorter encoding than separate compare
and branch instructions and they also don't clobber the condition
code (a.k.a. flag register) reducing pressure on the flag allocator.
I have deleted the 'loop_test.go' file and replaced it with a new
codegen test which performs a wider range of checks.
Object sizes from compilebench:
name old object-bytes new object-bytes delta
Template 562kB ± 0% 561kB ± 0% -0.28% (p=0.000 n=10+10)
Unicode 217kB ± 0% 217kB ± 0% -0.17% (p=0.000 n=10+10)
GoTypes 2.03MB ± 0% 2.02MB ± 0% -0.59% (p=0.000 n=10+10)
Compiler 8.16MB ± 0% 8.11MB ± 0% -0.62% (p=0.000 n=10+10)
SSA 27.4MB ± 0% 27.0MB ± 0% -1.45% (p=0.000 n=10+10)
Flate 356kB ± 0% 356kB ± 0% -0.12% (p=0.000 n=10+10)
GoParser 438kB ± 0% 436kB ± 0% -0.51% (p=0.000 n=10+10)
Reflect 1.37MB ± 0% 1.37MB ± 0% -0.42% (p=0.000 n=10+10)
Tar 485kB ± 0% 483kB ± 0% -0.39% (p=0.000 n=10+10)
XML 630kB ± 0% 621kB ± 0% -1.45% (p=0.000 n=10+10)
[Geo mean] 1.14MB 1.13MB -0.60%
name old text-bytes new text-bytes delta
HelloSize 763kB ± 0% 754kB ± 0% -1.30% (p=0.000 n=10+10)
CmdGoSize 10.7MB ± 0% 10.6MB ± 0% -0.91% (p=0.000 n=10+10)
[Geo mean] 2.86MB 2.82MB -1.10%
Change-Id: Ibca55d9c0aa1254aee69433731ab5d26a43a7c18
Reviewed-on: https://go-review.googlesource.com/c/go/+/198037
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/s390x')
-rw-r--r-- | src/cmd/compile/internal/s390x/ssa.go | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/src/cmd/compile/internal/s390x/ssa.go b/src/cmd/compile/internal/s390x/ssa.go index 15cb553eff..2be6c1ab94 100644 --- a/src/cmd/compile/internal/s390x/ssa.go +++ b/src/cmd/compile/internal/s390x/ssa.go @@ -814,7 +814,33 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { } } +func blockAsm(b *ssa.Block) obj.As { + switch b.Kind { + case ssa.BlockS390XBRC: + return s390x.ABRC + case ssa.BlockS390XCRJ: + return s390x.ACRJ + case ssa.BlockS390XCGRJ: + return s390x.ACGRJ + case ssa.BlockS390XCLRJ: + return s390x.ACLRJ + case ssa.BlockS390XCLGRJ: + return s390x.ACLGRJ + case ssa.BlockS390XCIJ: + return s390x.ACIJ + case ssa.BlockS390XCGIJ: + return s390x.ACGIJ + case ssa.BlockS390XCLIJ: + return s390x.ACLIJ + case ssa.BlockS390XCLGIJ: + return s390x.ACLGIJ + } + b.Fatalf("blockAsm not implemented: %s", b.LongString()) + panic("unreachable") +} + func ssaGenBlock(s *gc.SSAGenState, b, next *ssa.Block) { + // Handle generic blocks first. switch b.Kind { case ssa.BlockPlain: if b.Succs[0].Block() != next { @@ -822,47 +848,73 @@ func ssaGenBlock(s *gc.SSAGenState, b, next *ssa.Block) { p.To.Type = obj.TYPE_BRANCH s.Branches = append(s.Branches, gc.Branch{P: p, B: b.Succs[0].Block()}) } + return case ssa.BlockDefer: // defer returns in R3: // 0 if we should continue executing // 1 if we should jump to deferreturn call - p := s.Prog(s390x.ACMPW) - p.From.Type = obj.TYPE_REG - p.From.Reg = s390x.REG_R3 - p.To.Type = obj.TYPE_CONST - p.To.Offset = 0 - p = s.Prog(s390x.ABNE) - p.To.Type = obj.TYPE_BRANCH - s.Branches = append(s.Branches, gc.Branch{P: p, B: b.Succs[1].Block()}) + p := s.Br(s390x.ACIJ, b.Succs[1].Block()) + p.From.Type = obj.TYPE_CONST + p.From.Offset = int64(s390x.NotEqual & s390x.NotUnordered) // unordered is not possible + p.Reg = s390x.REG_R3 + p.RestArgs = []obj.Addr{{Type: obj.TYPE_CONST, Offset: 0}} if b.Succs[0].Block() != next { - p := s.Prog(s390x.ABR) - p.To.Type = obj.TYPE_BRANCH - s.Branches = append(s.Branches, gc.Branch{P: p, B: b.Succs[0].Block()}) + s.Br(s390x.ABR, b.Succs[0].Block()) } + return case ssa.BlockExit: + return case ssa.BlockRet: s.Prog(obj.ARET) + return case ssa.BlockRetJmp: p := s.Prog(s390x.ABR) p.To.Type = obj.TYPE_MEM p.To.Name = obj.NAME_EXTERN p.To.Sym = b.Aux.(*obj.LSym) + return + } + + // Handle s390x-specific blocks. These blocks all have a + // condition code mask in the Aux value and 2 successors. + succs := [...]*ssa.Block{b.Succs[0].Block(), b.Succs[1].Block()} + mask := b.Aux.(s390x.CCMask) + + // TODO: take into account Likely property for forward/backward + // branches. We currently can't do this because we don't know + // whether a block has already been emitted. In general forward + // branches are assumed 'not taken' and backward branches are + // assumed 'taken'. + if next == succs[0] { + succs[0], succs[1] = succs[1], succs[0] + mask = mask.Inverse() + } + + p := s.Br(blockAsm(b), succs[0]) + switch b.Kind { case ssa.BlockS390XBRC: - succs := [...]*ssa.Block{b.Succs[0].Block(), b.Succs[1].Block()} - mask := b.Aux.(s390x.CCMask) - if next == succs[0] { - succs[0], succs[1] = succs[1], succs[0] - mask = mask.Inverse() - } - // TODO: take into account Likely property for forward/backward - // branches. - p := s.Br(s390x.ABRC, succs[0]) p.From.Type = obj.TYPE_CONST p.From.Offset = int64(mask) - if next != succs[1] { - s.Br(s390x.ABR, succs[1]) - } + case ssa.BlockS390XCGRJ, ssa.BlockS390XCRJ, + ssa.BlockS390XCLGRJ, ssa.BlockS390XCLRJ: + p.From.Type = obj.TYPE_CONST + p.From.Offset = int64(mask & s390x.NotUnordered) // unordered is not possible + p.Reg = b.Controls[0].Reg() + p.RestArgs = []obj.Addr{{Type: obj.TYPE_REG, Reg: b.Controls[1].Reg()}} + case ssa.BlockS390XCGIJ, ssa.BlockS390XCIJ: + p.From.Type = obj.TYPE_CONST + p.From.Offset = int64(mask & s390x.NotUnordered) // unordered is not possible + p.Reg = b.Controls[0].Reg() + p.RestArgs = []obj.Addr{{Type: obj.TYPE_CONST, Offset: int64(int8(b.AuxInt))}} + case ssa.BlockS390XCLGIJ, ssa.BlockS390XCLIJ: + p.From.Type = obj.TYPE_CONST + p.From.Offset = int64(mask & s390x.NotUnordered) // unordered is not possible + p.Reg = b.Controls[0].Reg() + p.RestArgs = []obj.Addr{{Type: obj.TYPE_CONST, Offset: int64(uint8(b.AuxInt))}} default: b.Fatalf("branch not implemented: %s", b.LongString()) } + if next != succs[1] { + s.Br(s390x.ABR, succs[1]) + } } |