From 666c9aedd40853e2fc84bbd743b13cb267007ac2 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Thu, 30 Apr 2020 11:04:02 +0200 Subject: [PATCH] cmd/compile: switch to typed auxint for arm64 TBZ/TBNZ block This CL changes the arm64 TBZ/TBNZ block from using Aux to using a (typed) AuxInt. The corresponding rules have also been changed to be typed. Passes GOARCH=arm64 gotip build -toolexec 'toolstash -cmp' -a std Change-Id: I98d0cd2a791948f1db13259c17fb1b9b2807a043 Reviewed-on: https://go-review.googlesource.com/c/go/+/230839 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/arm64/ssa.go | 2 +- src/cmd/compile/internal/ssa/gen/ARM64.rules | 24 +++---- src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 12 ++-- src/cmd/compile/internal/ssa/gen/rulegen.go | 2 + src/cmd/compile/internal/ssa/opGen.go | 4 ++ src/cmd/compile/internal/ssa/rewrite.go | 1 - src/cmd/compile/internal/ssa/rewriteARM64.go | 72 ++++++++++---------- 7 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index e7d0f83d82b85b..06c520d76ab2c3 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -1083,7 +1083,7 @@ func ssaGenBlock(s *gc.SSAGenState, b, next *ssa.Block) { s.Br(obj.AJMP, b.Succs[0].Block()) } } - p.From.Offset = b.Aux.(int64) + p.From.Offset = b.AuxInt p.From.Type = obj.TYPE_CONST p.Reg = b.Controls[0].Reg() diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index dd644341de60ab..926a87f69dbe41 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -672,20 +672,20 @@ (GT (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 => (GT (CMPW a (MULW x y)) yes no) // Absorb bit-tests into block -(Z (ANDconst [c] x) yes no) && oneBit(c) -> (TBZ {int64(ntz64(c))} x yes no) -(NZ (ANDconst [c] x) yes no) && oneBit(c) -> (TBNZ {int64(ntz64(c))} x yes no) -(ZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) -> (TBZ {int64(ntz64(int64(uint32(c))))} x yes no) -(NZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) -> (TBNZ {int64(ntz64(int64(uint32(c))))} x yes no) -(EQ (TSTconst [c] x) yes no) && oneBit(c) -> (TBZ {int64(ntz64(c))} x yes no) -(NE (TSTconst [c] x) yes no) && oneBit(c) -> (TBNZ {int64(ntz64(c))} x yes no) -(EQ (TSTWconst [c] x) yes no) && oneBit(int64(uint32(c))) -> (TBZ {int64(ntz64(int64(uint32(c))))} x yes no) -(NE (TSTWconst [c] x) yes no) && oneBit(int64(uint32(c))) -> (TBNZ {int64(ntz64(int64(uint32(c))))} x yes no) +(Z (ANDconst [c] x) yes no) && oneBit(c) => (TBZ [int64(ntz64(c))] x yes no) +(NZ (ANDconst [c] x) yes no) && oneBit(c) => (TBNZ [int64(ntz64(c))] x yes no) +(ZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBZ [int64(ntz64(int64(uint32(c))))] x yes no) +(NZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBNZ [int64(ntz64(int64(uint32(c))))] x yes no) +(EQ (TSTconst [c] x) yes no) && oneBit(c) => (TBZ [int64(ntz64(c))] x yes no) +(NE (TSTconst [c] x) yes no) && oneBit(c) => (TBNZ [int64(ntz64(c))] x yes no) +(EQ (TSTWconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBZ [int64(ntz64(int64(uint32(c))))] x yes no) +(NE (TSTWconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBNZ [int64(ntz64(int64(uint32(c))))] x yes no) // Test sign-bit for signed comparisons against zero -(GE (CMPWconst [0] x) yes no) -> (TBZ {int64(31)} x yes no) -(GE (CMPconst [0] x) yes no) -> (TBZ {int64(63)} x yes no) -(LT (CMPWconst [0] x) yes no) -> (TBNZ {int64(31)} x yes no) -(LT (CMPconst [0] x) yes no) -> (TBNZ {int64(63)} x yes no) +(GE (CMPWconst [0] x) yes no) => (TBZ [31] x yes no) +(GE (CMPconst [0] x) yes no) => (TBZ [63] x yes no) +(LT (CMPWconst [0] x) yes no) => (TBNZ [31] x yes no) +(LT (CMPconst [0] x) yes no) => (TBNZ [63] x yes no) // fold offset into address (ADDconst [off1] (MOVDaddr [off2] {sym} ptr)) -> (MOVDaddr [off1+off2] {sym} ptr) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index c74d5590e706a5..964a25b052c0b6 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -691,12 +691,12 @@ func init() { {name: "ULE", controls: 1}, {name: "UGT", controls: 1}, {name: "UGE", controls: 1}, - {name: "Z", controls: 1}, // Control == 0 (take a register instead of flags) - {name: "NZ", controls: 1}, // Control != 0 - {name: "ZW", controls: 1}, // Control == 0, 32-bit - {name: "NZW", controls: 1}, // Control != 0, 32-bit - {name: "TBZ", controls: 1}, // Control & (1 << Aux.(int64)) == 0 - {name: "TBNZ", controls: 1}, // Control & (1 << Aux.(int64)) != 0 + {name: "Z", controls: 1}, // Control == 0 (take a register instead of flags) + {name: "NZ", controls: 1}, // Control != 0 + {name: "ZW", controls: 1}, // Control == 0, 32-bit + {name: "NZW", controls: 1}, // Control != 0, 32-bit + {name: "TBZ", controls: 1, aux: "Int64"}, // Control & (1 << AuxInt) == 0 + {name: "TBNZ", controls: 1, aux: "Int64"}, // Control & (1 << AuxInt) != 0 {name: "FLT", controls: 1}, {name: "FLE", controls: 1}, {name: "FGT", controls: 1}, diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index 1b2d86f4d574a5..0deae280b788cf 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -1842,6 +1842,8 @@ func (b blockData) auxIntType() string { return "int8" case "S390XCCMaskUint8": return "uint8" + case "Int64": + return "int64" default: return "invalid" } diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 3185f34fa54882..d619f36cf571ca 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -277,6 +277,10 @@ var blockString = [...]string{ func (k BlockKind) String() string { return blockString[k] } func (k BlockKind) AuxIntType() string { switch k { + case BlockARM64TBZ: + return "int64" + case BlockARM64TBNZ: + return "int64" case BlockS390XCIJ: return "int8" case BlockS390XCGIJ: diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index d5ed11d80298b4..d97497e24f4100 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -687,7 +687,6 @@ func s390xCCMaskToAux(c s390x.CCMask) interface{} { func s390xRotateParamsToAux(r s390x.RotateParams) interface{} { return r } - func cCopToAux(o Op) interface{} { return o } diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index d6cfb0eea4f6d5..e820c2438ce0ab 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -26071,30 +26071,30 @@ func rewriteBlockARM64(b *Block) bool { } // match: (EQ (TSTconst [c] x) yes no) // cond: oneBit(c) - // result: (TBZ {int64(ntz64(c))} x yes no) + // result: (TBZ [int64(ntz64(c))] x yes no) for b.Controls[0].Op == OpARM64TSTconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt64(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(c)) { break } b.resetWithControl(BlockARM64TBZ, x) - b.Aux = int64(ntz64(c)) + b.AuxInt = int64ToAuxInt(int64(ntz64(c))) return true } // match: (EQ (TSTWconst [c] x) yes no) // cond: oneBit(int64(uint32(c))) - // result: (TBZ {int64(ntz64(int64(uint32(c))))} x yes no) + // result: (TBZ [int64(ntz64(int64(uint32(c))))] x yes no) for b.Controls[0].Op == OpARM64TSTWconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt32(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(int64(uint32(c)))) { break } b.resetWithControl(BlockARM64TBZ, x) - b.Aux = int64(ntz64(int64(uint32(c)))) + b.AuxInt = int64ToAuxInt(int64(ntz64(int64(uint32(c))))) return true } // match: (EQ (FlagEQ) yes no) @@ -26521,27 +26521,27 @@ func rewriteBlockARM64(b *Block) bool { return true } // match: (GE (CMPWconst [0] x) yes no) - // result: (TBZ {int64(31)} x yes no) + // result: (TBZ [31] x yes no) for b.Controls[0].Op == OpARM64CMPWconst { v_0 := b.Controls[0] - if v_0.AuxInt != 0 { + if auxIntToInt32(v_0.AuxInt) != 0 { break } x := v_0.Args[0] b.resetWithControl(BlockARM64TBZ, x) - b.Aux = int64(31) + b.AuxInt = int64ToAuxInt(31) return true } // match: (GE (CMPconst [0] x) yes no) - // result: (TBZ {int64(63)} x yes no) + // result: (TBZ [63] x yes no) for b.Controls[0].Op == OpARM64CMPconst { v_0 := b.Controls[0] - if v_0.AuxInt != 0 { + if auxIntToInt64(v_0.AuxInt) != 0 { break } x := v_0.Args[0] b.resetWithControl(BlockARM64TBZ, x) - b.Aux = int64(63) + b.AuxInt = int64ToAuxInt(63) return true } // match: (GE (FlagEQ) yes no) @@ -27821,27 +27821,27 @@ func rewriteBlockARM64(b *Block) bool { return true } // match: (LT (CMPWconst [0] x) yes no) - // result: (TBNZ {int64(31)} x yes no) + // result: (TBNZ [31] x yes no) for b.Controls[0].Op == OpARM64CMPWconst { v_0 := b.Controls[0] - if v_0.AuxInt != 0 { + if auxIntToInt32(v_0.AuxInt) != 0 { break } x := v_0.Args[0] b.resetWithControl(BlockARM64TBNZ, x) - b.Aux = int64(31) + b.AuxInt = int64ToAuxInt(31) return true } // match: (LT (CMPconst [0] x) yes no) - // result: (TBNZ {int64(63)} x yes no) + // result: (TBNZ [63] x yes no) for b.Controls[0].Op == OpARM64CMPconst { v_0 := b.Controls[0] - if v_0.AuxInt != 0 { + if auxIntToInt64(v_0.AuxInt) != 0 { break } x := v_0.Args[0] b.resetWithControl(BlockARM64TBNZ, x) - b.Aux = int64(63) + b.AuxInt = int64ToAuxInt(63) return true } // match: (LT (FlagEQ) yes no) @@ -28254,30 +28254,30 @@ func rewriteBlockARM64(b *Block) bool { } // match: (NE (TSTconst [c] x) yes no) // cond: oneBit(c) - // result: (TBNZ {int64(ntz64(c))} x yes no) + // result: (TBNZ [int64(ntz64(c))] x yes no) for b.Controls[0].Op == OpARM64TSTconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt64(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(c)) { break } b.resetWithControl(BlockARM64TBNZ, x) - b.Aux = int64(ntz64(c)) + b.AuxInt = int64ToAuxInt(int64(ntz64(c))) return true } // match: (NE (TSTWconst [c] x) yes no) // cond: oneBit(int64(uint32(c))) - // result: (TBNZ {int64(ntz64(int64(uint32(c))))} x yes no) + // result: (TBNZ [int64(ntz64(int64(uint32(c))))] x yes no) for b.Controls[0].Op == OpARM64TSTWconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt32(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(int64(uint32(c)))) { break } b.resetWithControl(BlockARM64TBNZ, x) - b.Aux = int64(ntz64(int64(uint32(c)))) + b.AuxInt = int64ToAuxInt(int64(ntz64(int64(uint32(c))))) return true } // match: (NE (FlagEQ) yes no) @@ -28434,16 +28434,16 @@ func rewriteBlockARM64(b *Block) bool { } // match: (NZ (ANDconst [c] x) yes no) // cond: oneBit(c) - // result: (TBNZ {int64(ntz64(c))} x yes no) + // result: (TBNZ [int64(ntz64(c))] x yes no) for b.Controls[0].Op == OpARM64ANDconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt64(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(c)) { break } b.resetWithControl(BlockARM64TBNZ, x) - b.Aux = int64(ntz64(c)) + b.AuxInt = int64ToAuxInt(int64(ntz64(c))) return true } // match: (NZ (MOVDconst [0]) yes no) @@ -28472,16 +28472,16 @@ func rewriteBlockARM64(b *Block) bool { case BlockARM64NZW: // match: (NZW (ANDconst [c] x) yes no) // cond: oneBit(int64(uint32(c))) - // result: (TBNZ {int64(ntz64(int64(uint32(c))))} x yes no) + // result: (TBNZ [int64(ntz64(int64(uint32(c))))] x yes no) for b.Controls[0].Op == OpARM64ANDconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt64(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(int64(uint32(c)))) { break } b.resetWithControl(BlockARM64TBNZ, x) - b.Aux = int64(ntz64(int64(uint32(c)))) + b.AuxInt = int64ToAuxInt(int64(ntz64(int64(uint32(c))))) return true } // match: (NZW (MOVDconst [c]) yes no) @@ -28678,16 +28678,16 @@ func rewriteBlockARM64(b *Block) bool { case BlockARM64Z: // match: (Z (ANDconst [c] x) yes no) // cond: oneBit(c) - // result: (TBZ {int64(ntz64(c))} x yes no) + // result: (TBZ [int64(ntz64(c))] x yes no) for b.Controls[0].Op == OpARM64ANDconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt64(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(c)) { break } b.resetWithControl(BlockARM64TBZ, x) - b.Aux = int64(ntz64(c)) + b.AuxInt = int64ToAuxInt(int64(ntz64(c))) return true } // match: (Z (MOVDconst [0]) yes no) @@ -28716,16 +28716,16 @@ func rewriteBlockARM64(b *Block) bool { case BlockARM64ZW: // match: (ZW (ANDconst [c] x) yes no) // cond: oneBit(int64(uint32(c))) - // result: (TBZ {int64(ntz64(int64(uint32(c))))} x yes no) + // result: (TBZ [int64(ntz64(int64(uint32(c))))] x yes no) for b.Controls[0].Op == OpARM64ANDconst { v_0 := b.Controls[0] - c := v_0.AuxInt + c := auxIntToInt64(v_0.AuxInt) x := v_0.Args[0] if !(oneBit(int64(uint32(c)))) { break } b.resetWithControl(BlockARM64TBZ, x) - b.Aux = int64(ntz64(int64(uint32(c)))) + b.AuxInt = int64ToAuxInt(int64(ntz64(int64(uint32(c))))) return true } // match: (ZW (MOVDconst [c]) yes no)