]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.14] cmd/internal/obj: stop removing NOPs from instruction stream
authorKeith Randall <khr@golang.org>
Sat, 15 Aug 2020 15:08:37 +0000 (08:08 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Thu, 3 Sep 2020 02:31:58 +0000 (02:31 +0000)
This has already been done for s390x, ppc64. This CL is for
all the other architectures.

Fixes #40797

Change-Id: Idd1816e057df63022d47e99fa06617811d8c8489
Reviewed-on: https://go-review.googlesource.com/c/go/+/248684
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
(cherry picked from commit 46ca7b5ee2a8582736f1ddac27d8660e1104c345)
Reviewed-on: https://go-review.googlesource.com/c/go/+/249443
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>

src/cmd/internal/obj/arm/asm5.go
src/cmd/internal/obj/arm/obj5.go
src/cmd/internal/obj/arm64/asm7.go
src/cmd/internal/obj/arm64/obj7.go
src/cmd/internal/obj/mips/asm0.go
src/cmd/internal/obj/mips/obj0.go

index bc55dac8784f790e3d22ea7f298c1043d58c3b86..bde643caae60677bbb3e49e7ab5a438aa9d13f09 100644 (file)
@@ -327,6 +327,9 @@ var optab = []Optab{
        {obj.APCDATA, C_LCON, C_NONE, C_LCON, 0, 0, 0, 0, 0, 0},
        {obj.AFUNCDATA, C_LCON, C_NONE, C_ADDR, 0, 0, 0, 0, 0, 0},
        {obj.ANOP, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0, 0},
+       {obj.ANOP, C_LCON, C_NONE, C_NONE, 0, 0, 0, 0, 0, 0}, // nop variants, see #40689
+       {obj.ANOP, C_REG, C_NONE, C_NONE, 0, 0, 0, 0, 0, 0},
+       {obj.ANOP, C_FREG, C_NONE, C_NONE, 0, 0, 0, 0, 0, 0},
        {obj.ADUFFZERO, C_NONE, C_NONE, C_SBRA, 5, 4, 0, 0, 0, 0}, // same as ABL
        {obj.ADUFFCOPY, C_NONE, C_NONE, C_SBRA, 5, 4, 0, 0, 0, 0}, // same as ABL
        {obj.AXXX, C_NONE, C_NONE, C_NONE, 0, 4, 0, 0, 0, 0},
index a895929b6246ecf01e99d7b46753c09b535aa4b6..60a3532200ae5bf9e7aa226de8871fc653e5984a 100644 (file)
@@ -276,67 +276,21 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
 
        /*
         * find leaf subroutines
-        * strip NOPs
-        * expand RET
-        * expand BECOME pseudo
         */
-       var q1 *obj.Prog
-       var q *obj.Prog
        for p := cursym.Func.Text; p != nil; p = p.Link {
                switch p.As {
                case obj.ATEXT:
                        p.Mark |= LEAF
 
-               case obj.ARET:
-                       break
-
                case ADIV, ADIVU, AMOD, AMODU:
-                       q = p
                        cursym.Func.Text.Mark &^= LEAF
-                       continue
-
-               case obj.ANOP:
-                       q1 = p.Link
-                       q.Link = q1 /* q is non-nop */
-                       if q1 != nil {
-                               q1.Mark |= p.Mark
-                       }
-                       continue
 
                case ABL,
                        ABX,
                        obj.ADUFFZERO,
                        obj.ADUFFCOPY:
                        cursym.Func.Text.Mark &^= LEAF
-                       fallthrough
-
-               case AB,
-                       ABEQ,
-                       ABNE,
-                       ABCS,
-                       ABHS,
-                       ABCC,
-                       ABLO,
-                       ABMI,
-                       ABPL,
-                       ABVS,
-                       ABVC,
-                       ABHI,
-                       ABLS,
-                       ABGE,
-                       ABLT,
-                       ABGT,
-                       ABLE:
-                       q1 = p.Pcond
-                       if q1 != nil {
-                               for q1.As == obj.ANOP {
-                                       q1 = q1.Link
-                                       p.Pcond = q1
-                               }
-                       }
                }
-
-               q = p
        }
 
        var q2 *obj.Prog
index 971e1bdd6491855f4af38a72997dedcbcad9472f..72fde5209609d92f210a87c3961f683eb9bb7a43 100644 (file)
@@ -838,6 +838,9 @@ var optab = []Optab{
        {obj.APCDATA, C_VCON, C_NONE, C_NONE, C_VCON, 0, 0, 0, 0, 0},
        {obj.AFUNCDATA, C_VCON, C_NONE, C_NONE, C_ADDR, 0, 0, 0, 0, 0},
        {obj.ANOP, C_NONE, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0},
+       {obj.ANOP, C_LCON, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0}, // nop variants, see #40689
+       {obj.ANOP, C_REG, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0},
+       {obj.ANOP, C_VREG, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0},
        {obj.ADUFFZERO, C_NONE, C_NONE, C_NONE, C_SBRA, 5, 4, 0, 0, 0}, // same as AB/ABL
        {obj.ADUFFCOPY, C_NONE, C_NONE, C_NONE, C_SBRA, 5, 4, 0, 0, 0}, // same as AB/ABL
 
index 09f603a05992f2d33c30f2f9411065ccffdc0371..c9b477466aa80a9f7ae216fb38a2f80cb461695c 100644 (file)
@@ -467,73 +467,21 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
 
        /*
         * find leaf subroutines
-        * strip NOPs
-        * expand RET
         */
-       q := (*obj.Prog)(nil)
-       var q1 *obj.Prog
        for p := c.cursym.Func.Text; p != nil; p = p.Link {
                switch p.As {
                case obj.ATEXT:
                        p.Mark |= LEAF
 
-               case obj.ARET:
-                       break
-
-               case obj.ANOP:
-                       if p.Link != nil {
-                               q1 = p.Link
-                               q.Link = q1 /* q is non-nop */
-                               q1.Mark |= p.Mark
-                       }
-                       continue
-
                case ABL,
                        obj.ADUFFZERO,
                        obj.ADUFFCOPY:
                        c.cursym.Func.Text.Mark &^= LEAF
-                       fallthrough
-
-               case ACBNZ,
-                       ACBZ,
-                       ACBNZW,
-                       ACBZW,
-                       ATBZ,
-                       ATBNZ,
-                       AB,
-                       ABEQ,
-                       ABNE,
-                       ABCS,
-                       ABHS,
-                       ABCC,
-                       ABLO,
-                       ABMI,
-                       ABPL,
-                       ABVS,
-                       ABVC,
-                       ABHI,
-                       ABLS,
-                       ABGE,
-                       ABLT,
-                       ABGT,
-                       ABLE,
-                       AADR, /* strange */
-                       AADRP:
-                       q1 = p.Pcond
-
-                       if q1 != nil {
-                               for q1.As == obj.ANOP {
-                                       q1 = q1.Link
-                                       p.Pcond = q1
-                               }
-                       }
-
-                       break
                }
-
-               q = p
        }
 
+       var q *obj.Prog
+       var q1 *obj.Prog
        var retjmp *obj.LSym
        for p := c.cursym.Func.Text; p != nil; p = p.Link {
                o := p.As
index 934f88a0b18203a8b9488d00703a19bba4a4a771..dfe86349a241451208d7f8402921325c9970b043 100644 (file)
@@ -386,6 +386,9 @@ var optab = []Optab{
        {obj.APCDATA, C_LCON, C_NONE, C_LCON, 0, 0, 0, 0, 0},
        {obj.AFUNCDATA, C_SCON, C_NONE, C_ADDR, 0, 0, 0, 0, 0},
        {obj.ANOP, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0},
+       {obj.ANOP, C_LCON, C_NONE, C_NONE, 0, 0, 0, 0, 0}, // nop variants, see #40689
+       {obj.ANOP, C_REG, C_NONE, C_NONE, 0, 0, 0, 0, 0},
+       {obj.ANOP, C_FREG, C_NONE, C_NONE, 0, 0, 0, 0, 0},
        {obj.ADUFFZERO, C_NONE, C_NONE, C_LBRA, 11, 4, 0, 0, 0}, // same as AJMP
        {obj.ADUFFCOPY, C_NONE, C_NONE, C_LBRA, 11, 4, 0, 0, 0}, // same as AJMP
 
index 31061438443be61e7bc4e825ad8412737ed2c314..77cad979a64dab4558b19035d9f524798a06c7f7 100644 (file)
@@ -158,19 +158,14 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
 
        /*
         * find leaf subroutines
-        * strip NOPs
         * expand RET
         * expand BECOME pseudo
         */
 
-       var q *obj.Prog
-       var q1 *obj.Prog
        for p := c.cursym.Func.Text; p != nil; p = p.Link {
                switch p.As {
                /* too hard, just leave alone */
                case obj.ATEXT:
-                       q = p
-
                        p.Mark |= LABEL | LEAF | SYNC
                        if p.Link != nil {
                                p.Link.Mark |= LABEL
@@ -179,7 +174,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                /* too hard, just leave alone */
                case AMOVW,
                        AMOVV:
-                       q = p
                        if p.To.Type == obj.TYPE_REG && p.To.Reg >= REG_SPECIAL {
                                p.Mark |= LABEL | SYNC
                                break
@@ -195,11 +189,9 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                        ATLBWI,
                        ATLBP,
                        ATLBR:
-                       q = p
                        p.Mark |= LABEL | SYNC
 
                case ANOR:
-                       q = p
                        if p.To.Type == obj.TYPE_REG {
                                if p.To.Reg == REGZERO {
                                        p.Mark |= LABEL | SYNC
@@ -235,8 +227,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                        } else {
                                p.Mark |= BRANCH
                        }
-                       q = p
-                       q1 = p.Pcond
+                       q1 := p.Pcond
                        if q1 != nil {
                                for q1.As == obj.ANOP {
                                        q1 = q1.Link
@@ -254,24 +245,11 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                        if q1 != nil {
                                q1.Mark |= LABEL
                        }
-                       continue
 
                case ARET:
-                       q = p
                        if p.Link != nil {
                                p.Link.Mark |= LABEL
                        }
-                       continue
-
-               case obj.ANOP:
-                       q1 = p.Link
-                       q.Link = q1 /* q is non-nop */
-                       q1.Mark |= p.Mark
-                       continue
-
-               default:
-                       q = p
-                       continue
                }
        }
 
@@ -284,6 +262,8 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                mov = AMOVW
        }
 
+       var q *obj.Prog
+       var q1 *obj.Prog
        autosize := int32(0)
        var p1 *obj.Prog
        var p2 *obj.Prog