diff --git a/src/cmd/compile/internal/ssa/_gen/AMD64.rules b/src/cmd/compile/internal/ssa/_gen/AMD64.rules index 9177067e522206..e590b41d5f5a2d 100644 --- a/src/cmd/compile/internal/ssa/_gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/_gen/AMD64.rules @@ -628,6 +628,21 @@ // x & 1 == 0 -> (x & 1) ^ 1 (SETAE (BT(L|Q)const [0] x)) => (XORLconst [1] (ANDLconst [1] x)) +// Shorten compare by rewriting x < 128 as x <= 127, which can be encoded in a single-byte immediate on x86. +(SETL c:(CMP(Q|L)const [128] x)) && c.Uses == 1 => (SETLE (CMP(Q|L)const [127] x)) +(SETB c:(CMP(Q|L)const [128] x)) && c.Uses == 1 => (SETBE (CMP(Q|L)const [127] x)) + +// x >= 128 -> x > 127 +(SETGE c:(CMP(Q|L)const [128] x)) && c.Uses == 1 => (SETG (CMP(Q|L)const [127] x)) +(SETAE c:(CMP(Q|L)const [128] x)) && c.Uses == 1 => (SETA (CMP(Q|L)const [127] x)) + +(CMOVQLT x y c:(CMP(Q|L)const [128] z)) && c.Uses == 1 => (CMOVQLE x y (CMP(Q|L)const [127] z)) +(CMOVLLT x y c:(CMP(Q|L)const [128] z)) && c.Uses == 1 => (CMOVLLE x y (CMP(Q|L)const [127] z)) +(LT c:(CMP(Q|L)const [128] z) yes no) && c.Uses == 1 => (LE (CMP(Q|L)const [127] z) yes no) +(CMOVQGE x y c:(CMP(Q|L)const [128] z)) && c.Uses == 1 => (CMOVQGT x y (CMP(Q|L)const [127] z)) +(CMOVLGE x y c:(CMP(Q|L)const [128] z)) && c.Uses == 1 => (CMOVLGT x y (CMP(Q|L)const [127] z)) +(GE c:(CMP(Q|L)const [128] z) yes no) && c.Uses == 1 => (GT (CMP(Q|L)const [127] z) yes no) + // Recognize bit tests: a&(1<= 128 +} + +func ge128Unsigned64(x uint64) bool { + // amd64:`CMPQ.*127` + // amd64:`SETHI` + return x >= 128 +} + +func ge128Signed32(x int32) bool { + // amd64:`CMPL.*127` + // amd64:`SETGT` + return x >= 128 +} + +func ge128Signed64(x int64) bool { + // amd64:`CMPQ.*127` + // amd64:`SETGT` + return x >= 128 +} + func cmpToCmnGreaterThanEqual(a, b, c, d int) int { var c1, c2, c3, c4 int // arm64:`CMN`,`CSET\tPL`,-`CMP`