1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:50:05 -07:00

cmd/compile: move some generic rules to strongly typed

Move a lot of the constant folding rules to use strongly
typed AuxInt fields.

We need more than a cast to convert AuxInt to, e.g., float32.
Make conversion functions for converting back and forth.

Change-Id: Ia3d95ee3583ee2179a10938e20210a7617358c88
Reviewed-on: https://go-review.googlesource.com/c/go/+/227866
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
Keith Randall 2020-04-10 21:38:49 -07:00
parent fd18f3ba50
commit a1b802bde7
5 changed files with 609 additions and 445 deletions

View File

@ -38,127 +38,128 @@
// For now, the generated successors must be a permutation of the matched successors. // For now, the generated successors must be a permutation of the matched successors.
// constant folding // constant folding
(Trunc16to8 (Const16 [c])) -> (Const8 [int64(int8(c))]) (Trunc16to8 (Const16 [c])) => (Const8 [int8(c)])
(Trunc32to8 (Const32 [c])) -> (Const8 [int64(int8(c))]) (Trunc32to8 (Const32 [c])) => (Const8 [int8(c)])
(Trunc32to16 (Const32 [c])) -> (Const16 [int64(int16(c))]) (Trunc32to16 (Const32 [c])) => (Const16 [int16(c)])
(Trunc64to8 (Const64 [c])) -> (Const8 [int64(int8(c))]) (Trunc64to8 (Const64 [c])) => (Const8 [int8(c)])
(Trunc64to16 (Const64 [c])) -> (Const16 [int64(int16(c))]) (Trunc64to16 (Const64 [c])) => (Const16 [int16(c)])
(Trunc64to32 (Const64 [c])) -> (Const32 [int64(int32(c))]) (Trunc64to32 (Const64 [c])) => (Const32 [int32(c)])
(Cvt64Fto32F (Const64F [c])) -> (Const32F [auxFrom32F(float32(auxTo64F(c)))]) (Cvt64Fto32F (Const64F [c])) => (Const32F [float32(c)])
(Cvt32Fto64F (Const32F [c])) -> (Const64F [c]) // c is already a 64 bit float (Cvt32Fto64F (Const32F [c])) => (Const64F [float64(c)])
(Cvt32to32F (Const32 [c])) -> (Const32F [auxFrom32F(float32(int32(c)))]) (Cvt32to32F (Const32 [c])) => (Const32F [float32(c)])
(Cvt32to64F (Const32 [c])) -> (Const64F [auxFrom64F(float64(int32(c)))]) (Cvt32to64F (Const32 [c])) => (Const64F [float64(c)])
(Cvt64to32F (Const64 [c])) -> (Const32F [auxFrom32F(float32(c))]) (Cvt64to32F (Const64 [c])) => (Const32F [float32(c)])
(Cvt64to64F (Const64 [c])) -> (Const64F [auxFrom64F(float64(c))]) (Cvt64to64F (Const64 [c])) => (Const64F [float64(c)])
(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(auxTo32F(c)))]) (Cvt32Fto32 (Const32F [c])) => (Const32 [int32(c)])
(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(auxTo32F(c))]) (Cvt32Fto64 (Const32F [c])) => (Const64 [int64(c)])
(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(auxTo64F(c)))]) (Cvt64Fto32 (Const64F [c])) => (Const32 [int32(c)])
(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(auxTo64F(c))]) (Cvt64Fto64 (Const64F [c])) => (Const64 [int64(c)])
(Round32F x:(Const32F)) -> x (Round32F x:(Const32F)) => x
(Round64F x:(Const64F)) -> x (Round64F x:(Const64F)) => x
(CvtBoolToUint8 (ConstBool [c])) -> (Const8 [c]) (CvtBoolToUint8 (ConstBool [false])) => (Const8 [0])
(CvtBoolToUint8 (ConstBool [true])) => (Const8 [1])
(Trunc16to8 (ZeroExt8to16 x)) -> x (Trunc16to8 (ZeroExt8to16 x)) => x
(Trunc32to8 (ZeroExt8to32 x)) -> x (Trunc32to8 (ZeroExt8to32 x)) => x
(Trunc32to16 (ZeroExt8to32 x)) -> (ZeroExt8to16 x) (Trunc32to16 (ZeroExt8to32 x)) => (ZeroExt8to16 x)
(Trunc32to16 (ZeroExt16to32 x)) -> x (Trunc32to16 (ZeroExt16to32 x)) => x
(Trunc64to8 (ZeroExt8to64 x)) -> x (Trunc64to8 (ZeroExt8to64 x)) => x
(Trunc64to16 (ZeroExt8to64 x)) -> (ZeroExt8to16 x) (Trunc64to16 (ZeroExt8to64 x)) => (ZeroExt8to16 x)
(Trunc64to16 (ZeroExt16to64 x)) -> x (Trunc64to16 (ZeroExt16to64 x)) => x
(Trunc64to32 (ZeroExt8to64 x)) -> (ZeroExt8to32 x) (Trunc64to32 (ZeroExt8to64 x)) => (ZeroExt8to32 x)
(Trunc64to32 (ZeroExt16to64 x)) -> (ZeroExt16to32 x) (Trunc64to32 (ZeroExt16to64 x)) => (ZeroExt16to32 x)
(Trunc64to32 (ZeroExt32to64 x)) -> x (Trunc64to32 (ZeroExt32to64 x)) => x
(Trunc16to8 (SignExt8to16 x)) -> x (Trunc16to8 (SignExt8to16 x)) => x
(Trunc32to8 (SignExt8to32 x)) -> x (Trunc32to8 (SignExt8to32 x)) => x
(Trunc32to16 (SignExt8to32 x)) -> (SignExt8to16 x) (Trunc32to16 (SignExt8to32 x)) => (SignExt8to16 x)
(Trunc32to16 (SignExt16to32 x)) -> x (Trunc32to16 (SignExt16to32 x)) => x
(Trunc64to8 (SignExt8to64 x)) -> x (Trunc64to8 (SignExt8to64 x)) => x
(Trunc64to16 (SignExt8to64 x)) -> (SignExt8to16 x) (Trunc64to16 (SignExt8to64 x)) => (SignExt8to16 x)
(Trunc64to16 (SignExt16to64 x)) -> x (Trunc64to16 (SignExt16to64 x)) => x
(Trunc64to32 (SignExt8to64 x)) -> (SignExt8to32 x) (Trunc64to32 (SignExt8to64 x)) => (SignExt8to32 x)
(Trunc64to32 (SignExt16to64 x)) -> (SignExt16to32 x) (Trunc64to32 (SignExt16to64 x)) => (SignExt16to32 x)
(Trunc64to32 (SignExt32to64 x)) -> x (Trunc64to32 (SignExt32to64 x)) => x
(ZeroExt8to16 (Const8 [c])) -> (Const16 [int64( uint8(c))]) (ZeroExt8to16 (Const8 [c])) => (Const16 [int16( uint8(c))])
(ZeroExt8to32 (Const8 [c])) -> (Const32 [int64( uint8(c))]) (ZeroExt8to32 (Const8 [c])) => (Const32 [int32( uint8(c))])
(ZeroExt8to64 (Const8 [c])) -> (Const64 [int64( uint8(c))]) (ZeroExt8to64 (Const8 [c])) => (Const64 [int64( uint8(c))])
(ZeroExt16to32 (Const16 [c])) -> (Const32 [int64(uint16(c))]) (ZeroExt16to32 (Const16 [c])) => (Const32 [int32(uint16(c))])
(ZeroExt16to64 (Const16 [c])) -> (Const64 [int64(uint16(c))]) (ZeroExt16to64 (Const16 [c])) => (Const64 [int64(uint16(c))])
(ZeroExt32to64 (Const32 [c])) -> (Const64 [int64(uint32(c))]) (ZeroExt32to64 (Const32 [c])) => (Const64 [int64(uint32(c))])
(SignExt8to16 (Const8 [c])) -> (Const16 [int64( int8(c))]) (SignExt8to16 (Const8 [c])) => (Const16 [int16(c)])
(SignExt8to32 (Const8 [c])) -> (Const32 [int64( int8(c))]) (SignExt8to32 (Const8 [c])) => (Const32 [int32(c)])
(SignExt8to64 (Const8 [c])) -> (Const64 [int64( int8(c))]) (SignExt8to64 (Const8 [c])) => (Const64 [int64(c)])
(SignExt16to32 (Const16 [c])) -> (Const32 [int64( int16(c))]) (SignExt16to32 (Const16 [c])) => (Const32 [int32(c)])
(SignExt16to64 (Const16 [c])) -> (Const64 [int64( int16(c))]) (SignExt16to64 (Const16 [c])) => (Const64 [int64(c)])
(SignExt32to64 (Const32 [c])) -> (Const64 [int64( int32(c))]) (SignExt32to64 (Const32 [c])) => (Const64 [int64(c)])
(Neg8 (Const8 [c])) -> (Const8 [int64( -int8(c))]) (Neg8 (Const8 [c])) => (Const8 [-c])
(Neg16 (Const16 [c])) -> (Const16 [int64(-int16(c))]) (Neg16 (Const16 [c])) => (Const16 [-c])
(Neg32 (Const32 [c])) -> (Const32 [int64(-int32(c))]) (Neg32 (Const32 [c])) => (Const32 [-c])
(Neg64 (Const64 [c])) -> (Const64 [-c]) (Neg64 (Const64 [c])) => (Const64 [-c])
(Neg32F (Const32F [c])) && auxTo32F(c) != 0 -> (Const32F [auxFrom32F(-auxTo32F(c))]) (Neg32F (Const32F [c])) && c != 0 => (Const32F [-c])
(Neg64F (Const64F [c])) && auxTo64F(c) != 0 -> (Const64F [auxFrom64F(-auxTo64F(c))]) (Neg64F (Const64F [c])) && c != 0 => (Const64F [-c])
(Add8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c+d))]) (Add8 (Const8 [c]) (Const8 [d])) => (Const8 [c+d])
(Add16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c+d))]) (Add16 (Const16 [c]) (Const16 [d])) => (Const16 [c+d])
(Add32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c+d))]) (Add32 (Const32 [c]) (Const32 [d])) => (Const32 [c+d])
(Add64 (Const64 [c]) (Const64 [d])) -> (Const64 [c+d]) (Add64 (Const64 [c]) (Const64 [d])) => (Const64 [c+d])
(Add32F (Const32F [c]) (Const32F [d])) && !math.IsNaN(float64(auxTo32F(c) + auxTo32F(d))) -> (Const32F [auxFrom32F(auxTo32F(c) + auxTo32F(d))]) (Add32F (Const32F [c]) (Const32F [d])) && c+d == c+d => (Const32F [c+d])
(Add64F (Const64F [c]) (Const64F [d])) && !math.IsNaN(auxTo64F(c) + auxTo64F(d)) -> (Const64F [auxFrom64F(auxTo64F(c) + auxTo64F(d))]) (Add64F (Const64F [c]) (Const64F [d])) && c+d == c+d => (Const64F [c+d])
(AddPtr <t> x (Const64 [c])) -> (OffPtr <t> x [c]) (AddPtr <t> x (Const64 [c])) => (OffPtr <t> x [c])
(AddPtr <t> x (Const32 [c])) -> (OffPtr <t> x [c]) (AddPtr <t> x (Const32 [c])) => (OffPtr <t> x [int64(c)])
(Sub8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c-d))]) (Sub8 (Const8 [c]) (Const8 [d])) => (Const8 [c-d])
(Sub16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c-d))]) (Sub16 (Const16 [c]) (Const16 [d])) => (Const16 [c-d])
(Sub32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c-d))]) (Sub32 (Const32 [c]) (Const32 [d])) => (Const32 [c-d])
(Sub64 (Const64 [c]) (Const64 [d])) -> (Const64 [c-d]) (Sub64 (Const64 [c]) (Const64 [d])) => (Const64 [c-d])
(Sub32F (Const32F [c]) (Const32F [d])) && !math.IsNaN(float64(auxTo32F(c) - auxTo32F(d))) -> (Const32F [auxFrom32F(auxTo32F(c) - auxTo32F(d))]) (Sub32F (Const32F [c]) (Const32F [d])) && c-d == c-d => (Const32F [c-d])
(Sub64F (Const64F [c]) (Const64F [d])) && !math.IsNaN(auxTo64F(c) - auxTo64F(d)) -> (Const64F [auxFrom64F(auxTo64F(c) - auxTo64F(d))]) (Sub64F (Const64F [c]) (Const64F [d])) && c-d == c-d => (Const64F [c-d])
(Mul8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c*d))]) (Mul8 (Const8 [c]) (Const8 [d])) => (Const8 [c*d])
(Mul16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c*d))]) (Mul16 (Const16 [c]) (Const16 [d])) => (Const16 [c*d])
(Mul32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c*d))]) (Mul32 (Const32 [c]) (Const32 [d])) => (Const32 [c*d])
(Mul64 (Const64 [c]) (Const64 [d])) -> (Const64 [c*d]) (Mul64 (Const64 [c]) (Const64 [d])) => (Const64 [c*d])
(Mul32F (Const32F [c]) (Const32F [d])) && !math.IsNaN(float64(auxTo32F(c) * auxTo32F(d))) -> (Const32F [auxFrom32F(auxTo32F(c) * auxTo32F(d))]) (Mul32F (Const32F [c]) (Const32F [d])) && c*d == c*d => (Const32F [c*d])
(Mul64F (Const64F [c]) (Const64F [d])) && !math.IsNaN(auxTo64F(c) * auxTo64F(d)) -> (Const64F [auxFrom64F(auxTo64F(c) * auxTo64F(d))]) (Mul64F (Const64F [c]) (Const64F [d])) && c*d == c*d => (Const64F [c*d])
(And8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c&d))]) (And8 (Const8 [c]) (Const8 [d])) => (Const8 [c&d])
(And16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c&d))]) (And16 (Const16 [c]) (Const16 [d])) => (Const16 [c&d])
(And32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c&d))]) (And32 (Const32 [c]) (Const32 [d])) => (Const32 [c&d])
(And64 (Const64 [c]) (Const64 [d])) -> (Const64 [c&d]) (And64 (Const64 [c]) (Const64 [d])) => (Const64 [c&d])
(Or8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c|d))]) (Or8 (Const8 [c]) (Const8 [d])) => (Const8 [c|d])
(Or16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c|d))]) (Or16 (Const16 [c]) (Const16 [d])) => (Const16 [c|d])
(Or32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c|d))]) (Or32 (Const32 [c]) (Const32 [d])) => (Const32 [c|d])
(Or64 (Const64 [c]) (Const64 [d])) -> (Const64 [c|d]) (Or64 (Const64 [c]) (Const64 [d])) => (Const64 [c|d])
(Xor8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c^d))]) (Xor8 (Const8 [c]) (Const8 [d])) => (Const8 [c^d])
(Xor16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c^d))]) (Xor16 (Const16 [c]) (Const16 [d])) => (Const16 [c^d])
(Xor32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c^d))]) (Xor32 (Const32 [c]) (Const32 [d])) => (Const32 [c^d])
(Xor64 (Const64 [c]) (Const64 [d])) -> (Const64 [c^d]) (Xor64 (Const64 [c]) (Const64 [d])) => (Const64 [c^d])
(Ctz64 (Const64 [c])) && config.PtrSize == 4 -> (Const32 [ntz(c)]) (Ctz64 (Const64 [c])) && config.PtrSize == 4 => (Const32 [int32(ntz64(c))])
(Ctz32 (Const32 [c])) && config.PtrSize == 4 -> (Const32 [ntz32(c)]) (Ctz32 (Const32 [c])) && config.PtrSize == 4 => (Const32 [int32(ntz32(c))])
(Ctz16 (Const16 [c])) && config.PtrSize == 4 -> (Const32 [ntz16(c)]) (Ctz16 (Const16 [c])) && config.PtrSize == 4 => (Const32 [int32(ntz16(c))])
(Ctz8 (Const8 [c])) && config.PtrSize == 4 -> (Const32 [ntz8(c)]) (Ctz8 (Const8 [c])) && config.PtrSize == 4 => (Const32 [int32(ntz8(c))])
(Ctz64 (Const64 [c])) && config.PtrSize == 8 -> (Const64 [ntz(c)]) (Ctz64 (Const64 [c])) && config.PtrSize == 8 => (Const64 [int64(ntz64(c))])
(Ctz32 (Const32 [c])) && config.PtrSize == 8 -> (Const64 [ntz32(c)]) (Ctz32 (Const32 [c])) && config.PtrSize == 8 => (Const64 [int64(ntz32(c))])
(Ctz16 (Const16 [c])) && config.PtrSize == 8 -> (Const64 [ntz16(c)]) (Ctz16 (Const16 [c])) && config.PtrSize == 8 => (Const64 [int64(ntz16(c))])
(Ctz8 (Const8 [c])) && config.PtrSize == 8 -> (Const64 [ntz8(c)]) (Ctz8 (Const8 [c])) && config.PtrSize == 8 => (Const64 [int64(ntz8(c))])
(Div8 (Const8 [c]) (Const8 [d])) && d != 0 -> (Const8 [int64(int8(c)/int8(d))]) (Div8 (Const8 [c]) (Const8 [d])) && d != 0 => (Const8 [c/d])
(Div16 (Const16 [c]) (Const16 [d])) && d != 0 -> (Const16 [int64(int16(c)/int16(d))]) (Div16 (Const16 [c]) (Const16 [d])) && d != 0 => (Const16 [c/d])
(Div32 (Const32 [c]) (Const32 [d])) && d != 0 -> (Const32 [int64(int32(c)/int32(d))]) (Div32 (Const32 [c]) (Const32 [d])) && d != 0 => (Const32 [c/d])
(Div64 (Const64 [c]) (Const64 [d])) && d != 0 -> (Const64 [c/d]) (Div64 (Const64 [c]) (Const64 [d])) && d != 0 => (Const64 [c/d])
(Div8u (Const8 [c]) (Const8 [d])) && d != 0 -> (Const8 [int64(int8(uint8(c)/uint8(d)))]) (Div8u (Const8 [c]) (Const8 [d])) && d != 0 => (Const8 [int8(uint8(c)/uint8(d))])
(Div16u (Const16 [c]) (Const16 [d])) && d != 0 -> (Const16 [int64(int16(uint16(c)/uint16(d)))]) (Div16u (Const16 [c]) (Const16 [d])) && d != 0 => (Const16 [int16(uint16(c)/uint16(d))])
(Div32u (Const32 [c]) (Const32 [d])) && d != 0 -> (Const32 [int64(int32(uint32(c)/uint32(d)))]) (Div32u (Const32 [c]) (Const32 [d])) && d != 0 => (Const32 [int32(uint32(c)/uint32(d))])
(Div64u (Const64 [c]) (Const64 [d])) && d != 0 -> (Const64 [int64(uint64(c)/uint64(d))]) (Div64u (Const64 [c]) (Const64 [d])) && d != 0 => (Const64 [int64(uint64(c)/uint64(d))])
(Div32F (Const32F [c]) (Const32F [d])) && !math.IsNaN(float64(auxTo32F(c) / auxTo32F(d))) -> (Const32F [auxFrom32F(auxTo32F(c) / auxTo32F(d))]) (Div32F (Const32F [c]) (Const32F [d])) && c/d == c/d => (Const32F [c/d])
(Div64F (Const64F [c]) (Const64F [d])) && !math.IsNaN(auxTo64F(c) / auxTo64F(d)) -> (Const64F [auxFrom64F(auxTo64F(c) / auxTo64F(d))]) (Div64F (Const64F [c]) (Const64F [d])) && c/d == c/d => (Const64F [c/d])
(Select0 (Div128u (Const64 [0]) lo y)) -> (Div64u lo y) (Select0 (Div128u (Const64 [0]) lo y)) => (Div64u lo y)
(Select1 (Div128u (Const64 [0]) lo y)) -> (Mod64u lo y) (Select1 (Div128u (Const64 [0]) lo y)) => (Mod64u lo y)
(Not (ConstBool [c])) -> (ConstBool [1-c]) (Not (ConstBool [c])) -> (ConstBool [1-c])

View File

@ -739,11 +739,19 @@ func (w *bodyBase) add(node Statement) {
w.list = append(w.list, node) w.list = append(w.list, node)
} }
// predeclared contains globally known tokens that should not be redefined.
var predeclared = map[string]bool{
"nil": true,
"false": true,
"true": true,
}
// declared reports if the body contains a Declare or Declare2 with the given name. // declared reports if the body contains a Declare or Declare2 with the given name.
func (w *bodyBase) declared(name string) bool { func (w *bodyBase) declared(name string) bool {
if name == "nil" { if predeclared[name] {
// Treat "nil" as having already been declared. // Treat predeclared names as having already been declared.
// This lets us use nil to match an aux field. // This lets us use nil to match an aux field or
// true and false to match an auxint field.
return true return true
} }
for _, s := range w.list { for _, s := range w.list {
@ -1049,7 +1057,7 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string, cnt map[string]int,
alt: breakf("%s.%s.(%s) == %s", v, e.field, e.dclType, e.name), alt: breakf("%s.%s.(%s) == %s", v, e.field, e.dclType, e.name),
}) })
case "AuxInt": case "AuxInt":
rr.add(breakf("%s(%s.%s) != %s", e.dclType, v, e.field, e.name)) rr.add(breakf("auxIntTo%s(%s.%s) != %s", strings.Title(e.dclType), v, e.field, e.name))
case "Type": case "Type":
rr.add(breakf("%s.%s != %s", v, e.field, e.name)) rr.add(breakf("%s.%s != %s", v, e.field, e.name))
} }
@ -1063,7 +1071,7 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string, cnt map[string]int,
rr.add(declf(e.name, "%s.%s.(%s)", v, e.field, e.dclType)) rr.add(declf(e.name, "%s.%s.(%s)", v, e.field, e.dclType))
} }
case "AuxInt": case "AuxInt":
rr.add(declf(e.name, "%s(%s.%s)", e.dclType, v, e.field)) rr.add(declf(e.name, "auxIntTo%s(%s.%s)", strings.Title(e.dclType), v, e.field))
case "Type": case "Type":
rr.add(declf(e.name, "%s.%s", v, e.field)) rr.add(declf(e.name, "%s.%s", v, e.field))
} }
@ -1230,7 +1238,7 @@ func genResult0(rr *RuleRewrite, arch arch, result string, top, move bool, pos s
if rr.typed { if rr.typed {
// Make sure auxint value has the right type. // Make sure auxint value has the right type.
rr.add(stmtf("var _auxint %s = %s", op.auxIntType(), auxint)) rr.add(stmtf("var _auxint %s = %s", op.auxIntType(), auxint))
rr.add(stmtf("%s.AuxInt = int64(_auxint)", v)) rr.add(stmtf("%s.AuxInt = %sToAuxInt(_auxint)", v, op.auxIntType()))
} else { } else {
rr.add(stmtf("%s.AuxInt = %s", v, auxint)) rr.add(stmtf("%s.AuxInt = %s", v, auxint))
} }
@ -1772,7 +1780,8 @@ func (op opData) auxType() string {
// auxIntType returns the Go type that this operation should store in its auxInt field. // auxIntType returns the Go type that this operation should store in its auxInt field.
func (op opData) auxIntType() string { func (op opData) auxIntType() string {
switch op.aux { switch op.aux {
//case "Bool": case "Bool":
return "bool"
case "Int8": case "Int8":
return "int8" return "int8"
case "Int16": case "Int16":
@ -1782,8 +1791,10 @@ func (op opData) auxIntType() string {
case "Int64": case "Int64":
return "int64" return "int64"
//case "Int128": //case "Int128":
//case "Float32": case "Float32":
//case "Float64": return "float32"
case "Float64":
return "float64"
case "SymOff": case "SymOff":
return "int32" return "int32"
case "SymValAndOff": case "SymValAndOff":

View File

@ -347,11 +347,12 @@ func nlz(x int64) int64 {
return int64(bits.LeadingZeros64(uint64(x))) return int64(bits.LeadingZeros64(uint64(x)))
} }
// ntz returns the number of trailing zeros. // ntzX returns the number of trailing zeros.
func ntz(x int64) int64 { return int64(bits.TrailingZeros64(uint64(x))) } func ntz(x int64) int64 { return int64(bits.TrailingZeros64(uint64(x))) } // TODO: remove when no longer used
func ntz32(x int64) int64 { return int64(bits.TrailingZeros32(uint32(x))) } func ntz64(x int64) int { return bits.TrailingZeros64(uint64(x)) }
func ntz16(x int64) int64 { return int64(bits.TrailingZeros16(uint16(x))) } func ntz32(x int32) int { return bits.TrailingZeros32(uint32(x)) }
func ntz8(x int64) int64 { return int64(bits.TrailingZeros8(uint8(x))) } func ntz16(x int16) int { return bits.TrailingZeros16(uint16(x)) }
func ntz8(x int8) int { return bits.TrailingZeros8(uint8(x)) }
func oneBit(x int64) bool { func oneBit(x int64) bool {
return bits.OnesCount64(uint64(x)) == 1 return bits.OnesCount64(uint64(x)) == 1
@ -513,6 +514,62 @@ func auxTo64F(i int64) float64 {
return math.Float64frombits(uint64(i)) return math.Float64frombits(uint64(i))
} }
func auxIntToBool(i int64) bool {
if i == 0 {
return false
}
return true
}
func auxIntToInt8(i int64) int8 {
return int8(i)
}
func auxIntToInt16(i int64) int16 {
return int16(i)
}
func auxIntToInt32(i int64) int32 {
return int32(i)
}
func auxIntToInt64(i int64) int64 {
return i
}
func auxIntToFloat32(i int64) float32 {
return float32(math.Float64frombits(uint64(i)))
}
func auxIntToFloat64(i int64) float64 {
return math.Float64frombits(uint64(i))
}
func auxIntToValAndOff(i int64) ValAndOff {
return ValAndOff(i)
}
func boolToAuxInt(b bool) int64 {
if b {
return 1
}
return 0
}
func int8ToAuxInt(i int8) int64 {
return int64(i)
}
func int16ToAuxInt(i int16) int64 {
return int64(i)
}
func int32ToAuxInt(i int32) int64 {
return int64(i)
}
func int64ToAuxInt(i int64) int64 {
return int64(i)
}
func float32ToAuxInt(f float32) int64 {
return int64(math.Float64bits(float64(f)))
}
func float64ToAuxInt(f float64) int64 {
return int64(math.Float64bits(f))
}
func ValAndOffToAuxInt(v ValAndOff) int64 {
return int64(v)
}
// uaddOvf reports whether unsigned a+b would overflow. // uaddOvf reports whether unsigned a+b would overflow.
func uaddOvf(a, b int64) bool { func uaddOvf(a, b int64) bool {
return uint64(a)+uint64(b) < uint64(a) return uint64(a)+uint64(b) < uint64(a)

View File

@ -6940,12 +6940,12 @@ func rewriteValueAMD64_OpAMD64CMPBconst(v *Value) bool {
// cond: l.Uses == 1 && clobber(l) // cond: l.Uses == 1 && clobber(l)
// result: @l.Block (CMPBconstload {sym} [makeValAndOff32(int32(c),off)] ptr mem) // result: @l.Block (CMPBconstload {sym} [makeValAndOff32(int32(c),off)] ptr mem)
for { for {
c := int8(v.AuxInt) c := auxIntToInt8(v.AuxInt)
l := v_0 l := v_0
if l.Op != OpAMD64MOVBload { if l.Op != OpAMD64MOVBload {
break break
} }
off := int32(l.AuxInt) off := auxIntToInt32(l.AuxInt)
sym, _ := l.Aux.(Sym) sym, _ := l.Aux.(Sym)
mem := l.Args[1] mem := l.Args[1]
ptr := l.Args[0] ptr := l.Args[0]
@ -6956,7 +6956,7 @@ func rewriteValueAMD64_OpAMD64CMPBconst(v *Value) bool {
v0 := b.NewValue0(l.Pos, OpAMD64CMPBconstload, types.TypeFlags) v0 := b.NewValue0(l.Pos, OpAMD64CMPBconstload, types.TypeFlags)
v.copyOf(v0) v.copyOf(v0)
var _auxint ValAndOff = makeValAndOff32(int32(c), off) var _auxint ValAndOff = makeValAndOff32(int32(c), off)
v0.AuxInt = int64(_auxint) v0.AuxInt = ValAndOffToAuxInt(_auxint)
var _aux Sym = sym var _aux Sym = sym
v0.Aux = _aux v0.Aux = _aux
v0.AddArg2(ptr, mem) v0.AddArg2(ptr, mem)
@ -7327,12 +7327,12 @@ func rewriteValueAMD64_OpAMD64CMPLconst(v *Value) bool {
// cond: l.Uses == 1 && clobber(l) // cond: l.Uses == 1 && clobber(l)
// result: @l.Block (CMPLconstload {sym} [makeValAndOff32(c,off)] ptr mem) // result: @l.Block (CMPLconstload {sym} [makeValAndOff32(c,off)] ptr mem)
for { for {
c := int32(v.AuxInt) c := auxIntToInt32(v.AuxInt)
l := v_0 l := v_0
if l.Op != OpAMD64MOVLload { if l.Op != OpAMD64MOVLload {
break break
} }
off := int32(l.AuxInt) off := auxIntToInt32(l.AuxInt)
sym, _ := l.Aux.(Sym) sym, _ := l.Aux.(Sym)
mem := l.Args[1] mem := l.Args[1]
ptr := l.Args[0] ptr := l.Args[0]
@ -7343,7 +7343,7 @@ func rewriteValueAMD64_OpAMD64CMPLconst(v *Value) bool {
v0 := b.NewValue0(l.Pos, OpAMD64CMPLconstload, types.TypeFlags) v0 := b.NewValue0(l.Pos, OpAMD64CMPLconstload, types.TypeFlags)
v.copyOf(v0) v.copyOf(v0)
var _auxint ValAndOff = makeValAndOff32(c, off) var _auxint ValAndOff = makeValAndOff32(c, off)
v0.AuxInt = int64(_auxint) v0.AuxInt = ValAndOffToAuxInt(_auxint)
var _aux Sym = sym var _aux Sym = sym
v0.Aux = _aux v0.Aux = _aux
v0.AddArg2(ptr, mem) v0.AddArg2(ptr, mem)
@ -7894,12 +7894,12 @@ func rewriteValueAMD64_OpAMD64CMPQconst(v *Value) bool {
// cond: l.Uses == 1 && clobber(l) // cond: l.Uses == 1 && clobber(l)
// result: @l.Block (CMPQconstload {sym} [makeValAndOff32(c,off)] ptr mem) // result: @l.Block (CMPQconstload {sym} [makeValAndOff32(c,off)] ptr mem)
for { for {
c := int32(v.AuxInt) c := auxIntToInt32(v.AuxInt)
l := v_0 l := v_0
if l.Op != OpAMD64MOVQload { if l.Op != OpAMD64MOVQload {
break break
} }
off := int32(l.AuxInt) off := auxIntToInt32(l.AuxInt)
sym, _ := l.Aux.(Sym) sym, _ := l.Aux.(Sym)
mem := l.Args[1] mem := l.Args[1]
ptr := l.Args[0] ptr := l.Args[0]
@ -7910,7 +7910,7 @@ func rewriteValueAMD64_OpAMD64CMPQconst(v *Value) bool {
v0 := b.NewValue0(l.Pos, OpAMD64CMPQconstload, types.TypeFlags) v0 := b.NewValue0(l.Pos, OpAMD64CMPQconstload, types.TypeFlags)
v.copyOf(v0) v.copyOf(v0)
var _auxint ValAndOff = makeValAndOff32(c, off) var _auxint ValAndOff = makeValAndOff32(c, off)
v0.AuxInt = int64(_auxint) v0.AuxInt = ValAndOffToAuxInt(_auxint)
var _aux Sym = sym var _aux Sym = sym
v0.Aux = _aux v0.Aux = _aux
v0.AddArg2(ptr, mem) v0.AddArg2(ptr, mem)
@ -8266,12 +8266,12 @@ func rewriteValueAMD64_OpAMD64CMPWconst(v *Value) bool {
// cond: l.Uses == 1 && clobber(l) // cond: l.Uses == 1 && clobber(l)
// result: @l.Block (CMPWconstload {sym} [makeValAndOff32(int32(c),off)] ptr mem) // result: @l.Block (CMPWconstload {sym} [makeValAndOff32(int32(c),off)] ptr mem)
for { for {
c := int16(v.AuxInt) c := auxIntToInt16(v.AuxInt)
l := v_0 l := v_0
if l.Op != OpAMD64MOVWload { if l.Op != OpAMD64MOVWload {
break break
} }
off := int32(l.AuxInt) off := auxIntToInt32(l.AuxInt)
sym, _ := l.Aux.(Sym) sym, _ := l.Aux.(Sym)
mem := l.Args[1] mem := l.Args[1]
ptr := l.Args[0] ptr := l.Args[0]
@ -8282,7 +8282,7 @@ func rewriteValueAMD64_OpAMD64CMPWconst(v *Value) bool {
v0 := b.NewValue0(l.Pos, OpAMD64CMPWconstload, types.TypeFlags) v0 := b.NewValue0(l.Pos, OpAMD64CMPWconstload, types.TypeFlags)
v.copyOf(v0) v.copyOf(v0)
var _auxint ValAndOff = makeValAndOff32(int32(c), off) var _auxint ValAndOff = makeValAndOff32(int32(c), off)
v0.AuxInt = int64(_auxint) v0.AuxInt = ValAndOffToAuxInt(_auxint)
var _aux Sym = sym var _aux Sym = sym
v0.Aux = _aux v0.Aux = _aux
v0.AddArg2(ptr, mem) v0.AddArg2(ptr, mem)

File diff suppressed because it is too large Load Diff