1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 (Add(Ptr|64|32|16|8) ...) => (ADDV ...)
6 (Add(32|64)F ...) => (ADD(F|D) ...)
7
8 (Sub(Ptr|64|32|16|8) ...) => (SUBV ...)
9 (Sub(32|64)F ...) => (SUB(F|D) ...)
10
11 (Mul(64|32|16|8) ...) => (MULV ...)
12 (Mul(32|64)F ...) => (MUL(F|D) ...)
13 (Select0 (Mul64uhilo x y)) => (MULHVU x y)
14 (Select1 (Mul64uhilo x y)) => (MULV x y)
15 (Select0 (Mul64uover x y)) => (MULV x y)
16 (Select1 (Mul64uover x y)) => (SGTU <typ.Bool> (MULHVU x y) (MOVVconst <typ.UInt64> [0]))
17
18 (Hmul64 ...) => (MULHV ...)
19 (Hmul64u ...) => (MULHVU ...)
20 (Hmul32 x y) => (SRAVconst (MULV (SignExt32to64 x) (SignExt32to64 y)) [32])
21 (Hmul32u x y) => (SRLVconst (MULV (ZeroExt32to64 x) (ZeroExt32to64 y)) [32])
22
23 (Div64 x y) => (DIVV x y)
24 (Div64u ...) => (DIVVU ...)
25 (Div32 x y) => (DIVV (SignExt32to64 x) (SignExt32to64 y))
26 (Div32u x y) => (DIVVU (ZeroExt32to64 x) (ZeroExt32to64 y))
27 (Div16 x y) => (DIVV (SignExt16to64 x) (SignExt16to64 y))
28 (Div16u x y) => (DIVVU (ZeroExt16to64 x) (ZeroExt16to64 y))
29 (Div8 x y) => (DIVV (SignExt8to64 x) (SignExt8to64 y))
30 (Div8u x y) => (DIVVU (ZeroExt8to64 x) (ZeroExt8to64 y))
31 (Div(32|64)F ...) => (DIV(F|D) ...)
32
33 (Mod64 x y) => (REMV x y)
34 (Mod64u ...) => (REMVU ...)
35 (Mod32 x y) => (REMV (SignExt32to64 x) (SignExt32to64 y))
36 (Mod32u x y) => (REMVU (ZeroExt32to64 x) (ZeroExt32to64 y))
37 (Mod16 x y) => (REMV (SignExt16to64 x) (SignExt16to64 y))
38 (Mod16u x y) => (REMVU (ZeroExt16to64 x) (ZeroExt16to64 y))
39 (Mod8 x y) => (REMV (SignExt8to64 x) (SignExt8to64 y))
40 (Mod8u x y) => (REMVU (ZeroExt8to64 x) (ZeroExt8to64 y))
41
42 (Select0 <t> (Add64carry x y c)) => (ADDV (ADDV <t> x y) c)
43 (Select1 <t> (Add64carry x y c)) =>
44 (OR (SGTU <t> x s:(ADDV <t> x y)) (SGTU <t> s (ADDV <t> s c)))
45
46 (Select0 <t> (Sub64borrow x y c)) => (SUBV (SUBV <t> x y) c)
47 (Select1 <t> (Sub64borrow x y c)) =>
48 (OR (SGTU <t> s:(SUBV <t> x y) x) (SGTU <t> (SUBV <t> s c) s))
49
50 // (x + y) / 2 with x>=y => (x - y) / 2 + y
51 (Avg64u <t> x y) => (ADDV (SRLVconst <t> (SUBV <t> x y) [1]) y)
52
53 (And(64|32|16|8) ...) => (AND ...)
54 (Or(64|32|16|8) ...) => (OR ...)
55 (Xor(64|32|16|8) ...) => (XOR ...)
56
57 // shifts
58 // hardware instruction uses only the low 6 bits of the shift
59 // we compare to 64 to ensure Go semantics for large shifts
60 (Lsh64x64 <t> x y) => (MASKEQZ (SLLV <t> x y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
61 (Lsh64x32 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
62 (Lsh64x16 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
63 (Lsh64x8 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
64
65 (Lsh32x64 <t> x y) => (MASKEQZ (SLLV <t> x y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
66 (Lsh32x32 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
67 (Lsh32x16 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
68 (Lsh32x8 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
69
70 (Lsh16x64 <t> x y) => (MASKEQZ (SLLV <t> x y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
71 (Lsh16x32 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
72 (Lsh16x16 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
73 (Lsh16x8 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
74
75 (Lsh8x64 <t> x y) => (MASKEQZ (SLLV <t> x y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
76 (Lsh8x32 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
77 (Lsh8x16 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
78 (Lsh8x8 <t> x y) => (MASKEQZ (SLLV <t> x (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
79
80 (Rsh64Ux64 <t> x y) => (MASKEQZ (SRLV <t> x y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
81 (Rsh64Ux32 <t> x y) => (MASKEQZ (SRLV <t> x (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
82 (Rsh64Ux16 <t> x y) => (MASKEQZ (SRLV <t> x (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
83 (Rsh64Ux8 <t> x y) => (MASKEQZ (SRLV <t> x (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
84
85 (Rsh32Ux64 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt32to64 x) y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
86 (Rsh32Ux32 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt32to64 x) (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
87 (Rsh32Ux16 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt32to64 x) (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
88 (Rsh32Ux8 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt32to64 x) (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
89
90 (Rsh16Ux64 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt16to64 x) y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
91 (Rsh16Ux32 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt16to64 x) (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
92 (Rsh16Ux16 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt16to64 x) (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
93 (Rsh16Ux8 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt16to64 x) (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
94
95 (Rsh8Ux64 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt8to64 x) y) (SGTU (MOVVconst <typ.UInt64> [64]) y))
96 (Rsh8Ux32 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt8to64 x) (ZeroExt32to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt32to64 y)))
97 (Rsh8Ux16 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt8to64 x) (ZeroExt16to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt16to64 y)))
98 (Rsh8Ux8 <t> x y) => (MASKEQZ (SRLV <t> (ZeroExt8to64 x) (ZeroExt8to64 y)) (SGTU (MOVVconst <typ.UInt64> [64]) (ZeroExt8to64 y)))
99
100 (Rsh64x64 <t> x y) => (SRAV x (OR <t> (NEGV <t> (SGTU y (MOVVconst <typ.UInt64> [63]))) y))
101 (Rsh64x32 <t> x y) => (SRAV x (OR <t> (NEGV <t> (SGTU (ZeroExt32to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt32to64 y)))
102 (Rsh64x16 <t> x y) => (SRAV x (OR <t> (NEGV <t> (SGTU (ZeroExt16to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt16to64 y)))
103 (Rsh64x8 <t> x y) => (SRAV x (OR <t> (NEGV <t> (SGTU (ZeroExt8to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt8to64 y)))
104
105 (Rsh32x64 <t> x y) => (SRAV (SignExt32to64 x) (OR <t> (NEGV <t> (SGTU y (MOVVconst <typ.UInt64> [63]))) y))
106 (Rsh32x32 <t> x y) => (SRAV (SignExt32to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt32to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt32to64 y)))
107 (Rsh32x16 <t> x y) => (SRAV (SignExt32to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt16to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt16to64 y)))
108 (Rsh32x8 <t> x y) => (SRAV (SignExt32to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt8to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt8to64 y)))
109
110 (Rsh16x64 <t> x y) => (SRAV (SignExt16to64 x) (OR <t> (NEGV <t> (SGTU y (MOVVconst <typ.UInt64> [63]))) y))
111 (Rsh16x32 <t> x y) => (SRAV (SignExt16to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt32to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt32to64 y)))
112 (Rsh16x16 <t> x y) => (SRAV (SignExt16to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt16to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt16to64 y)))
113 (Rsh16x8 <t> x y) => (SRAV (SignExt16to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt8to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt8to64 y)))
114
115 (Rsh8x64 <t> x y) => (SRAV (SignExt8to64 x) (OR <t> (NEGV <t> (SGTU y (MOVVconst <typ.UInt64> [63]))) y))
116 (Rsh8x32 <t> x y) => (SRAV (SignExt8to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt32to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt32to64 y)))
117 (Rsh8x16 <t> x y) => (SRAV (SignExt8to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt16to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt16to64 y)))
118 (Rsh8x8 <t> x y) => (SRAV (SignExt8to64 x) (OR <t> (NEGV <t> (SGTU (ZeroExt8to64 y) (MOVVconst <typ.UInt64> [63]))) (ZeroExt8to64 y)))
119
120 // bitfield ops
121
122 // bstrpickv
123 // (x << lc) >> rc
124 (SRLVconst [rc] (SLLVconst [lc] x)) && lc <= rc => (BSTRPICKV [rc-lc + ((64-lc)-1)<<6] x)
125 // uint64(x) >> rc
126 (SRLVconst [rc] (MOVWUreg x)) && rc < 32 => (BSTRPICKV [rc + 31<<6] x)
127 (SRLVconst [rc] (MOVHUreg x)) && rc < 16 => (BSTRPICKV [rc + 15<<6] x)
128 (SRLVconst [rc] (MOVBUreg x)) && rc < 8 => (BSTRPICKV [rc + 7<<6] x)
129 // uint64(x >> rc)
130 (MOVWUreg (SRLVconst [rc] x)) && rc < 32 => (BSTRPICKV [rc + (31+rc)<<6] x)
131 (MOVHUreg (SRLVconst [rc] x)) && rc < 16 => (BSTRPICKV [rc + (15+rc)<<6] x)
132 (MOVBUreg (SRLVconst [rc] x)) && rc < 8 => (BSTRPICKV [rc + (7+rc)<<6] x)
133
134 // rotates
135 (RotateLeft8 <t> x (MOVVconst [c])) => (Or8 (Lsh8x64 <t> x (MOVVconst [c&7])) (Rsh8Ux64 <t> x (MOVVconst [-c&7])))
136 (RotateLeft8 <t> x y) => (OR <t> (SLLV <t> x (ANDconst <typ.Int64> [7] y)) (SRLV <t> (ZeroExt8to64 x) (ANDconst <typ.Int64> [7] (NEGV <typ.Int64> y))))
137 (RotateLeft16 <t> x (MOVVconst [c])) => (Or16 (Lsh16x64 <t> x (MOVVconst [c&15])) (Rsh16Ux64 <t> x (MOVVconst [-c&15])))
138 (RotateLeft16 <t> x y) => (ROTR <t> (OR <typ.UInt32> (ZeroExt16to32 x) (SLLVconst <t> (ZeroExt16to32 x) [16])) (NEGV <typ.Int64> y))
139 (RotateLeft32 x y) => (ROTR x (NEGV <y.Type> y))
140 (RotateLeft64 x y) => (ROTRV x (NEGV <y.Type> y))
141
142 // unary ops
143 (Neg(64|32|16|8) ...) => (NEGV ...)
144 (Neg(32|64)F ...) => (NEG(F|D) ...)
145
146 (Com(64|32|16|8) x) => (NOR (MOVVconst [0]) x)
147
148 (BitLen64 <t> x) => (NEGV <t> (SUBVconst <t> [64] (CLZV <t> x)))
149 (BitLen32 <t> x) => (NEGV <t> (SUBVconst <t> [32] (CLZW <t> x)))
150 (Bswap(16|32|64) ...) => (REVB(2H|2W|V) ...)
151 (BitRev8 ...) => (BITREV4B ...)
152 (BitRev16 <t> x) => (REVB2H (BITREV4B <t> x))
153 (BitRev32 ...) => (BITREVW ...)
154 (BitRev64 ...) => (BITREVV ...)
155 (Ctz(32|64)NonZero ...) => (Ctz(32|64) ...)
156 (Ctz(32|64) ...) => (CTZ(W|V) ...)
157
158 (PopCount64 <t> x) => (MOVVfpgp <t> (VPCNT64 <typ.Float64> (MOVVgpfp <typ.Float64> x)))
159 (PopCount32 <t> x) => (MOVWfpgp <t> (VPCNT32 <typ.Float32> (MOVWgpfp <typ.Float32> x)))
160 (PopCount16 <t> x) => (MOVWfpgp <t> (VPCNT16 <typ.Float32> (MOVWgpfp <typ.Float32> (ZeroExt16to32 x))))
161
162 // math package intrinsics
163 (Sqrt ...) => (SQRTD ...)
164 (Sqrt32 ...) => (SQRTF ...)
165 (Abs ...) => (ABSD ...)
166 (Copysign ...) => (FCOPYSGD ...)
167
168 (Min(64|32)F ...) => (FMIN(D|F) ...)
169 (Max(64|32)F ...) => (FMAX(D|F) ...)
170
171 // boolean ops -- booleans are represented with 0=false, 1=true
172 (AndB ...) => (AND ...)
173 (OrB ...) => (OR ...)
174 (EqB x y) => (XOR (MOVVconst [1]) (XOR <typ.Bool> x y))
175 (NeqB ...) => (XOR ...)
176 (Not x) => (XORconst [1] x)
177
178 // constants
179 (Const(64|32|16|8) [val]) => (MOVVconst [int64(val)])
180 (Const(32|64)F [val]) => (MOV(F|D)const [float64(val)])
181 (ConstNil) => (MOVVconst [0])
182 (ConstBool [t]) => (MOVVconst [int64(b2i(t))])
183
184 (Slicemask <t> x) => (SRAVconst (NEGV <t> x) [63])
185
186 // truncations
187 // Because we ignore high parts of registers, truncates are just copies.
188 (Trunc16to8 ...) => (Copy ...)
189 (Trunc32to8 ...) => (Copy ...)
190 (Trunc32to16 ...) => (Copy ...)
191 (Trunc64to8 ...) => (Copy ...)
192 (Trunc64to16 ...) => (Copy ...)
193 (Trunc64to32 ...) => (Copy ...)
194
195 // Zero-/Sign-extensions
196 (ZeroExt8to16 ...) => (MOVBUreg ...)
197 (ZeroExt8to32 ...) => (MOVBUreg ...)
198 (ZeroExt16to32 ...) => (MOVHUreg ...)
199 (ZeroExt8to64 ...) => (MOVBUreg ...)
200 (ZeroExt16to64 ...) => (MOVHUreg ...)
201 (ZeroExt32to64 ...) => (MOVWUreg ...)
202
203 (SignExt8to16 ...) => (MOVBreg ...)
204 (SignExt8to32 ...) => (MOVBreg ...)
205 (SignExt16to32 ...) => (MOVHreg ...)
206 (SignExt8to64 ...) => (MOVBreg ...)
207 (SignExt16to64 ...) => (MOVHreg ...)
208 (SignExt32to64 ...) => (MOVWreg ...)
209
210 // float <=> int conversion
211 (Cvt32to32F ...) => (MOVWF ...)
212 (Cvt32to64F ...) => (MOVWD ...)
213 (Cvt64to32F ...) => (MOVVF ...)
214 (Cvt64to64F ...) => (MOVVD ...)
215 (Cvt32Fto32 ...) => (TRUNCFW ...)
216 (Cvt64Fto32 ...) => (TRUNCDW ...)
217 (Cvt32Fto64 ...) => (TRUNCFV ...)
218 (Cvt64Fto64 ...) => (TRUNCDV ...)
219 (Cvt32Fto64F ...) => (MOVFD ...)
220 (Cvt64Fto32F ...) => (MOVDF ...)
221
222 (CvtBoolToUint8 ...) => (Copy ...)
223
224 (Round(32|64)F ...) => (LoweredRound(32|64)F ...)
225
226 // comparisons
227 (Eq8 x y) => (SGTU (MOVVconst [1]) (XOR (ZeroExt8to64 x) (ZeroExt8to64 y)))
228 (Eq16 x y) => (SGTU (MOVVconst [1]) (XOR (ZeroExt16to64 x) (ZeroExt16to64 y)))
229 (Eq32 x y) => (SGTU (MOVVconst [1]) (XOR (ZeroExt32to64 x) (ZeroExt32to64 y)))
230 (Eq64 x y) => (SGTU (MOVVconst [1]) (XOR x y))
231 (EqPtr x y) => (SGTU (MOVVconst [1]) (XOR x y))
232 (Eq(32|64)F x y) => (FPFlagTrue (CMPEQ(F|D) x y))
233
234 (Neq8 x y) => (SGTU (XOR (ZeroExt8to64 x) (ZeroExt8to64 y)) (MOVVconst [0]))
235 (Neq16 x y) => (SGTU (XOR (ZeroExt16to32 x) (ZeroExt16to64 y)) (MOVVconst [0]))
236 (Neq32 x y) => (SGTU (XOR (ZeroExt32to64 x) (ZeroExt32to64 y)) (MOVVconst [0]))
237 (Neq64 x y) => (SGTU (XOR x y) (MOVVconst [0]))
238 (NeqPtr x y) => (SGTU (XOR x y) (MOVVconst [0]))
239 (Neq(32|64)F x y) => (FPFlagFalse (CMPEQ(F|D) x y))
240
241 (Less8 x y) => (SGT (SignExt8to64 y) (SignExt8to64 x))
242 (Less16 x y) => (SGT (SignExt16to64 y) (SignExt16to64 x))
243 (Less32 x y) => (SGT (SignExt32to64 y) (SignExt32to64 x))
244 (Less64 x y) => (SGT y x)
245 (Less(32|64)F x y) => (FPFlagTrue (CMPGT(F|D) y x)) // reverse operands to work around NaN
246
247 (Less8U x y) => (SGTU (ZeroExt8to64 y) (ZeroExt8to64 x))
248 (Less16U x y) => (SGTU (ZeroExt16to64 y) (ZeroExt16to64 x))
249 (Less32U x y) => (SGTU (ZeroExt32to64 y) (ZeroExt32to64 x))
250 (Less64U x y) => (SGTU y x)
251
252 (Leq8 x y) => (XOR (MOVVconst [1]) (SGT (SignExt8to64 x) (SignExt8to64 y)))
253 (Leq16 x y) => (XOR (MOVVconst [1]) (SGT (SignExt16to64 x) (SignExt16to64 y)))
254 (Leq32 x y) => (XOR (MOVVconst [1]) (SGT (SignExt32to64 x) (SignExt32to64 y)))
255 (Leq64 x y) => (XOR (MOVVconst [1]) (SGT x y))
256 (Leq(32|64)F x y) => (FPFlagTrue (CMPGE(F|D) y x)) // reverse operands to work around NaN
257
258 (Leq8U x y) => (XOR (MOVVconst [1]) (SGTU (ZeroExt8to64 x) (ZeroExt8to64 y)))
259 (Leq16U x y) => (XOR (MOVVconst [1]) (SGTU (ZeroExt16to64 x) (ZeroExt16to64 y)))
260 (Leq32U x y) => (XOR (MOVVconst [1]) (SGTU (ZeroExt32to64 x) (ZeroExt32to64 y)))
261 (Leq64U x y) => (XOR (MOVVconst [1]) (SGTU x y))
262
263 (OffPtr [off] ptr:(SP)) => (MOVVaddr [int32(off)] ptr)
264 (OffPtr [off] ptr) => (ADDVconst [off] ptr)
265
266 (Addr {sym} base) => (MOVVaddr {sym} base)
267 (LocalAddr <t> {sym} base mem) && t.Elem().HasPointers() => (MOVVaddr {sym} (SPanchored base mem))
268 (LocalAddr <t> {sym} base _) && !t.Elem().HasPointers() => (MOVVaddr {sym} base)
269
270 // loads
271 (Load <t> ptr mem) && t.IsBoolean() => (MOVBUload ptr mem)
272 (Load <t> ptr mem) && (is8BitInt(t) && t.IsSigned()) => (MOVBload ptr mem)
273 (Load <t> ptr mem) && (is8BitInt(t) && !t.IsSigned()) => (MOVBUload ptr mem)
274 (Load <t> ptr mem) && (is16BitInt(t) && t.IsSigned()) => (MOVHload ptr mem)
275 (Load <t> ptr mem) && (is16BitInt(t) && !t.IsSigned()) => (MOVHUload ptr mem)
276 (Load <t> ptr mem) && (is32BitInt(t) && t.IsSigned()) => (MOVWload ptr mem)
277 (Load <t> ptr mem) && (is32BitInt(t) && !t.IsSigned()) => (MOVWUload ptr mem)
278 (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) => (MOVVload ptr mem)
279 (Load <t> ptr mem) && is32BitFloat(t) => (MOVFload ptr mem)
280 (Load <t> ptr mem) && is64BitFloat(t) => (MOVDload ptr mem)
281
282 // stores
283 (Store {t} ptr val mem) && t.Size() == 1 => (MOVBstore ptr val mem)
284 (Store {t} ptr val mem) && t.Size() == 2 => (MOVHstore ptr val mem)
285 (Store {t} ptr val mem) && t.Size() == 4 && !t.IsFloat() => (MOVWstore ptr val mem)
286 (Store {t} ptr val mem) && t.Size() == 8 && !t.IsFloat() => (MOVVstore ptr val mem)
287 (Store {t} ptr val mem) && t.Size() == 4 && t.IsFloat() => (MOVFstore ptr val mem)
288 (Store {t} ptr val mem) && t.Size() == 8 && t.IsFloat() => (MOVDstore ptr val mem)
289
290 // zeroing
291 (Zero [0] _ mem) => mem
292 (Zero [1] ptr mem) => (MOVBstore ptr (MOVVconst [0]) mem)
293 (Zero [2] ptr mem) => (MOVHstore ptr (MOVVconst [0]) mem)
294 (Zero [3] ptr mem) =>
295 (MOVBstore [2] ptr (MOVVconst [0])
296 (MOVHstore ptr (MOVVconst [0]) mem))
297 (Zero [4] {t} ptr mem) => (MOVWstore ptr (MOVVconst [0]) mem)
298 (Zero [5] ptr mem) =>
299 (MOVBstore [4] ptr (MOVVconst [0])
300 (MOVWstore ptr (MOVVconst [0]) mem))
301 (Zero [6] ptr mem) =>
302 (MOVHstore [4] ptr (MOVVconst [0])
303 (MOVWstore ptr (MOVVconst [0]) mem))
304 (Zero [7] ptr mem) =>
305 (MOVWstore [3] ptr (MOVVconst [0])
306 (MOVWstore ptr (MOVVconst [0]) mem))
307 (Zero [8] {t} ptr mem) => (MOVVstore ptr (MOVVconst [0]) mem)
308 (Zero [9] ptr mem) =>
309 (MOVBstore [8] ptr (MOVVconst [0])
310 (MOVVstore ptr (MOVVconst [0]) mem))
311 (Zero [10] ptr mem) =>
312 (MOVHstore [8] ptr (MOVVconst [0])
313 (MOVVstore ptr (MOVVconst [0]) mem))
314 (Zero [11] ptr mem) =>
315 (MOVWstore [7] ptr (MOVVconst [0])
316 (MOVVstore ptr (MOVVconst [0]) mem))
317 (Zero [12] ptr mem) =>
318 (MOVWstore [8] ptr (MOVVconst [0])
319 (MOVVstore ptr (MOVVconst [0]) mem))
320 (Zero [13] ptr mem) =>
321 (MOVVstore [5] ptr (MOVVconst [0])
322 (MOVVstore ptr (MOVVconst [0]) mem))
323 (Zero [14] ptr mem) =>
324 (MOVVstore [6] ptr (MOVVconst [0])
325 (MOVVstore ptr (MOVVconst [0]) mem))
326 (Zero [15] ptr mem) =>
327 (MOVVstore [7] ptr (MOVVconst [0])
328 (MOVVstore ptr (MOVVconst [0]) mem))
329 (Zero [16] ptr mem) =>
330 (MOVVstore [8] ptr (MOVVconst [0])
331 (MOVVstore ptr (MOVVconst [0]) mem))
332
333 // strip off fractional word zeroing
334 (Zero [s] ptr mem) && s%8 != 0 && s > 16 =>
335 (Zero [s%8]
336 (OffPtr <ptr.Type> ptr [s-s%8])
337 (Zero [s-s%8] ptr mem))
338
339 // medium zeroing uses a duff device
340 (Zero [s] ptr mem)
341 && s%8 == 0 && s > 16 && s <= 8*128
342 && !config.noDuffDevice =>
343 (DUFFZERO [8 * (128 - s/8)] ptr mem)
344
345 // large zeroing uses a loop
346 (Zero [s] ptr mem)
347 && s%8 == 0 && s > 8*128 =>
348 (LoweredZero
349 ptr
350 (ADDVconst <ptr.Type> ptr [s-8])
351 mem)
352
353 // moves
354 (Move [0] _ _ mem) => mem
355 (Move [1] dst src mem) => (MOVBstore dst (MOVBUload src mem) mem)
356 (Move [2] dst src mem) => (MOVHstore dst (MOVHUload src mem) mem)
357 (Move [3] dst src mem) =>
358 (MOVBstore [2] dst (MOVBUload [2] src mem)
359 (MOVHstore dst (MOVHUload src mem) mem))
360 (Move [4] dst src mem) => (MOVWstore dst (MOVWUload src mem) mem)
361 (Move [5] dst src mem) =>
362 (MOVBstore [4] dst (MOVBUload [4] src mem)
363 (MOVWstore dst (MOVWUload src mem) mem))
364 (Move [6] dst src mem) =>
365 (MOVHstore [4] dst (MOVHUload [4] src mem)
366 (MOVWstore dst (MOVWUload src mem) mem))
367 (Move [7] dst src mem) =>
368 (MOVWstore [3] dst (MOVWUload [3] src mem)
369 (MOVWstore dst (MOVWUload src mem) mem))
370 (Move [8] dst src mem) => (MOVVstore dst (MOVVload src mem) mem)
371 (Move [9] dst src mem) =>
372 (MOVBstore [8] dst (MOVBUload [8] src mem)
373 (MOVVstore dst (MOVVload src mem) mem))
374 (Move [10] dst src mem) =>
375 (MOVHstore [8] dst (MOVHUload [8] src mem)
376 (MOVVstore dst (MOVVload src mem) mem))
377 (Move [11] dst src mem) =>
378 (MOVWstore [7] dst (MOVWload [7] src mem)
379 (MOVVstore dst (MOVVload src mem) mem))
380 (Move [12] dst src mem) =>
381 (MOVWstore [8] dst (MOVWUload [8] src mem)
382 (MOVVstore dst (MOVVload src mem) mem))
383 (Move [13] dst src mem) =>
384 (MOVVstore [5] dst (MOVVload [5] src mem)
385 (MOVVstore dst (MOVVload src mem) mem))
386 (Move [14] dst src mem) =>
387 (MOVVstore [6] dst (MOVVload [6] src mem)
388 (MOVVstore dst (MOVVload src mem) mem))
389 (Move [15] dst src mem) =>
390 (MOVVstore [7] dst (MOVVload [7] src mem)
391 (MOVVstore dst (MOVVload src mem) mem))
392 (Move [16] dst src mem) =>
393 (MOVVstore [8] dst (MOVVload [8] src mem)
394 (MOVVstore dst (MOVVload src mem) mem))
395
396 // strip off fractional word move
397 (Move [s] dst src mem) && s%8 != 0 && s > 16 =>
398 (Move [s%8]
399 (OffPtr <dst.Type> dst [s-s%8])
400 (OffPtr <src.Type> src [s-s%8])
401 (Move [s-s%8] dst src mem))
402
403 // medium move uses a duff device
404 (Move [s] dst src mem)
405 && s%8 == 0 && s > 16 && s <= 8*128
406 && !config.noDuffDevice && logLargeCopy(v, s) =>
407 (DUFFCOPY [16 * (128 - s/8)] dst src mem)
408 // 16 and 128 are magic constants. 16 is the number of bytes to encode:
409 // MOVV (R20), R30
410 // ADDV $8, R20
411 // MOVV R30, (R21)
412 // ADDV $8, R21
413 // and 128 is the number of such blocks. See runtime/duff_loong64.s:duffcopy.
414
415 // large move uses a loop
416 (Move [s] dst src mem)
417 && s%8 == 0 && s > 1024 && logLargeCopy(v, s) =>
418 (LoweredMove
419 dst
420 src
421 (ADDVconst <src.Type> src [s-8])
422 mem)
423
424
425 // float <=> int register moves, with no conversion.
426 // These come up when compiling math.{Float64bits, Float64frombits, Float32bits, Float32frombits}.
427 (MOVVload [off] {sym} ptr (MOVDstore [off] {sym} ptr val _)) => (MOVVfpgp val)
428 (MOVDload [off] {sym} ptr (MOVVstore [off] {sym} ptr val _)) => (MOVVgpfp val)
429 (MOVWUload [off] {sym} ptr (MOVFstore [off] {sym} ptr val _)) => (ZeroExt32to64 (MOVWfpgp <typ.Float32> val))
430 (MOVFload [off] {sym} ptr (MOVWstore [off] {sym} ptr val _)) => (MOVWgpfp val)
431
432 // Similarly for stores, if we see a store after FPR <=> GPR move, then redirect store to use the other register set.
433 (MOVVstore [off] {sym} ptr (MOVVfpgp val) mem) => (MOVDstore [off] {sym} ptr val mem)
434 (MOVDstore [off] {sym} ptr (MOVVgpfp val) mem) => (MOVVstore [off] {sym} ptr val mem)
435 (MOVWstore [off] {sym} ptr (MOVWfpgp val) mem) => (MOVFstore [off] {sym} ptr val mem)
436 (MOVFstore [off] {sym} ptr (MOVWgpfp val) mem) => (MOVWstore [off] {sym} ptr val mem)
437
438 // calls
439 (StaticCall ...) => (CALLstatic ...)
440 (ClosureCall ...) => (CALLclosure ...)
441 (InterCall ...) => (CALLinter ...)
442 (TailCall ...) => (CALLtail ...)
443
444 // atomic intrinsics
445 (AtomicLoad(8|32|64) ...) => (LoweredAtomicLoad(8|32|64) ...)
446 (AtomicLoadPtr ...) => (LoweredAtomicLoad64 ...)
447
448 (AtomicStore(8|32|64) ...) => (LoweredAtomicStore(8|32|64) ...)
449 (AtomicStore(8|32|64)Variant ...) => (LoweredAtomicStore(8|32|64)Variant ...)
450 (AtomicStorePtrNoWB ...) => (LoweredAtomicStore64 ...)
451
452 (AtomicExchange(32|64) ...) => (LoweredAtomicExchange(32|64) ...)
453
454 (AtomicAdd(32|64) ...) => (LoweredAtomicAdd(32|64) ...)
455
456 (AtomicCompareAndSwap32 ptr old new mem) => (LoweredAtomicCas32 ptr (SignExt32to64 old) new mem)
457 (AtomicCompareAndSwap64 ...) => (LoweredAtomicCas64 ...)
458
459 // Atomic memory logical operations (old style).
460 //
461 // AtomicAnd8(ptr,val) => LoweredAtomicAnd32(ptr&^3, ^((uint8(val) ^ 0xff) << ((ptr & 3) * 8)))
462 // AtomicOr8(ptr,val) => LoweredAtomicOr32(ptr&^3, uint32(val) << ((ptr & 3) * 8))
463 //
464 (AtomicAnd8 ptr val mem) =>
465 (LoweredAtomicAnd32 (AND <typ.Uintptr> (MOVVconst [^3]) ptr)
466 (NORconst [0] <typ.UInt32> (SLLV <typ.UInt32> (XORconst <typ.UInt32> [0xff] (ZeroExt8to32 val))
467 (SLLVconst <typ.UInt64> [3] (ANDconst <typ.UInt64> [3] ptr)))) mem)
468
469 (AtomicOr8 ptr val mem) =>
470 (LoweredAtomicOr32 (AND <typ.Uintptr> (MOVVconst [^3]) ptr)
471 (SLLV <typ.UInt32> (ZeroExt8to32 val)
472 (SLLVconst <typ.UInt64> [3] (ANDconst <typ.UInt64> [3] ptr))) mem)
473
474 (AtomicAnd32 ...) => (LoweredAtomicAnd32 ...)
475 (AtomicOr32 ...) => (LoweredAtomicOr32 ...)
476
477 // Atomic memory logical operations (new style).
478 (AtomicAnd(64|32)value ...) => (LoweredAtomicAnd(64|32)value ...)
479 (AtomicOr(64|32)value ...) => (LoweredAtomicOr(64|32)value ...)
480
481 // checks
482 (NilCheck ...) => (LoweredNilCheck ...)
483 (IsNonNil ptr) => (SGTU ptr (MOVVconst [0]))
484 (IsInBounds idx len) => (SGTU len idx)
485 (IsSliceInBounds idx len) => (XOR (MOVVconst [1]) (SGTU idx len))
486
487 // pseudo-ops
488 (GetClosurePtr ...) => (LoweredGetClosurePtr ...)
489 (GetCallerSP ...) => (LoweredGetCallerSP ...)
490 (GetCallerPC ...) => (LoweredGetCallerPC ...)
491
492 (If cond yes no) => (NE (MOVBUreg <typ.UInt64> cond) yes no)
493 (MOVBUreg x:((SGT|SGTU) _ _)) => x
494 (MOVBUreg x:(XOR (MOVVconst [1]) ((SGT|SGTU) _ _))) => x
495
496 // Write barrier.
497 (WB ...) => (LoweredWB ...)
498
499 // Publication barrier as intrinsic
500 (PubBarrier ...) => (LoweredPubBarrier ...)
501
502 (PanicBounds [kind] x y mem) && boundsABI(kind) == 0 => (LoweredPanicBoundsA [kind] x y mem)
503 (PanicBounds [kind] x y mem) && boundsABI(kind) == 1 => (LoweredPanicBoundsB [kind] x y mem)
504 (PanicBounds [kind] x y mem) && boundsABI(kind) == 2 => (LoweredPanicBoundsC [kind] x y mem)
505
506 (CondSelect <t> x y cond) => (OR (MASKEQZ <t> x cond) (MASKNEZ <t> y cond))
507
508 // c > d-x => x > d-c
509 (SGT (MOVVconst [c]) (NEGV (SUBVconst [d] x))) && is32Bit(d-c) => (SGT x (MOVVconst [d-c]))
510
511 (SGT (MOVVconst [c]) x) && is32Bit(c) => (SGTconst [c] x)
512 (SGTU (MOVVconst [c]) x) && is32Bit(c) => (SGTUconst [c] x)
513
514 // fold offset into address
515 (ADDVconst [off1] (MOVVaddr [off2] {sym} ptr)) && is32Bit(off1+int64(off2)) => (MOVVaddr [int32(off1)+int32(off2)] {sym} ptr)
516
517 // fold address into load/store
518 // Do not fold global variable access in -dynlink mode, where it will be rewritten
519 // to use the GOT via REGTMP, which currently cannot handle large offset.
520 (MOV(B|BU|H|HU|W|WU|V|F|D)load [off1] {sym} (ADDVconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
521 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
522 (MOV(B|BU|H|HU|W|WU|V|F|D)load [off1+int32(off2)] {sym} ptr mem)
523
524 (MOV(B|H|W|V|F|D)store [off1] {sym} (ADDVconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
525 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
526 (MOV(B|H|W|V|F|D)store [off1+int32(off2)] {sym} ptr val mem)
527
528 (MOV(B|H|W|V)storezero [off1] {sym} (ADDVconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
529 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
530 (MOV(B|H|W|V)storezero [off1+int32(off2)] {sym} ptr mem)
531
532 (MOV(B|BU|H|HU|W|WU|V|F|D)load [off1] {sym1} (MOVVaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2)
533 && is32Bit(int64(off1)+int64(off2)) && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
534 (MOV(B|BU|H|HU|W|WU|V|F|D)load [off1+int32(off2)] {mergeSym(sym1,sym2)} ptr mem)
535
536 (MOV(B|H|W|V|F|D)store [off1] {sym1} (MOVVaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2)
537 && is32Bit(int64(off1)+int64(off2)) && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
538 (MOV(B|H|W|V|F|D)store [off1+int32(off2)] {mergeSym(sym1,sym2)} ptr val mem)
539
540 (MOV(B|H|W|V)storezero [off1] {sym1} (MOVVaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2)
541 && is32Bit(int64(off1)+int64(off2)) && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
542 (MOV(B|H|W|V)storezero [off1+int32(off2)] {mergeSym(sym1,sym2)} ptr mem)
543
544 // don't extend after proper load
545 (MOVBreg x:(MOVBload _ _)) => (MOVVreg x)
546 (MOVBUreg x:(MOVBUload _ _)) => (MOVVreg x)
547 (MOVHreg x:(MOVBload _ _)) => (MOVVreg x)
548 (MOVHreg x:(MOVBUload _ _)) => (MOVVreg x)
549 (MOVHreg x:(MOVHload _ _)) => (MOVVreg x)
550 (MOVHUreg x:(MOVBUload _ _)) => (MOVVreg x)
551 (MOVHUreg x:(MOVHUload _ _)) => (MOVVreg x)
552 (MOVWreg x:(MOVBload _ _)) => (MOVVreg x)
553 (MOVWreg x:(MOVBUload _ _)) => (MOVVreg x)
554 (MOVWreg x:(MOVHload _ _)) => (MOVVreg x)
555 (MOVWreg x:(MOVHUload _ _)) => (MOVVreg x)
556 (MOVWreg x:(MOVWload _ _)) => (MOVVreg x)
557 (MOVWUreg x:(MOVBUload _ _)) => (MOVVreg x)
558 (MOVWUreg x:(MOVHUload _ _)) => (MOVVreg x)
559 (MOVWUreg x:(MOVWUload _ _)) => (MOVVreg x)
560
561 // fold double extensions
562 (MOVBreg x:(MOVBreg _)) => (MOVVreg x)
563 (MOVBUreg x:(MOVBUreg _)) => (MOVVreg x)
564 (MOVHreg x:(MOVBreg _)) => (MOVVreg x)
565 (MOVHreg x:(MOVBUreg _)) => (MOVVreg x)
566 (MOVHreg x:(MOVHreg _)) => (MOVVreg x)
567 (MOVHUreg x:(MOVBUreg _)) => (MOVVreg x)
568 (MOVHUreg x:(MOVHUreg _)) => (MOVVreg x)
569 (MOVWreg x:(MOVBreg _)) => (MOVVreg x)
570 (MOVWreg x:(MOVBUreg _)) => (MOVVreg x)
571 (MOVWreg x:(MOVHreg _)) => (MOVVreg x)
572 (MOVWreg x:(MOVWreg _)) => (MOVVreg x)
573 (MOVWUreg x:(MOVBUreg _)) => (MOVVreg x)
574 (MOVWUreg x:(MOVHUreg _)) => (MOVVreg x)
575 (MOVWUreg x:(MOVWUreg _)) => (MOVVreg x)
576
577 // don't extend before store
578 (MOVBstore [off] {sym} ptr (MOVBreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
579 (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
580 (MOVBstore [off] {sym} ptr (MOVHreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
581 (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
582 (MOVBstore [off] {sym} ptr (MOVWreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
583 (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
584 (MOVHstore [off] {sym} ptr (MOVHreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
585 (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
586 (MOVHstore [off] {sym} ptr (MOVWreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
587 (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
588 (MOVWstore [off] {sym} ptr (MOVWreg x) mem) => (MOVWstore [off] {sym} ptr x mem)
589 (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVWstore [off] {sym} ptr x mem)
590
591 (MOVBstore [off] {sym} ptr (MOVVconst [0]) mem) => (MOVBstorezero [off] {sym} ptr mem)
592 (MOVHstore [off] {sym} ptr (MOVVconst [0]) mem) => (MOVHstorezero [off] {sym} ptr mem)
593 (MOVWstore [off] {sym} ptr (MOVVconst [0]) mem) => (MOVWstorezero [off] {sym} ptr mem)
594 (MOVVstore [off] {sym} ptr (MOVVconst [0]) mem) => (MOVVstorezero [off] {sym} ptr mem)
595
596 // register indexed load
597 (MOVVload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVVloadidx ptr idx mem)
598 (MOVWUload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVWUloadidx ptr idx mem)
599 (MOVWload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVWloadidx ptr idx mem)
600 (MOVHUload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVHUloadidx ptr idx mem)
601 (MOVHload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVHloadidx ptr idx mem)
602 (MOVBUload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVBUloadidx ptr idx mem)
603 (MOVBload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVBloadidx ptr idx mem)
604 (MOVFload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVFloadidx ptr idx mem)
605 (MOVDload [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVDloadidx ptr idx mem)
606 (MOVVloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVVload [int32(c)] ptr mem)
607 (MOVVloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVVload [int32(c)] ptr mem)
608 (MOVWUloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVWUload [int32(c)] ptr mem)
609 (MOVWUloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVWUload [int32(c)] ptr mem)
610 (MOVWloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVWload [int32(c)] ptr mem)
611 (MOVWloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVWload [int32(c)] ptr mem)
612 (MOVHUloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVHUload [int32(c)] ptr mem)
613 (MOVHUloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVHUload [int32(c)] ptr mem)
614 (MOVHloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVHload [int32(c)] ptr mem)
615 (MOVHloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVHload [int32(c)] ptr mem)
616 (MOVBUloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVBUload [int32(c)] ptr mem)
617 (MOVBUloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVBUload [int32(c)] ptr mem)
618 (MOVBloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVBload [int32(c)] ptr mem)
619 (MOVBloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVBload [int32(c)] ptr mem)
620 (MOVFloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVFload [int32(c)] ptr mem)
621 (MOVFloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVFload [int32(c)] ptr mem)
622 (MOVDloadidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVDload [int32(c)] ptr mem)
623 (MOVDloadidx (MOVVconst [c]) ptr mem) && is32Bit(c) => (MOVDload [int32(c)] ptr mem)
624
625 // register indexed store
626 (MOVVstore [off] {sym} (ADDV ptr idx) val mem) && off == 0 && sym == nil => (MOVVstoreidx ptr idx val mem)
627 (MOVWstore [off] {sym} (ADDV ptr idx) val mem) && off == 0 && sym == nil => (MOVWstoreidx ptr idx val mem)
628 (MOVHstore [off] {sym} (ADDV ptr idx) val mem) && off == 0 && sym == nil => (MOVHstoreidx ptr idx val mem)
629 (MOVBstore [off] {sym} (ADDV ptr idx) val mem) && off == 0 && sym == nil => (MOVBstoreidx ptr idx val mem)
630 (MOVFstore [off] {sym} (ADDV ptr idx) val mem) && off == 0 && sym == nil => (MOVFstoreidx ptr idx val mem)
631 (MOVDstore [off] {sym} (ADDV ptr idx) val mem) && off == 0 && sym == nil => (MOVDstoreidx ptr idx val mem)
632 (MOVVstoreidx ptr (MOVVconst [c]) val mem) && is32Bit(c) => (MOVVstore [int32(c)] ptr val mem)
633 (MOVVstoreidx (MOVVconst [c]) idx val mem) && is32Bit(c) => (MOVVstore [int32(c)] idx val mem)
634 (MOVWstoreidx ptr (MOVVconst [c]) val mem) && is32Bit(c) => (MOVWstore [int32(c)] ptr val mem)
635 (MOVWstoreidx (MOVVconst [c]) idx val mem) && is32Bit(c) => (MOVWstore [int32(c)] idx val mem)
636 (MOVHstoreidx ptr (MOVVconst [c]) val mem) && is32Bit(c) => (MOVHstore [int32(c)] ptr val mem)
637 (MOVHstoreidx (MOVVconst [c]) idx val mem) && is32Bit(c) => (MOVHstore [int32(c)] idx val mem)
638 (MOVBstoreidx ptr (MOVVconst [c]) val mem) && is32Bit(c) => (MOVBstore [int32(c)] ptr val mem)
639 (MOVBstoreidx (MOVVconst [c]) idx val mem) && is32Bit(c) => (MOVBstore [int32(c)] idx val mem)
640 (MOVFstoreidx ptr (MOVVconst [c]) val mem) && is32Bit(c) => (MOVFstore [int32(c)] ptr val mem)
641 (MOVFstoreidx (MOVVconst [c]) idx val mem) && is32Bit(c) => (MOVFstore [int32(c)] idx val mem)
642 (MOVDstoreidx ptr (MOVVconst [c]) val mem) && is32Bit(c) => (MOVDstore [int32(c)] ptr val mem)
643 (MOVDstoreidx (MOVVconst [c]) idx val mem) && is32Bit(c) => (MOVDstore [int32(c)] idx val mem)
644
645 // register indexed store zero
646 (MOVVstorezero [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVVstorezeroidx ptr idx mem)
647 (MOVWstorezero [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVWstorezeroidx ptr idx mem)
648 (MOVHstorezero [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVHstorezeroidx ptr idx mem)
649 (MOVBstorezero [off] {sym} (ADDV ptr idx) mem) && off == 0 && sym == nil => (MOVBstorezeroidx ptr idx mem)
650 (MOVVstoreidx ptr idx (MOVVconst [0]) mem) => (MOVVstorezeroidx ptr idx mem)
651 (MOVWstoreidx ptr idx (MOVVconst [0]) mem) => (MOVWstorezeroidx ptr idx mem)
652 (MOVHstoreidx ptr idx (MOVVconst [0]) mem) => (MOVHstorezeroidx ptr idx mem)
653 (MOVBstoreidx ptr idx (MOVVconst [0]) mem) => (MOVBstorezeroidx ptr idx mem)
654 (MOVVstorezeroidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVVstorezero [int32(c)] ptr mem)
655 (MOVVstorezeroidx (MOVVconst [c]) idx mem) && is32Bit(c) => (MOVVstorezero [int32(c)] idx mem)
656 (MOVWstorezeroidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVWstorezero [int32(c)] ptr mem)
657 (MOVWstorezeroidx (MOVVconst [c]) idx mem) && is32Bit(c) => (MOVWstorezero [int32(c)] idx mem)
658 (MOVHstorezeroidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVHstorezero [int32(c)] ptr mem)
659 (MOVHstorezeroidx (MOVVconst [c]) idx mem) && is32Bit(c) => (MOVHstorezero [int32(c)] idx mem)
660 (MOVBstorezeroidx ptr (MOVVconst [c]) mem) && is32Bit(c) => (MOVBstorezero [int32(c)] ptr mem)
661 (MOVBstorezeroidx (MOVVconst [c]) idx mem) && is32Bit(c) => (MOVBstorezero [int32(c)] idx mem)
662
663 // if a register move has only 1 use, just use the same register without emitting instruction
664 // MOVVnop doesn't emit instruction, only for ensuring the type.
665 (MOVVreg x) && x.Uses == 1 => (MOVVnop x)
666
667 // TODO: we should be able to get rid of MOVVnop all together.
668 // But for now, this is enough to get rid of lots of them.
669 (MOVVnop (MOVVconst [c])) => (MOVVconst [c])
670
671 // fold constant into arithmetic ops
672 (ADDV x (MOVVconst <t> [c])) && is32Bit(c) && !t.IsPtr() => (ADDVconst [c] x)
673 (SUBV x (MOVVconst [c])) && is32Bit(c) => (SUBVconst [c] x)
674 (AND x (MOVVconst [c])) && is32Bit(c) => (ANDconst [c] x)
675 (OR x (MOVVconst [c])) && is32Bit(c) => (ORconst [c] x)
676 (XOR x (MOVVconst [c])) && is32Bit(c) => (XORconst [c] x)
677 (NOR x (MOVVconst [c])) && is32Bit(c) => (NORconst [c] x)
678
679 (SLLV _ (MOVVconst [c])) && uint64(c)>=64 => (MOVVconst [0])
680 (SRLV _ (MOVVconst [c])) && uint64(c)>=64 => (MOVVconst [0])
681 (SRAV x (MOVVconst [c])) && uint64(c)>=64 => (SRAVconst x [63])
682 (SLLV x (MOVVconst [c])) => (SLLVconst x [c])
683 (SRLV x (MOVVconst [c])) => (SRLVconst x [c])
684 (SRAV x (MOVVconst [c])) => (SRAVconst x [c])
685 (ROTR x (MOVVconst [c])) => (ROTRconst x [c&31])
686 (ROTRV x (MOVVconst [c])) => (ROTRVconst x [c&63])
687
688 // If the shift amount is larger than the datasize(32, 16, 8), we can optimize to constant 0.
689 (MOVWUreg (SLLVconst [lc] x)) && lc >= 32 => (MOVVconst [0])
690 (MOVHUreg (SLLVconst [lc] x)) && lc >= 16 => (MOVVconst [0])
691 (MOVBUreg (SLLVconst [lc] x)) && lc >= 8 => (MOVVconst [0])
692
693 // After zero extension, the upper (64-datasize(32|16|8)) bits are zero, we can optimize to constant 0.
694 (SRLVconst [rc] (MOVWUreg x)) && rc >= 32 => (MOVVconst [0])
695 (SRLVconst [rc] (MOVHUreg x)) && rc >= 16 => (MOVVconst [0])
696 (SRLVconst [rc] (MOVBUreg x)) && rc >= 8 => (MOVVconst [0])
697
698 // mul by constant
699 (MULV x (MOVVconst [-1])) => (NEGV x)
700 (MULV _ (MOVVconst [0])) => (MOVVconst [0])
701 (MULV x (MOVVconst [1])) => x
702 (MULV x (MOVVconst [c])) && isPowerOfTwo(c) => (SLLVconst [log64(c)] x)
703
704 // div by constant
705 (DIVVU x (MOVVconst [1])) => x
706 (DIVVU x (MOVVconst [c])) && isPowerOfTwo(c) => (SRLVconst [log64(c)] x)
707 (REMVU _ (MOVVconst [1])) => (MOVVconst [0]) // mod
708 (REMVU x (MOVVconst [c])) && isPowerOfTwo(c) => (ANDconst [c-1] x) // mod
709
710 // FMA
711 (FMA ...) => (FMADDD ...)
712 ((ADD|SUB)F (MULF x y) z) && z.Block.Func.useFMA(v) => (FM(ADD|SUB)F x y z)
713 ((ADD|SUB)D (MULD x y) z) && z.Block.Func.useFMA(v) => (FM(ADD|SUB)D x y z)
714 // z - xy -> -(xy - z)
715 (SUBF z (MULF x y)) && z.Block.Func.useFMA(v) => (FNMSUBF x y z)
716 (SUBD z (MULD x y)) && z.Block.Func.useFMA(v) => (FNMSUBD x y z)
717 // z + (-xy) -> -(xy - z)
718 // z - (-xy) -> xy + z
719 ((ADD|SUB)F z (NEGF (MULF x y))) && z.Block.Func.useFMA(v) => (F(NMSUB|MADD)F x y z)
720 ((ADD|SUB)D z (NEGD (MULD x y))) && z.Block.Func.useFMA(v) => (F(NMSUB|MADD)D x y z)
721 // -xy - z -> -(xy + z)
722 (SUBF (NEGF (MULF x y)) z) && z.Block.Func.useFMA(v) => (FNMADDF x y z)
723 (SUBD (NEGD (MULD x y)) z) && z.Block.Func.useFMA(v) => (FNMADDD x y z)
724
725 // generic simplifications
726 (ADDV x (NEGV y)) => (SUBV x y)
727 (SUBV x x) => (MOVVconst [0])
728 (SUBV (MOVVconst [0]) x) => (NEGV x)
729 (AND x x) => x
730 (OR x x) => x
731 (XOR x x) => (MOVVconst [0])
732
733 // remove redundant *const ops
734 (ADDVconst [0] x) => x
735 (SUBVconst [0] x) => x
736 (ANDconst [0] _) => (MOVVconst [0])
737 (ANDconst [-1] x) => x
738 (ORconst [0] x) => x
739 (ORconst [-1] _) => (MOVVconst [-1])
740 (XORconst [0] x) => x
741 (XORconst [-1] x) => (NORconst [0] x)
742 (MASKEQZ (MOVVconst [0]) cond) => (MOVVconst [0])
743 (MASKNEZ (MOVVconst [0]) cond) => (MOVVconst [0])
744 (MASKEQZ x (MOVVconst [c])) && c == 0 => (MOVVconst [0])
745 (MASKEQZ x (MOVVconst [c])) && c != 0 => x
746
747 // generic constant folding
748 (ADDVconst [c] (MOVVconst [d])) => (MOVVconst [c+d])
749 (ADDVconst [c] (ADDVconst [d] x)) && is32Bit(c+d) => (ADDVconst [c+d] x)
750 (ADDVconst [c] (SUBVconst [d] x)) && is32Bit(c-d) => (ADDVconst [c-d] x)
751 (SUBVconst [c] (MOVVconst [d])) => (MOVVconst [d-c])
752 (SUBVconst [c] (SUBVconst [d] x)) && is32Bit(-c-d) => (ADDVconst [-c-d] x)
753 (SUBVconst [c] (ADDVconst [d] x)) && is32Bit(-c+d) => (ADDVconst [-c+d] x)
754 (SUBV (MOVVconst [c]) (NEGV (SUBVconst [d] x))) => (ADDVconst [c-d] x)
755 (SLLVconst [c] (MOVVconst [d])) => (MOVVconst [d<<uint64(c)])
756 (SRLVconst [c] (MOVVconst [d])) => (MOVVconst [int64(uint64(d)>>uint64(c))])
757 (SRAVconst [c] (MOVVconst [d])) => (MOVVconst [d>>uint64(c)])
758 (MULV (MOVVconst [c]) (MOVVconst [d])) => (MOVVconst [c*d])
759 (DIVV (MOVVconst [c]) (MOVVconst [d])) && d != 0 => (MOVVconst [c/d])
760 (DIVVU (MOVVconst [c]) (MOVVconst [d])) && d != 0 => (MOVVconst [int64(uint64(c)/uint64(d))])
761 (REMV (MOVVconst [c]) (MOVVconst [d])) && d != 0 => (MOVVconst [c%d]) // mod
762 (REMVU (MOVVconst [c]) (MOVVconst [d])) && d != 0 => (MOVVconst [int64(uint64(c)%uint64(d))]) // mod
763 (ANDconst [c] (MOVVconst [d])) => (MOVVconst [c&d])
764 (ANDconst [c] (ANDconst [d] x)) => (ANDconst [c&d] x)
765 (ORconst [c] (MOVVconst [d])) => (MOVVconst [c|d])
766 (ORconst [c] (ORconst [d] x)) && is32Bit(c|d) => (ORconst [c|d] x)
767 (XORconst [c] (MOVVconst [d])) => (MOVVconst [c^d])
768 (XORconst [c] (XORconst [d] x)) && is32Bit(c^d) => (XORconst [c^d] x)
769 (NORconst [c] (MOVVconst [d])) => (MOVVconst [^(c|d)])
770 (NEGV (MOVVconst [c])) => (MOVVconst [-c])
771 (MOVBreg (MOVVconst [c])) => (MOVVconst [int64(int8(c))])
772 (MOVBUreg (MOVVconst [c])) => (MOVVconst [int64(uint8(c))])
773 (MOVHreg (MOVVconst [c])) => (MOVVconst [int64(int16(c))])
774 (MOVHUreg (MOVVconst [c])) => (MOVVconst [int64(uint16(c))])
775 (MOVWreg (MOVVconst [c])) => (MOVVconst [int64(int32(c))])
776 (MOVWUreg (MOVVconst [c])) => (MOVVconst [int64(uint32(c))])
777 (MOVVreg (MOVVconst [c])) => (MOVVconst [c])
778
779 (MOVBUreg (ANDconst [c] x)) => (ANDconst [c&0xff] x)
780
781 // constant comparisons
782 (SGTconst [c] (MOVVconst [d])) && c>d => (MOVVconst [1])
783 (SGTconst [c] (MOVVconst [d])) && c<=d => (MOVVconst [0])
784 (SGTUconst [c] (MOVVconst [d])) && uint64(c)>uint64(d) => (MOVVconst [1])
785 (SGTUconst [c] (MOVVconst [d])) && uint64(c)<=uint64(d) => (MOVVconst [0])
786
787 // other known comparisons
788 (SGTconst [c] (MOVBreg _)) && 0x7f < c => (MOVVconst [1])
789 (SGTconst [c] (MOVBreg _)) && c <= -0x80 => (MOVVconst [0])
790 (SGTconst [c] (MOVBUreg _)) && 0xff < c => (MOVVconst [1])
791 (SGTconst [c] (MOVBUreg _)) && c < 0 => (MOVVconst [0])
792 (SGTUconst [c] (MOVBUreg _)) && 0xff < uint64(c) => (MOVVconst [1])
793 (SGTconst [c] (MOVHreg _)) && 0x7fff < c => (MOVVconst [1])
794 (SGTconst [c] (MOVHreg _)) && c <= -0x8000 => (MOVVconst [0])
795 (SGTconst [c] (MOVHUreg _)) && 0xffff < c => (MOVVconst [1])
796 (SGTconst [c] (MOVHUreg _)) && c < 0 => (MOVVconst [0])
797 (SGTUconst [c] (MOVHUreg _)) && 0xffff < uint64(c) => (MOVVconst [1])
798 (SGTconst [c] (MOVWUreg _)) && c < 0 => (MOVVconst [0])
799 (SGTconst [c] (ANDconst [m] _)) && 0 <= m && m < c => (MOVVconst [1])
800 (SGTUconst [c] (ANDconst [m] _)) && uint64(m) < uint64(c) => (MOVVconst [1])
801 (SGTconst [c] (SRLVconst _ [d])) && 0 <= c && 0 < d && d <= 63 && 0xffffffffffffffff>>uint64(d) < uint64(c) => (MOVVconst [1])
802 (SGTUconst [c] (SRLVconst _ [d])) && 0 < d && d <= 63 && 0xffffffffffffffff>>uint64(d) < uint64(c) => (MOVVconst [1])
803
804 // SGT/SGTU with known outcomes.
805 (SGT x x) => (MOVVconst [0])
806 (SGTU x x) => (MOVVconst [0])
807
808 // Optimizations
809
810 // Absorb boolean tests into block
811 (NE (FPFlagTrue cmp) yes no) => (FPT cmp yes no)
812 (NE (FPFlagFalse cmp) yes no) => (FPF cmp yes no)
813 (EQ (FPFlagTrue cmp) yes no) => (FPF cmp yes no)
814 (EQ (FPFlagFalse cmp) yes no) => (FPT cmp yes no)
815 (NE (XORconst [1] cmp:(SGT _ _)) yes no) => (EQ cmp yes no)
816 (NE (XORconst [1] cmp:(SGTU _ _)) yes no) => (EQ cmp yes no)
817 (NE (XORconst [1] cmp:(SGTconst _)) yes no) => (EQ cmp yes no)
818 (NE (XORconst [1] cmp:(SGTUconst _)) yes no) => (EQ cmp yes no)
819 (EQ (XORconst [1] cmp:(SGT _ _)) yes no) => (NE cmp yes no)
820 (EQ (XORconst [1] cmp:(SGTU _ _)) yes no) => (NE cmp yes no)
821 (EQ (XORconst [1] cmp:(SGTconst _)) yes no) => (NE cmp yes no)
822 (EQ (XORconst [1] cmp:(SGTUconst _)) yes no) => (NE cmp yes no)
823 (NE (SGTUconst [1] x) yes no) => (EQ x yes no)
824 (EQ (SGTUconst [1] x) yes no) => (NE x yes no)
825 (NE (SGTU x (MOVVconst [0])) yes no) => (NE x yes no)
826 (EQ (SGTU x (MOVVconst [0])) yes no) => (EQ x yes no)
827 (NE (SGTconst [0] x) yes no) => (LTZ x yes no)
828 (EQ (SGTconst [0] x) yes no) => (GEZ x yes no)
829 (NE (SGT x (MOVVconst [0])) yes no) => (GTZ x yes no)
830 (EQ (SGT x (MOVVconst [0])) yes no) => (LEZ x yes no)
831
832 (EQ (SGTU (MOVVconst [c]) y) yes no) && c >= -2048 && c <= 2047 => (EQ (SGTUconst [c] y) yes no)
833 (NE (SGTU (MOVVconst [c]) y) yes no) && c >= -2048 && c <= 2047 => (NE (SGTUconst [c] y) yes no)
834 (EQ (SUBV x y) yes no) => (BEQ x y yes no)
835 (NE (SUBV x y) yes no) => (BNE x y yes no)
836 (EQ (SGT x y) yes no) => (BGE y x yes no)
837 (NE (SGT x y) yes no) => (BLT y x yes no)
838 (EQ (SGTU x y) yes no) => (BGEU y x yes no)
839 (NE (SGTU x y) yes no) => (BLTU y x yes no)
840
841 // absorb constants into branches
842 (EQ (MOVVconst [0]) yes no) => (First yes no)
843 (EQ (MOVVconst [c]) yes no) && c != 0 => (First no yes)
844 (NE (MOVVconst [0]) yes no) => (First no yes)
845 (NE (MOVVconst [c]) yes no) && c != 0 => (First yes no)
846 (LTZ (MOVVconst [c]) yes no) && c < 0 => (First yes no)
847 (LTZ (MOVVconst [c]) yes no) && c >= 0 => (First no yes)
848 (LEZ (MOVVconst [c]) yes no) && c <= 0 => (First yes no)
849 (LEZ (MOVVconst [c]) yes no) && c > 0 => (First no yes)
850 (GTZ (MOVVconst [c]) yes no) && c > 0 => (First yes no)
851 (GTZ (MOVVconst [c]) yes no) && c <= 0 => (First no yes)
852 (GEZ (MOVVconst [c]) yes no) && c >= 0 => (First yes no)
853 (GEZ (MOVVconst [c]) yes no) && c < 0 => (First no yes)
854
855 // Arch-specific inlining for small or disjoint runtime.memmove
856 // Match post-lowering calls, register version.
857 (SelectN [0] call:(CALLstatic {sym} dst src (MOVVconst [sz]) mem))
858 && sz >= 0
859 && isSameCall(sym, "runtime.memmove")
860 && call.Uses == 1
861 && isInlinableMemmove(dst, src, sz, config)
862 && clobber(call)
863 => (Move [sz] dst src mem)
864
View as plain text