]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove a false dependency for TZCNT
authornimelehin <nimelehin@gmail.com>
Mon, 6 Dec 2021 15:46:25 +0000 (18:46 +0300)
committerKeith Randall <khr@golang.org>
Thu, 31 Mar 2022 19:39:37 +0000 (19:39 +0000)
LZCNT/TZCNT on some Intel CPUs suffer from a false dependency on
the destination register.

The problem was mentioned in the GCC Ticket: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62011#c7
and fixed with https://gcc.gnu.org/viewcvs?rev=214112&root=gcc&view=rev

Change-Id: I8109e84f03ac85f221b06d3b913612b58320d151
Reviewed-on: https://go-review.googlesource.com/c/go/+/369019
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Alex Rakoczy <alex@golang.org>
Run-TryBot: Alex Rakoczy <alex@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/amd64/ssa.go

index b0e5c34030f32b9d6b62159a7fef03e4dc3a5e80..8ec54a8b03762a99c68f9f4a6672c5935807489f 100644 (file)
@@ -265,8 +265,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
 
        case ssa.OpAMD64BLSIQ, ssa.OpAMD64BLSIL,
                ssa.OpAMD64BLSMSKQ, ssa.OpAMD64BLSMSKL,
-               ssa.OpAMD64BLSRQ, ssa.OpAMD64BLSRL,
-               ssa.OpAMD64TZCNTQ, ssa.OpAMD64TZCNTL:
+               ssa.OpAMD64BLSRQ, ssa.OpAMD64BLSRL:
                p := s.Prog(v.Op.Asm())
                p.From.Type = obj.TYPE_REG
                p.From.Reg = v.Args[0].Reg()
@@ -1137,9 +1136,11 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
                p.SetFrom3Reg(v.Args[0].Reg())
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpAMD64POPCNTQ, ssa.OpAMD64POPCNTL:
+       case ssa.OpAMD64POPCNTQ, ssa.OpAMD64POPCNTL,
+               ssa.OpAMD64TZCNTQ, ssa.OpAMD64TZCNTL:
                if v.Args[0].Reg() != v.Reg() {
-                       // POPCNT on Intel has a false dependency on the destination register.
+                       // POPCNT/TZCNT/LZCNT have a false dependency on the destination register on Intel cpus.
+                       // TZCNT/LZCNT problem affects pre-Skylake models. See discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62011#c7.
                        // Xor register with itself to break the dependency.
                        p := s.Prog(x86.AXORL)
                        p.From.Type = obj.TYPE_REG