]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize 386's assembly generator
authorBen Shi <powerman1st@163.com>
Thu, 20 Sep 2018 01:26:17 +0000 (01:26 +0000)
committerBen Shi <powerman1st@163.com>
Thu, 20 Sep 2018 06:33:58 +0000 (06:33 +0000)
The ADDconstmodify has similar logic with other constmodify like
instructions. This CL optimize them to share code via fallthrough.
And the size of pkg/linux_386/cmd/compile/internal/x86.a decreases
about 0.3KB.

Change-Id: Ibdf06228afde875e8fe8e30851b50ca2be513dd9
Reviewed-on: https://go-review.googlesource.com/136398
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/x86/ssa.go

index a53b63ab92e2d68cb95de129873c8101ecc496e4..e0bb4418ecac47f858bfe61143060d9732b82430 100644 (file)
@@ -547,22 +547,22 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.To.Reg = v.Args[0].Reg()
                gc.AddAux(&p.To, v)
        case ssa.Op386ADDLconstmodify:
-               var p *obj.Prog = nil
                sc := v.AuxValAndOff()
-               off := sc.Off()
                val := sc.Val()
-               if val == 1 {
-                       p = s.Prog(x86.AINCL)
-               } else if val == -1 {
-                       p = s.Prog(x86.ADECL)
-               } else {
-                       p = s.Prog(v.Op.Asm())
-                       p.From.Type = obj.TYPE_CONST
-                       p.From.Offset = val
+               if val == 1 || val == -1 {
+                       var p *obj.Prog
+                       if val == 1 {
+                               p = s.Prog(x86.AINCL)
+                       } else {
+                               p = s.Prog(x86.ADECL)
+                       }
+                       off := sc.Off()
+                       p.To.Type = obj.TYPE_MEM
+                       p.To.Reg = v.Args[0].Reg()
+                       gc.AddAux2(&p.To, v, off)
+                       break
                }
-               p.To.Type = obj.TYPE_MEM
-               p.To.Reg = v.Args[0].Reg()
-               gc.AddAux2(&p.To, v, off)
+               fallthrough
        case ssa.Op386ANDLconstmodify, ssa.Op386ORLconstmodify, ssa.Op386XORLconstmodify:
                sc := v.AuxValAndOff()
                off := sc.Off()