1 // Copyright 2016 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) ...) => (ADD ...)
6 (Add(32|64)F ...) => (FADD(S|D) ...)
7
8 (Sub(Ptr|64|32|16|8) ...) => (SUB ...)
9 (Sub(32|64)F ...) => (FSUB(S|D) ...)
10
11 (Mul64 ...) => (MUL ...)
12 (Mul(32|16|8) ...) => (MULW ...)
13 (Mul(32|64)F ...) => (FMUL(S|D) ...)
14
15 (Hmul64 ...) => (MULH ...)
16 (Hmul64u ...) => (UMULH ...)
17 (Hmul32 x y) => (SRAconst (MULL <typ.Int64> x y) [32])
18 (Hmul32u x y) => (SRAconst (UMULL <typ.UInt64> x y) [32])
19 (Select0 (Mul64uhilo x y)) => (UMULH x y)
20 (Select1 (Mul64uhilo x y)) => (MUL x y)
21
22 (Div64 [false] x y) => (DIV x y)
23 (Div32 [false] x y) => (DIVW x y)
24 (Div16 [false] x y) => (DIVW (SignExt16to32 x) (SignExt16to32 y))
25 (Div16u x y) => (UDIVW (ZeroExt16to32 x) (ZeroExt16to32 y))
26 (Div8 x y) => (DIVW (SignExt8to32 x) (SignExt8to32 y))
27 (Div8u x y) => (UDIVW (ZeroExt8to32 x) (ZeroExt8to32 y))
28 (Div64u ...) => (UDIV ...)
29 (Div32u ...) => (UDIVW ...)
30 (Div32F ...) => (FDIVS ...)
31 (Div64F ...) => (FDIVD ...)
32
33 (Mod64 x y) => (MOD x y)
34 (Mod32 x y) => (MODW x y)
35 (Mod64u ...) => (UMOD ...)
36 (Mod32u ...) => (UMODW ...)
37 (Mod(16|8) x y) => (MODW (SignExt(16|8)to32 x) (SignExt(16|8)to32 y))
38 (Mod(16|8)u x y) => (UMODW (ZeroExt(16|8)to32 x) (ZeroExt(16|8)to32 y))
39
40 // (x + y) / 2 with x>=y => (x - y) / 2 + y
41 (Avg64u <t> x y) => (ADD (SRLconst <t> (SUB <t> x y) [1]) y)
42
43 (And(64|32|16|8) ...) => (AND ...)
44 (Or(64|32|16|8) ...) => (OR ...)
45 (Xor(64|32|16|8) ...) => (XOR ...)
46
47 // unary ops
48 (Neg(64|32|16|8) ...) => (NEG ...)
49 (Neg(32|64)F ...) => (FNEG(S|D) ...)
50 (Com(64|32|16|8) ...) => (MVN ...)
51
52 // math package intrinsics
53 (Abs ...) => (FABSD ...)
54 (Sqrt ...) => (FSQRTD ...)
55 (Ceil ...) => (FRINTPD ...)
56 (Floor ...) => (FRINTMD ...)
57 (Round ...) => (FRINTAD ...)
58 (RoundToEven ...) => (FRINTND ...)
59 (Trunc ...) => (FRINTZD ...)
60 (FMA x y z) => (FMADDD z x y)
61
62 (Sqrt32 ...) => (FSQRTS ...)
63
64 (Min(64|32)F ...) => (FMIN(D|S) ...)
65 (Max(64|32)F ...) => (FMAX(D|S) ...)
66
67 // lowering rotates
68 // we do rotate detection in generic rules, if the following rules need to be changed, check generic rules first.
69 (RotateLeft8 <t> x (MOVDconst [c])) => (Or8 (Lsh8x64 <t> x (MOVDconst [c&7])) (Rsh8Ux64 <t> x (MOVDconst [-c&7])))
70 (RotateLeft8 <t> x y) => (OR <t> (SLL <t> x (ANDconst <typ.Int64> [7] y)) (SRL <t> (ZeroExt8to64 x) (ANDconst <typ.Int64> [7] (NEG <typ.Int64> y))))
71 (RotateLeft16 <t> x (MOVDconst [c])) => (Or16 (Lsh16x64 <t> x (MOVDconst [c&15])) (Rsh16Ux64 <t> x (MOVDconst [-c&15])))
72 (RotateLeft16 <t> x y) => (RORW <t> (ORshiftLL <typ.UInt32> (ZeroExt16to32 x) (ZeroExt16to32 x) [16]) (NEG <typ.Int64> y))
73 (RotateLeft32 x y) => (RORW x (NEG <y.Type> y))
74 (RotateLeft64 x y) => (ROR x (NEG <y.Type> y))
75
76 (Ctz(64|32|16|8)NonZero ...) => (Ctz(64|32|32|32) ...)
77
78 (Ctz64 <t> x) => (CLZ (RBIT <t> x))
79 (Ctz32 <t> x) => (CLZW (RBITW <t> x))
80 (Ctz16 <t> x) => (CLZW <t> (RBITW <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x)))
81 (Ctz8 <t> x) => (CLZW <t> (RBITW <typ.UInt32> (ORconst <typ.UInt32> [0x100] x)))
82
83 (PopCount64 <t> x) => (FMOVDfpgp <t> (VUADDLV <typ.Float64> (VCNT <typ.Float64> (FMOVDgpfp <typ.Float64> x))))
84 (PopCount32 <t> x) => (FMOVDfpgp <t> (VUADDLV <typ.Float64> (VCNT <typ.Float64> (FMOVDgpfp <typ.Float64> (ZeroExt32to64 x)))))
85 (PopCount16 <t> x) => (FMOVDfpgp <t> (VUADDLV <typ.Float64> (VCNT <typ.Float64> (FMOVDgpfp <typ.Float64> (ZeroExt16to64 x)))))
86
87 // Load args directly into the register class where it will be used.
88 (FMOVDgpfp <t> (Arg [off] {sym})) => @b.Func.Entry (Arg <t> [off] {sym})
89 (FMOVDfpgp <t> (Arg [off] {sym})) => @b.Func.Entry (Arg <t> [off] {sym})
90
91 // Similarly for stores, if we see a store after FPR <=> GPR move, then redirect store to use the other register set.
92 (MOVDstore [off] {sym} ptr (FMOVDfpgp val) mem) => (FMOVDstore [off] {sym} ptr val mem)
93 (FMOVDstore [off] {sym} ptr (FMOVDgpfp val) mem) => (MOVDstore [off] {sym} ptr val mem)
94 (MOVWstore [off] {sym} ptr (FMOVSfpgp val) mem) => (FMOVSstore [off] {sym} ptr val mem)
95 (FMOVSstore [off] {sym} ptr (FMOVSgpfp val) mem) => (MOVWstore [off] {sym} ptr val mem)
96
97 // float <=> int register moves, with no conversion.
98 // These come up when compiling math.{Float64bits, Float64frombits, Float32bits, Float32frombits}.
99 (MOVDload [off] {sym} ptr (FMOVDstore [off] {sym} ptr val _)) => (FMOVDfpgp val)
100 (FMOVDload [off] {sym} ptr (MOVDstore [off] {sym} ptr val _)) => (FMOVDgpfp val)
101 (MOVWUload [off] {sym} ptr (FMOVSstore [off] {sym} ptr val _)) => (FMOVSfpgp val)
102 (FMOVSload [off] {sym} ptr (MOVWstore [off] {sym} ptr val _)) => (FMOVSgpfp val)
103
104 (BitLen64 x) => (SUB (MOVDconst [64]) (CLZ <typ.Int> x))
105 (BitLen32 x) => (SUB (MOVDconst [32]) (CLZW <typ.Int> x))
106 (BitLen(16|8) x) => (BitLen64 (ZeroExt(16|8)to64 x))
107
108 (Bswap64 ...) => (REV ...)
109 (Bswap32 ...) => (REVW ...)
110 (Bswap16 ...) => (REV16W ...)
111
112 (BitRev64 ...) => (RBIT ...)
113 (BitRev32 ...) => (RBITW ...)
114 (BitRev16 x) => (SRLconst [48] (RBIT <typ.UInt64> x))
115 (BitRev8 x) => (SRLconst [56] (RBIT <typ.UInt64> x))
116
117 // In fact, UMOD will be translated into UREM instruction, and UREM is originally translated into
118 // UDIV and MSUB instructions. But if there is already an identical UDIV instruction just before or
119 // after UREM (case like quo, rem := z/y, z%y), then the second UDIV instruction becomes redundant.
120 // The purpose of this rule is to have this extra UDIV instruction removed in CSE pass.
121 (UMOD <typ.UInt64> x y) => (MSUB <typ.UInt64> x y (UDIV <typ.UInt64> x y))
122 (UMODW <typ.UInt32> x y) => (MSUBW <typ.UInt32> x y (UDIVW <typ.UInt32> x y))
123
124 // 64-bit addition with carry.
125 (Select0 (Add64carry x y c)) => (Select0 <typ.UInt64> (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] c))))
126 (Select1 (Add64carry x y c)) => (ADCzerocarry <typ.UInt64> (Select1 <types.TypeFlags> (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] c)))))
127
128 // 64-bit subtraction with borrowing.
129 (Select0 (Sub64borrow x y bo)) => (Select0 <typ.UInt64> (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags bo))))
130 (Select1 (Sub64borrow x y bo)) => (NEG <typ.UInt64> (NGCzerocarry <typ.UInt64> (Select1 <types.TypeFlags> (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags bo))))))
131
132 // boolean ops -- booleans are represented with 0=false, 1=true
133 (AndB ...) => (AND ...)
134 (OrB ...) => (OR ...)
135 (EqB x y) => (XOR (MOVDconst [1]) (XOR <typ.Bool> x y))
136 (NeqB ...) => (XOR ...)
137 (Not x) => (XOR (MOVDconst [1]) x)
138
139 // shifts
140 // hardware instruction uses only the low 6 bits of the shift
141 // we compare to 64 to ensure Go semantics for large shifts
142 // Rules about rotates with non-const shift are based on the following rules,
143 // if the following rules change, please also modify the rules based on them.
144
145 // check shiftIsBounded first, if shift value is proved to be valid then we
146 // can do the shift directly.
147 // left shift
148 (Lsh32x(64|32|16|8) ...) => (Lsh64x(64|32|16|8) ...)
149 (Lsh16x(64|32|16|8) ...) => (Lsh64x(64|32|16|8) ...)
150 (Lsh8x(64|32|16|8) ...) => (Lsh64x(64|32|16|8) ...)
151
152 (Lsh64x(64|32|16|8) <t> x y) && shiftIsBounded(v) => (SLL <t> x y)
153
154 // signed right shift
155 (Rsh32x(64|32|16|8) <t> [bounded] x y) => (Rsh64x(64|32|16|8) <t> [bounded] (SignExt32to64 x) y)
156 (Rsh16x(64|32|16|8) <t> [bounded] x y) => (Rsh64x(64|32|16|8) <t> [bounded] (SignExt16to64 x) y)
157 (Rsh8x(64|32|16|8) <t> [bounded] x y) => (Rsh64x(64|32|16|8) <t> [bounded] (SignExt8to64 x) y)
158
159 (Rsh64x(64|32|16|8) <t> x y) && shiftIsBounded(v) => (SRA <t> x y)
160
161 // unsigned right shift
162 (Rsh32Ux(64|32|16|8) <t> [bounded] x y) => (Rsh64Ux(64|32|16|8) <t> [bounded] (ZeroExt32to64 x) y)
163 (Rsh16Ux(64|32|16|8) <t> [bounded] x y) => (Rsh64Ux(64|32|16|8) <t> [bounded] (ZeroExt16to64 x) y)
164 (Rsh8Ux(64|32|16|8) <t> [bounded] x y) => (Rsh64Ux(64|32|16|8) <t> [bounded] (ZeroExt8to64 x) y)
165
166 (Rsh64Ux(64|32|16|8) <t> x y) && shiftIsBounded(v) => (SRL <t> x y)
167
168 // shift value may be out of range, use CMP + CSEL instead
169 (Lsh64x64 <t> x y) && !shiftIsBounded(v) => (CSEL [OpARM64LessThanU] (SLL <t> x y) (Const64 <t> [0]) (CMPconst [64] y))
170 (Lsh64x32 <t> x y) && !shiftIsBounded(v) => (CSEL [OpARM64LessThanU] (SLL <t> x y) (Const64 <t> [0]) (CMPWconst [64] y))
171 (Lsh64x(16|8) <t> [bounded] x y) && !shiftIsBounded(v) => (Lsh64x32 <t> [bounded] x (ZeroExt(16|8)to32 y))
172
173 (Rsh64Ux64 <t> x y) && !shiftIsBounded(v) => (CSEL [OpARM64LessThanU] (SRL <t> x y) (Const64 <t> [0]) (CMPconst [64] y))
174 (Rsh64Ux32 <t> x y) && !shiftIsBounded(v) => (CSEL [OpARM64LessThanU] (SRL <t> x y) (Const64 <t> [0]) (CMPWconst [64] y))
175 (Rsh64Ux(16|8) <t> [bounded] x y) && !shiftIsBounded(v) => (Rsh64Ux32 <t> [bounded] x (ZeroExt(16|8)to32 y))
176
177 (Rsh64x64 <t> x y) && !shiftIsBounded(v) => (SRA x (CSEL [OpARM64LessThanU] <y.Type> y (Const64 <y.Type> [63]) (CMPconst [64] y)))
178 (Rsh64x32 <t> x y) && !shiftIsBounded(v) => (SRA x (CSEL [OpARM64LessThanU] <y.Type> y (Const64 <y.Type> [63]) (CMPWconst [64] y)))
179 (Rsh64x(16|8) <t> [bounded] x y) && !shiftIsBounded(v) => (Rsh64x32 <t> [bounded] x (ZeroExt(16|8)to32 y))
180
181 // constants
182 (Const(64|32|16|8) [val]) => (MOVDconst [int64(val)])
183 (Const(32|64)F [val]) => (FMOV(S|D)const [float64(val)])
184 (ConstNil) => (MOVDconst [0])
185 (ConstBool [t]) => (MOVDconst [b2i(t)])
186
187 (Slicemask <t> x) => (SRAconst (NEG <t> x) [63])
188
189 // truncations
190 // Because we ignore high parts of registers, truncates are just copies.
191 (Trunc16to8 ...) => (Copy ...)
192 (Trunc32to8 ...) => (Copy ...)
193 (Trunc32to16 ...) => (Copy ...)
194 (Trunc64to8 ...) => (Copy ...)
195 (Trunc64to16 ...) => (Copy ...)
196 (Trunc64to32 ...) => (Copy ...)
197
198 // Zero-/Sign-extensions
199 (ZeroExt8to16 ...) => (MOVBUreg ...)
200 (ZeroExt8to32 ...) => (MOVBUreg ...)
201 (ZeroExt16to32 ...) => (MOVHUreg ...)
202 (ZeroExt8to64 ...) => (MOVBUreg ...)
203 (ZeroExt16to64 ...) => (MOVHUreg ...)
204 (ZeroExt32to64 ...) => (MOVWUreg ...)
205
206 (SignExt8to16 ...) => (MOVBreg ...)
207 (SignExt8to32 ...) => (MOVBreg ...)
208 (SignExt16to32 ...) => (MOVHreg ...)
209 (SignExt8to64 ...) => (MOVBreg ...)
210 (SignExt16to64 ...) => (MOVHreg ...)
211 (SignExt32to64 ...) => (MOVWreg ...)
212
213 // float <=> int conversion
214 (Cvt32to32F ...) => (SCVTFWS ...)
215 (Cvt32to64F ...) => (SCVTFWD ...)
216 (Cvt64to32F ...) => (SCVTFS ...)
217 (Cvt64to64F ...) => (SCVTFD ...)
218 (Cvt32Uto32F ...) => (UCVTFWS ...)
219 (Cvt32Uto64F ...) => (UCVTFWD ...)
220 (Cvt64Uto32F ...) => (UCVTFS ...)
221 (Cvt64Uto64F ...) => (UCVTFD ...)
222 (Cvt32Fto32 ...) => (FCVTZSSW ...)
223 (Cvt64Fto32 ...) => (FCVTZSDW ...)
224 (Cvt32Fto64 ...) => (FCVTZSS ...)
225 (Cvt64Fto64 ...) => (FCVTZSD ...)
226 (Cvt32Fto32U ...) => (FCVTZUSW ...)
227 (Cvt64Fto32U ...) => (FCVTZUDW ...)
228 (Cvt32Fto64U ...) => (FCVTZUS ...)
229 (Cvt64Fto64U ...) => (FCVTZUD ...)
230 (Cvt32Fto64F ...) => (FCVTSD ...)
231 (Cvt64Fto32F ...) => (FCVTDS ...)
232
233 (CvtBoolToUint8 ...) => (Copy ...)
234
235 (Round32F ...) => (LoweredRound32F ...)
236 (Round64F ...) => (LoweredRound64F ...)
237
238 // comparisons
239 (Eq8 x y) => (Equal (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
240 (Eq16 x y) => (Equal (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
241 (Eq32 x y) => (Equal (CMPW x y))
242 (Eq64 x y) => (Equal (CMP x y))
243 (EqPtr x y) => (Equal (CMP x y))
244 (Eq32F x y) => (Equal (FCMPS x y))
245 (Eq64F x y) => (Equal (FCMPD x y))
246
247 (Neq8 x y) => (NotEqual (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
248 (Neq16 x y) => (NotEqual (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
249 (Neq32 x y) => (NotEqual (CMPW x y))
250 (Neq64 x y) => (NotEqual (CMP x y))
251 (NeqPtr x y) => (NotEqual (CMP x y))
252 (Neq(32|64)F x y) => (NotEqual (FCMP(S|D) x y))
253
254 (Less(8|16) x y) => (LessThan (CMPW (SignExt(8|16)to32 x) (SignExt(8|16)to32 y)))
255 (Less32 x y) => (LessThan (CMPW x y))
256 (Less64 x y) => (LessThan (CMP x y))
257
258 // Set condition flags for floating-point comparisons "x < y"
259 // and "x <= y". Because if either or both of the operands are
260 // NaNs, all three of (x < y), (x == y) and (x > y) are false,
261 // and ARM Manual says FCMP instruction sets PSTATE.<N,Z,C,V>
262 // of this case to (0, 0, 1, 1).
263 (Less32F x y) => (LessThanF (FCMPS x y))
264 (Less64F x y) => (LessThanF (FCMPD x y))
265
266 // For an unsigned integer x, the following rules are useful when combining branch
267 // 0 < x => x != 0
268 // x <= 0 => x == 0
269 // x < 1 => x == 0
270 // 1 <= x => x != 0
271 (Less(8U|16U|32U|64U) zero:(MOVDconst [0]) x) => (Neq(8|16|32|64) zero x)
272 (Leq(8U|16U|32U|64U) x zero:(MOVDconst [0])) => (Eq(8|16|32|64) x zero)
273 (Less(8U|16U|32U|64U) x (MOVDconst [1])) => (Eq(8|16|32|64) x (MOVDconst [0]))
274 (Leq(8U|16U|32U|64U) (MOVDconst [1]) x) => (Neq(8|16|32|64) (MOVDconst [0]) x)
275
276 (Less8U x y) => (LessThanU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
277 (Less16U x y) => (LessThanU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
278 (Less32U x y) => (LessThanU (CMPW x y))
279 (Less64U x y) => (LessThanU (CMP x y))
280
281 (Leq8 x y) => (LessEqual (CMPW (SignExt8to32 x) (SignExt8to32 y)))
282 (Leq16 x y) => (LessEqual (CMPW (SignExt16to32 x) (SignExt16to32 y)))
283 (Leq32 x y) => (LessEqual (CMPW x y))
284 (Leq64 x y) => (LessEqual (CMP x y))
285
286 // Refer to the comments for op Less64F above.
287 (Leq32F x y) => (LessEqualF (FCMPS x y))
288 (Leq64F x y) => (LessEqualF (FCMPD x y))
289
290 (Leq8U x y) => (LessEqualU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
291 (Leq16U x y) => (LessEqualU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
292 (Leq32U x y) => (LessEqualU (CMPW x y))
293 (Leq64U x y) => (LessEqualU (CMP x y))
294
295 // Optimize comparison between a floating-point value and 0.0 with "FCMP $(0.0), Fn"
296 (FCMPS x (FMOVSconst [0])) => (FCMPS0 x)
297 (FCMPS (FMOVSconst [0]) x) => (InvertFlags (FCMPS0 x))
298 (FCMPD x (FMOVDconst [0])) => (FCMPD0 x)
299 (FCMPD (FMOVDconst [0]) x) => (InvertFlags (FCMPD0 x))
300
301 // CSEL needs a flag-generating argument. Synthesize a TSTW if necessary.
302 (CondSelect x y boolval) && flagArg(boolval) != nil => (CSEL [boolval.Op] x y flagArg(boolval))
303 (CondSelect x y boolval) && flagArg(boolval) == nil => (CSEL [OpARM64NotEqual] x y (TSTWconst [1] boolval))
304
305 (OffPtr [off] ptr:(SP)) && is32Bit(off) => (MOVDaddr [int32(off)] ptr)
306 (OffPtr [off] ptr) => (ADDconst [off] ptr)
307
308 (Addr {sym} base) => (MOVDaddr {sym} base)
309 (LocalAddr <t> {sym} base mem) && t.Elem().HasPointers() => (MOVDaddr {sym} (SPanchored base mem))
310 (LocalAddr <t> {sym} base _) && !t.Elem().HasPointers() => (MOVDaddr {sym} base)
311
312 // loads
313 (Load <t> ptr mem) && t.IsBoolean() => (MOVBUload ptr mem)
314 (Load <t> ptr mem) && (is8BitInt(t) && t.IsSigned()) => (MOVBload ptr mem)
315 (Load <t> ptr mem) && (is8BitInt(t) && !t.IsSigned()) => (MOVBUload ptr mem)
316 (Load <t> ptr mem) && (is16BitInt(t) && t.IsSigned()) => (MOVHload ptr mem)
317 (Load <t> ptr mem) && (is16BitInt(t) && !t.IsSigned()) => (MOVHUload ptr mem)
318 (Load <t> ptr mem) && (is32BitInt(t) && t.IsSigned()) => (MOVWload ptr mem)
319 (Load <t> ptr mem) && (is32BitInt(t) && !t.IsSigned()) => (MOVWUload ptr mem)
320 (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) => (MOVDload ptr mem)
321 (Load <t> ptr mem) && is32BitFloat(t) => (FMOVSload ptr mem)
322 (Load <t> ptr mem) && is64BitFloat(t) => (FMOVDload ptr mem)
323 (Load <t> ptr mem) && t.Size() == 16 => (FMOVQload ptr mem)
324
325 // stores
326 (Store {t} ptr val mem) && t.Size() == 1 => (MOVBstore ptr val mem)
327 (Store {t} ptr val mem) && t.Size() == 2 => (MOVHstore ptr val mem)
328 (Store {t} ptr val mem) && t.Size() == 4 && !t.IsFloat() => (MOVWstore ptr val mem)
329 (Store {t} ptr val mem) && t.Size() == 8 && !t.IsFloat() => (MOVDstore ptr val mem)
330 (Store {t} ptr val mem) && t.Size() == 4 && t.IsFloat() => (FMOVSstore ptr val mem)
331 (Store {t} ptr val mem) && t.Size() == 8 && t.IsFloat() => (FMOVDstore ptr val mem)
332 (Store {t} ptr val mem) && t.Size() == 16 => (FMOVQstore ptr val mem)
333
334 // zeroing
335 (Zero [0] _ mem) => mem
336 (Zero [1] ptr mem) => (MOVBstore ptr (MOVDconst [0]) mem)
337 (Zero [2] ptr mem) => (MOVHstore ptr (MOVDconst [0]) mem)
338 (Zero [4] ptr mem) => (MOVWstore ptr (MOVDconst [0]) mem)
339 (Zero [3] ptr mem) =>
340 (MOVBstore [2] ptr (MOVDconst [0])
341 (MOVHstore ptr (MOVDconst [0]) mem))
342 (Zero [5] ptr mem) =>
343 (MOVBstore [4] ptr (MOVDconst [0])
344 (MOVWstore ptr (MOVDconst [0]) mem))
345 (Zero [6] ptr mem) =>
346 (MOVHstore [4] ptr (MOVDconst [0])
347 (MOVWstore ptr (MOVDconst [0]) mem))
348 (Zero [7] ptr mem) =>
349 (MOVWstore [3] ptr (MOVDconst [0])
350 (MOVWstore ptr (MOVDconst [0]) mem))
351 (Zero [8] ptr mem) => (MOVDstore ptr (MOVDconst [0]) mem)
352 (Zero [9] ptr mem) =>
353 (MOVBstore [8] ptr (MOVDconst [0])
354 (MOVDstore ptr (MOVDconst [0]) mem))
355 (Zero [10] ptr mem) =>
356 (MOVHstore [8] ptr (MOVDconst [0])
357 (MOVDstore ptr (MOVDconst [0]) mem))
358 (Zero [11] ptr mem) =>
359 (MOVDstore [3] ptr (MOVDconst [0])
360 (MOVDstore ptr (MOVDconst [0]) mem))
361 (Zero [12] ptr mem) =>
362 (MOVWstore [8] ptr (MOVDconst [0])
363 (MOVDstore ptr (MOVDconst [0]) mem))
364 (Zero [13] ptr mem) =>
365 (MOVDstore [5] ptr (MOVDconst [0])
366 (MOVDstore ptr (MOVDconst [0]) mem))
367 (Zero [14] ptr mem) =>
368 (MOVDstore [6] ptr (MOVDconst [0])
369 (MOVDstore ptr (MOVDconst [0]) mem))
370 (Zero [15] ptr mem) =>
371 (MOVDstore [7] ptr (MOVDconst [0])
372 (MOVDstore ptr (MOVDconst [0]) mem))
373 (Zero [16] ptr mem) =>
374 (STP [0] ptr (MOVDconst [0]) (MOVDconst [0]) mem)
375
376 (Zero [s] ptr mem) && s > 16 && s < 192 => (LoweredZero [s] ptr mem)
377 (Zero [s] ptr mem) && s >= 192 => (LoweredZeroLoop [s] ptr mem)
378
379 // moves
380 (Move [0] _ _ mem) => mem
381 (Move [1] dst src mem) => (MOVBstore dst (MOVBUload src mem) mem)
382 (Move [2] dst src mem) => (MOVHstore dst (MOVHUload src mem) mem)
383 (Move [3] dst src mem) =>
384 (MOVBstore [2] dst (MOVBUload [2] src mem)
385 (MOVHstore dst (MOVHUload src mem) mem))
386 (Move [4] dst src mem) => (MOVWstore dst (MOVWUload src mem) mem)
387 (Move [5] dst src mem) =>
388 (MOVBstore [4] dst (MOVBUload [4] src mem)
389 (MOVWstore dst (MOVWUload src mem) mem))
390 (Move [6] dst src mem) =>
391 (MOVHstore [4] dst (MOVHUload [4] src mem)
392 (MOVWstore dst (MOVWUload src mem) mem))
393 (Move [7] dst src mem) =>
394 (MOVWstore [3] dst (MOVWUload [3] src mem)
395 (MOVWstore dst (MOVWUload src mem) mem))
396 (Move [8] dst src mem) => (MOVDstore dst (MOVDload src mem) mem)
397 (Move [9] dst src mem) =>
398 (MOVBstore [8] dst (MOVBUload [8] src mem)
399 (MOVDstore dst (MOVDload src mem) mem))
400 (Move [10] dst src mem) =>
401 (MOVHstore [8] dst (MOVHUload [8] src mem)
402 (MOVDstore dst (MOVDload src mem) mem))
403 (Move [11] dst src mem) =>
404 (MOVDstore [3] dst (MOVDload [3] src mem)
405 (MOVDstore dst (MOVDload src mem) mem))
406 (Move [12] dst src mem) =>
407 (MOVWstore [8] dst (MOVWUload [8] src mem)
408 (MOVDstore dst (MOVDload src mem) mem))
409 (Move [13] dst src mem) =>
410 (MOVDstore [5] dst (MOVDload [5] src mem)
411 (MOVDstore dst (MOVDload src mem) mem))
412 (Move [14] dst src mem) =>
413 (MOVDstore [6] dst (MOVDload [6] src mem)
414 (MOVDstore dst (MOVDload src mem) mem))
415 (Move [15] dst src mem) =>
416 (MOVDstore [7] dst (MOVDload [7] src mem)
417 (MOVDstore dst (MOVDload src mem) mem))
418 (Move [16] dst src mem) => (FMOVQstore dst (FMOVQload src mem) mem)
419
420 (Move [s] dst src mem) && s > 16 && s <= 24 =>
421 (MOVDstore [int32(s-8)] dst (MOVDload [int32(s-8)] src mem)
422 (FMOVQstore dst (FMOVQload src mem) mem))
423 (Move [s] dst src mem) && s > 24 && s < 32 =>
424 (FMOVQstore [int32(s-16)] dst (FMOVQload [int32(s-16)] src mem)
425 (FMOVQstore dst (FMOVQload src mem) mem))
426 (Move [32] dst src mem) =>
427 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem)
428 (Move [s] dst src mem) && s > 32 && s <= 40 =>
429 (MOVDstore [int32(s-8)] dst (MOVDload [int32(s-8)] src mem)
430 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem))
431 (Move [s] dst src mem) && s > 40 && s <= 48 =>
432 (FMOVQstore [int32(s-16)] dst (FMOVQload [int32(s-16)] src mem)
433 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem))
434 (Move [s] dst src mem) && s > 48 && s <= 64 =>
435 (FSTPQ [int32(s-32)] dst (Select0 <typ.Vec128> (FLDPQ [int32(s-32)] src mem)) (Select1 <typ.Vec128> (FLDPQ [int32(s-32)] src mem))
436 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem))
437
438 (Move [s] dst src mem) && s > 64 && s < 192 && logLargeCopy(v, s) => (LoweredMove [s] dst src mem)
439 (Move [s] dst src mem) && s >= 192 && logLargeCopy(v, s) => (LoweredMoveLoop [s] dst src mem)
440
441 // calls
442 (StaticCall ...) => (CALLstatic ...)
443 (ClosureCall ...) => (CALLclosure ...)
444 (InterCall ...) => (CALLinter ...)
445 (TailCall ...) => (CALLtail ...)
446 (TailCallInter ...) => (CALLtailinter ...)
447
448 // checks
449 (NilCheck ...) => (LoweredNilCheck ...)
450 (IsNonNil ptr) => (NotEqual (CMPconst [0] ptr))
451 (IsInBounds idx len) => (LessThanU (CMP idx len))
452 (IsSliceInBounds idx len) => (LessEqualU (CMP idx len))
453
454 // pseudo-ops
455 (GetClosurePtr ...) => (LoweredGetClosurePtr ...)
456 (GetCallerSP ...) => (LoweredGetCallerSP ...)
457 (GetCallerPC ...) => (LoweredGetCallerPC ...)
458 (MemEq ...) => (LoweredMemEq ...)
459
460 // Absorb pseudo-ops into blocks.
461 (If (Equal cc) yes no) => (EQ cc yes no)
462 (If (NotEqual cc) yes no) => (NE cc yes no)
463 (If (LessThan cc) yes no) => (LT cc yes no)
464 (If (LessThanU cc) yes no) => (ULT cc yes no)
465 (If (LessEqual cc) yes no) => (LE cc yes no)
466 (If (LessEqualU cc) yes no) => (ULE cc yes no)
467 (If (GreaterThan cc) yes no) => (GT cc yes no)
468 (If (GreaterThanU cc) yes no) => (UGT cc yes no)
469 (If (GreaterEqual cc) yes no) => (GE cc yes no)
470 (If (GreaterEqualU cc) yes no) => (UGE cc yes no)
471 (If (LessThanF cc) yes no) => (FLT cc yes no)
472 (If (LessEqualF cc) yes no) => (FLE cc yes no)
473 (If (GreaterThanF cc) yes no) => (FGT cc yes no)
474 (If (GreaterEqualF cc) yes no) => (FGE cc yes no)
475
476 (If cond yes no) => (TBNZ [0] cond yes no)
477
478 (JumpTable idx) => (JUMPTABLE {makeJumpTableSym(b)} idx (MOVDaddr <typ.Uintptr> {makeJumpTableSym(b)} (SB)))
479
480 // atomic intrinsics
481 // Note: these ops do not accept offset.
482 (AtomicLoad8 ...) => (LDARB ...)
483 (AtomicLoad32 ...) => (LDARW ...)
484 (AtomicLoad64 ...) => (LDAR ...)
485 (AtomicLoadPtr ...) => (LDAR ...)
486
487 (AtomicStore8 ...) => (STLRB ...)
488 (AtomicStore32 ...) => (STLRW ...)
489 (AtomicStore64 ...) => (STLR ...)
490 (AtomicStorePtrNoWB ...) => (STLR ...)
491
492 (AtomicExchange(8|32|64) ...) => (LoweredAtomicExchange(8|32|64) ...)
493 (AtomicAdd(32|64) ...) => (LoweredAtomicAdd(32|64) ...)
494 (AtomicCompareAndSwap(32|64) ...) => (LoweredAtomicCas(32|64) ...)
495
496 (AtomicAdd(32|64)Variant ...) => (LoweredAtomicAdd(32|64)Variant ...)
497 (AtomicExchange(8|32|64)Variant ...) => (LoweredAtomicExchange(8|32|64)Variant ...)
498 (AtomicCompareAndSwap(32|64)Variant ...) => (LoweredAtomicCas(32|64)Variant ...)
499
500 // Return old contents.
501 (AtomicAnd(64|32|8)value ...) => (LoweredAtomicAnd(64|32|8) ...)
502 (AtomicOr(64|32|8)value ...) => (LoweredAtomicOr(64|32|8) ...)
503 (AtomicAnd(64|32|8)valueVariant ...) => (LoweredAtomicAnd(64|32|8)Variant ...)
504 (AtomicOr(64|32|8)valueVariant ...) => (LoweredAtomicOr(64|32|8)Variant ...)
505
506 // Write barrier.
507 (WB ...) => (LoweredWB ...)
508
509 // Publication barrier (0xe is ST option)
510 (PubBarrier mem) => (DMB [0xe] mem)
511
512 (PanicBounds ...) => (LoweredPanicBoundsRR ...)
513 (LoweredPanicBoundsRR [kind] x (MOVDconst [c]) mem) => (LoweredPanicBoundsRC [kind] x {PanicBoundsC{C:c}} mem)
514 (LoweredPanicBoundsRR [kind] (MOVDconst [c]) y mem) => (LoweredPanicBoundsCR [kind] {PanicBoundsC{C:c}} y mem)
515 (LoweredPanicBoundsRC [kind] {p} (MOVDconst [c]) mem) => (LoweredPanicBoundsCC [kind] {PanicBoundsCC{Cx:c, Cy:p.C}} mem)
516 (LoweredPanicBoundsCR [kind] {p} (MOVDconst [c]) mem) => (LoweredPanicBoundsCC [kind] {PanicBoundsCC{Cx:p.C, Cy:c}} mem)
517
518 // Optimizations
519
520 // Replace widen -> wide_unop -> narrow with narrow_unop when one exists.
521 (FCVTDS (F(ABS|SQRT|RINTP|RINTM|RINTA|RINTN|RINTZ)D (FCVTSD x))) =>
522 (F(ABS|SQRT|RINTP|RINTM|RINTA|RINTN|RINTZ)S x)
523
524
525 // Absorb boolean tests into block
526 (NZ (Equal cc) yes no) => (EQ cc yes no)
527 (NZ (NotEqual cc) yes no) => (NE cc yes no)
528 (NZ (LessThan cc) yes no) => (LT cc yes no)
529 (NZ (LessThanU cc) yes no) => (ULT cc yes no)
530 (NZ (LessEqual cc) yes no) => (LE cc yes no)
531 (NZ (LessEqualU cc) yes no) => (ULE cc yes no)
532 (NZ (GreaterThan cc) yes no) => (GT cc yes no)
533 (NZ (GreaterThanU cc) yes no) => (UGT cc yes no)
534 (NZ (GreaterEqual cc) yes no) => (GE cc yes no)
535 (NZ (GreaterEqualU cc) yes no) => (UGE cc yes no)
536 (NZ (LessThanF cc) yes no) => (FLT cc yes no)
537 (NZ (LessEqualF cc) yes no) => (FLE cc yes no)
538 (NZ (GreaterThanF cc) yes no) => (FGT cc yes no)
539 (NZ (GreaterEqualF cc) yes no) => (FGE cc yes no)
540
541 (TBNZ [0] (Equal cc) yes no) => (EQ cc yes no)
542 (TBNZ [0] (NotEqual cc) yes no) => (NE cc yes no)
543 (TBNZ [0] (LessThan cc) yes no) => (LT cc yes no)
544 (TBNZ [0] (LessThanU cc) yes no) => (ULT cc yes no)
545 (TBNZ [0] (LessEqual cc) yes no) => (LE cc yes no)
546 (TBNZ [0] (LessEqualU cc) yes no) => (ULE cc yes no)
547 (TBNZ [0] (GreaterThan cc) yes no) => (GT cc yes no)
548 (TBNZ [0] (GreaterThanU cc) yes no) => (UGT cc yes no)
549 (TBNZ [0] (GreaterEqual cc) yes no) => (GE cc yes no)
550 (TBNZ [0] (GreaterEqualU cc) yes no) => (UGE cc yes no)
551 (TBNZ [0] (LessThanF cc) yes no) => (FLT cc yes no)
552 (TBNZ [0] (LessEqualF cc) yes no) => (FLE cc yes no)
553 (TBNZ [0] (GreaterThanF cc) yes no) => (FGT cc yes no)
554 (TBNZ [0] (GreaterEqualF cc) yes no) => (FGE cc yes no)
555
556 (TB(Z|NZ) [0] (XORconst [1] x) yes no) => (TB(NZ|Z) [0] x yes no)
557
558 ((EQ|NE|LT|LE|GT|GE) (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TST x y) yes no)
559 ((EQ|NE|LT|LE|GT|GE) (CMPconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TSTconst [c] y) yes no)
560 ((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TSTW x y) yes no)
561 ((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TSTWconst [int32(c)] y) yes no)
562
563 // For conditional instructions such as CSET, CSEL.
564 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPconst [0] z:(AND x y))) && z.Uses == 1 =>
565 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TST x y))
566 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 =>
567 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TSTWconst [int32(c)] y))
568 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPWconst [0] z:(AND x y))) && z.Uses == 1 =>
569 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TSTW x y))
570 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPconst [0] x:(ANDconst [c] y))) && x.Uses == 1 =>
571 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TSTconst [c] y))
572
573 ((EQ|NE|LT|LE|GT|GE) (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMNconst [c] y) yes no)
574 ((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMNWconst [int32(c)] y) yes no)
575 ((EQ|NE|LT|LE|GT|GE) (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMN x y) yes no)
576 ((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMNW x y) yes no)
577
578 // CMP(x,-y) -> CMN(x,y) is only valid for unordered comparison, if y can be -1<<63
579 ((EQ|NE) (CMP x z:(NEG y)) yes no) && z.Uses == 1 => ((EQ|NE) (CMN x y) yes no)
580 ((Equal|NotEqual) (CMP x z:(NEG y))) && z.Uses == 1 => ((Equal|NotEqual) (CMN x y))
581
582 // CMPW(x,-y) -> CMNW(x,y) is only valid for unordered comparison, if y can be -1<<31
583 ((EQ|NE) (CMPW x z:(NEG y)) yes no) && z.Uses == 1 => ((EQ|NE) (CMNW x y) yes no)
584 ((Equal|NotEqual) (CMPW x z:(NEG y))) && z.Uses == 1 => ((Equal|NotEqual) (CMNW x y))
585
586 // For conditional instructions such as CSET, CSEL.
587 // TODO: add support for LE, GT, overflow needs to be considered.
588 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPconst [0] x:(ADDconst [c] y))) && x.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNconst [c] y))
589 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPWconst [0] x:(ADDconst [c] y))) && x.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNWconst [int32(c)] y))
590 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPconst [0] z:(ADD x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMN x y))
591 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPWconst [0] z:(ADD x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNW x y))
592 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPconst [0] z:(MADD a x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMN a (MUL <x.Type> x y)))
593 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPconst [0] z:(MSUB a x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMP a (MUL <x.Type> x y)))
594 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPWconst [0] z:(MADDW a x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNW a (MULW <x.Type> x y)))
595 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPWconst [0] z:(MSUBW a x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMPW a (MULW <x.Type> x y)))
596
597 ((CMPconst|CMNconst) [c] y) && c < 0 && c != -1<<63 => ((CMNconst|CMPconst) [-c] y)
598 ((CMPWconst|CMNWconst) [c] y) && c < 0 && c != -1<<31 => ((CMNWconst|CMPWconst) [-c] y)
599
600 ((EQ|NE) (CMPconst [0] x) yes no) => ((Z|NZ) x yes no)
601 ((EQ|NE) (CMPWconst [0] x) yes no) => ((ZW|NZW) x yes no)
602
603 ((ULE|UGT) (CMPconst [0] x)) => ((EQ|NE) (CMPconst [0] x))
604 ((ULE|UGT) (CMPWconst [0] x)) => ((EQ|NE) (CMPWconst [0] x))
605
606 ((Z|NZ) sub:(SUB x y)) && sub.Uses == 1 => ((EQ|NE) (CMP x y))
607 ((ZW|NZW) sub:(SUB x y)) && sub.Uses == 1 => ((EQ|NE) (CMPW x y))
608 ((Z|NZ) sub:(SUBconst [c] y)) && sub.Uses == 1 => ((EQ|NE) (CMPconst [c] y))
609 ((ZW|NZW) sub:(SUBconst [c] y)) && sub.Uses == 1 => ((EQ|NE) (CMPWconst [int32(c)] y))
610
611 ((EQ|NE|LT|LE|GT|GE) (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMN a (MUL <x.Type> x y)) yes no)
612 ((EQ|NE|LT|LE|GT|GE) (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMP a (MUL <x.Type> x y)) yes no)
613 ((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMNW a (MULW <x.Type> x y)) yes no)
614 ((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 => ((EQ|NE|LTnoov|LEnoov|GTnoov|GEnoov) (CMPW a (MULW <x.Type> x y)) yes no)
615
616 // Absorb bit-tests into block
617 (Z (ANDconst [c] x) yes no) && oneBit(c) => (TBZ [int64(ntz64(c))] x yes no)
618 (NZ (ANDconst [c] x) yes no) && oneBit(c) => (TBNZ [int64(ntz64(c))] x yes no)
619 (ZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBZ [int64(ntz64(int64(uint32(c))))] x yes no)
620 (NZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBNZ [int64(ntz64(int64(uint32(c))))] x yes no)
621 (EQ (TSTconst [c] x) yes no) && oneBit(c) => (TBZ [int64(ntz64(c))] x yes no)
622 (NE (TSTconst [c] x) yes no) && oneBit(c) => (TBNZ [int64(ntz64(c))] x yes no)
623 (EQ (TSTWconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBZ [int64(ntz64(int64(uint32(c))))] x yes no)
624 (NE (TSTWconst [c] x) yes no) && oneBit(int64(uint32(c))) => (TBNZ [int64(ntz64(int64(uint32(c))))] x yes no)
625
626 ((Z|NZ) s:(SRLconst [63] x) yes no) && s.Uses == 1 => (TB(Z|NZ) [63] x yes no)
627 ((Z|NZ) s:(SRAconst [63] x) yes no) && s.Uses == 1 => (TB(Z|NZ) [63] x yes no)
628
629 // Merge more operations into TBZ & TBNZ
630 (TB(Z|NZ) [t] sv:(SRLconst [s] x) yes no) && t+s < 64 && sv.Uses == 1 => (TB(Z|NZ) [t+s] x yes no )
631 (TBZ [t] (SRLconst [s] x) yes no) && t+s >= 64 => (First yes no )
632 (TBNZ [t] (SRLconst [s] x) yes no) && t+s >= 64 => (First no yes)
633
634 (TB(Z|NZ) [t] sv:(SLLconst [s] x) yes no) && t-s >= 0 && sv.Uses == 1 => (TB(Z|NZ) [t-s] x yes no )
635 (TBZ [t] (SLLconst [s] x) yes no) && t-s < 0 => (First yes no )
636 (TBNZ [t] (SLLconst [s] x) yes no) && t-s < 0 => (First no yes)
637
638 (TB(Z|NZ) [t] rv:(RORconst [r] x) yes no) && rv.Uses == 1 => (TB(Z|NZ) [int64(uint64(t+r)%64)] x yes no)
639
640 (TB(Z|NZ) [t] sv:(SRAconst [s] x) yes no) && t+s < 64 && sv.Uses == 1 => (TB(Z|NZ) [t+s] x yes no)
641 (TB(Z|NZ) [t] sv:(SRAconst [s] x) yes no) && t+s >= 64 && sv.Uses == 1 => (TB(Z|NZ) [63 ] x yes no)
642
643 // Test sign-bit for signed comparisons against zero
644 (GE (CMPWconst [0] x) yes no) => (TBZ [31] x yes no)
645 (GE (CMPconst [0] x) yes no) => (TBZ [63] x yes no)
646 (LT (CMPWconst [0] x) yes no) => (TBNZ [31] x yes no)
647 (LT (CMPconst [0] x) yes no) => (TBNZ [63] x yes no)
648
649 // fold offset into address
650 (ADDconst [off1] (MOVDaddr [off2] {sym} ptr)) && is32Bit(off1+int64(off2)) =>
651 (MOVDaddr [int32(off1)+off2] {sym} ptr)
652
653 // fold address into load/store.
654 // Do not fold global variable access in -dynlink mode, where it will
655 // be rewritten to use the GOT via REGTMP, which currently cannot handle
656 // large offset.
657 (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
658 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
659 (MOVBload [off1+int32(off2)] {sym} ptr mem)
660 (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
661 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
662 (MOVBUload [off1+int32(off2)] {sym} ptr mem)
663 (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
664 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
665 (MOVHload [off1+int32(off2)] {sym} ptr mem)
666 (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
667 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
668 (MOVHUload [off1+int32(off2)] {sym} ptr mem)
669 (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
670 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
671 (MOVWload [off1+int32(off2)] {sym} ptr mem)
672 (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
673 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
674 (MOVWUload [off1+int32(off2)] {sym} ptr mem)
675 (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
676 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
677 (MOVDload [off1+int32(off2)] {sym} ptr mem)
678 (LDP [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
679 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
680 (LDP [off1+int32(off2)] {sym} ptr mem)
681 (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
682 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
683 (FMOVSload [off1+int32(off2)] {sym} ptr mem)
684 (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
685 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
686 (FMOVDload [off1+int32(off2)] {sym} ptr mem)
687 (FMOVQload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
688 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
689 (FMOVQload [off1+int32(off2)] {sym} ptr mem)
690 (FLDPQ [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(int64(off1)+off2)
691 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
692 (FLDPQ [off1+int32(off2)] {sym} ptr mem)
693
694 // register indexed load
695 (MOVDload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVDloadidx ptr idx mem)
696 (MOVWUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVWUloadidx ptr idx mem)
697 (MOVWload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVWloadidx ptr idx mem)
698 (MOVHUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVHUloadidx ptr idx mem)
699 (MOVHload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVHloadidx ptr idx mem)
700 (MOVBUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVBUloadidx ptr idx mem)
701 (MOVBload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVBloadidx ptr idx mem)
702 (FMOVSload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (FMOVSloadidx ptr idx mem)
703 (FMOVDload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (FMOVDloadidx ptr idx mem)
704
705 (MOVDloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVDload [int32(c)] ptr mem)
706 (MOVDloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVDload [int32(c)] ptr mem)
707 (MOVWUloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVWUload [int32(c)] ptr mem)
708 (MOVWUloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVWUload [int32(c)] ptr mem)
709 (MOVWloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVWload [int32(c)] ptr mem)
710 (MOVWloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVWload [int32(c)] ptr mem)
711 (MOVHUloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVHUload [int32(c)] ptr mem)
712 (MOVHUloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVHUload [int32(c)] ptr mem)
713 (MOVHloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVHload [int32(c)] ptr mem)
714 (MOVHloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVHload [int32(c)] ptr mem)
715 (MOVBUloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVBUload [int32(c)] ptr mem)
716 (MOVBUloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVBUload [int32(c)] ptr mem)
717 (MOVBloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (MOVBload [int32(c)] ptr mem)
718 (MOVBloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (MOVBload [int32(c)] ptr mem)
719 (FMOVSloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (FMOVSload [int32(c)] ptr mem)
720 (FMOVSloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (FMOVSload [int32(c)] ptr mem)
721 (FMOVDloadidx ptr (MOVDconst [c]) mem) && is32Bit(c) => (FMOVDload [int32(c)] ptr mem)
722 (FMOVDloadidx (MOVDconst [c]) ptr mem) && is32Bit(c) => (FMOVDload [int32(c)] ptr mem)
723
724 // shifted register indexed load
725 (MOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) && off == 0 && sym == nil => (MOVDloadidx8 ptr idx mem)
726 (MOVWUload [off] {sym} (ADDshiftLL [2] ptr idx) mem) && off == 0 && sym == nil => (MOVWUloadidx4 ptr idx mem)
727 (MOVWload [off] {sym} (ADDshiftLL [2] ptr idx) mem) && off == 0 && sym == nil => (MOVWloadidx4 ptr idx mem)
728 (MOVHUload [off] {sym} (ADDshiftLL [1] ptr idx) mem) && off == 0 && sym == nil => (MOVHUloadidx2 ptr idx mem)
729 (MOVHload [off] {sym} (ADDshiftLL [1] ptr idx) mem) && off == 0 && sym == nil => (MOVHloadidx2 ptr idx mem)
730 (MOVDloadidx ptr (SLLconst [3] idx) mem) => (MOVDloadidx8 ptr idx mem)
731 (MOVWloadidx ptr (SLLconst [2] idx) mem) => (MOVWloadidx4 ptr idx mem)
732 (MOVWUloadidx ptr (SLLconst [2] idx) mem) => (MOVWUloadidx4 ptr idx mem)
733 (MOVHloadidx ptr (SLLconst [1] idx) mem) => (MOVHloadidx2 ptr idx mem)
734 (MOVHUloadidx ptr (SLLconst [1] idx) mem) => (MOVHUloadidx2 ptr idx mem)
735 (MOVHloadidx ptr (ADD idx idx) mem) => (MOVHloadidx2 ptr idx mem)
736 (MOVHUloadidx ptr (ADD idx idx) mem) => (MOVHUloadidx2 ptr idx mem)
737 (MOVDloadidx (SLLconst [3] idx) ptr mem) => (MOVDloadidx8 ptr idx mem)
738 (MOVWloadidx (SLLconst [2] idx) ptr mem) => (MOVWloadidx4 ptr idx mem)
739 (MOVWUloadidx (SLLconst [2] idx) ptr mem) => (MOVWUloadidx4 ptr idx mem)
740 (MOVHloadidx (ADD idx idx) ptr mem) => (MOVHloadidx2 ptr idx mem)
741 (MOVHUloadidx (ADD idx idx) ptr mem) => (MOVHUloadidx2 ptr idx mem)
742 (MOVDloadidx8 ptr (MOVDconst [c]) mem) && is32Bit(c<<3) => (MOVDload [int32(c)<<3] ptr mem)
743 (MOVWUloadidx4 ptr (MOVDconst [c]) mem) && is32Bit(c<<2) => (MOVWUload [int32(c)<<2] ptr mem)
744 (MOVWloadidx4 ptr (MOVDconst [c]) mem) && is32Bit(c<<2) => (MOVWload [int32(c)<<2] ptr mem)
745 (MOVHUloadidx2 ptr (MOVDconst [c]) mem) && is32Bit(c<<1) => (MOVHUload [int32(c)<<1] ptr mem)
746 (MOVHloadidx2 ptr (MOVDconst [c]) mem) && is32Bit(c<<1) => (MOVHload [int32(c)<<1] ptr mem)
747
748 (FMOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) && off == 0 && sym == nil => (FMOVDloadidx8 ptr idx mem)
749 (FMOVSload [off] {sym} (ADDshiftLL [2] ptr idx) mem) && off == 0 && sym == nil => (FMOVSloadidx4 ptr idx mem)
750 (FMOVDloadidx ptr (SLLconst [3] idx) mem) => (FMOVDloadidx8 ptr idx mem)
751 (FMOVSloadidx ptr (SLLconst [2] idx) mem) => (FMOVSloadidx4 ptr idx mem)
752 (FMOVDloadidx (SLLconst [3] idx) ptr mem) => (FMOVDloadidx8 ptr idx mem)
753 (FMOVSloadidx (SLLconst [2] idx) ptr mem) => (FMOVSloadidx4 ptr idx mem)
754 (FMOVDloadidx8 ptr (MOVDconst [c]) mem) && is32Bit(c<<3) => (FMOVDload ptr [int32(c)<<3] mem)
755 (FMOVSloadidx4 ptr (MOVDconst [c]) mem) && is32Bit(c<<2) => (FMOVSload ptr [int32(c)<<2] mem)
756
757 (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
758 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
759 (MOVBstore [off1+int32(off2)] {sym} ptr val mem)
760 (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
761 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
762 (MOVHstore [off1+int32(off2)] {sym} ptr val mem)
763 (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
764 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
765 (MOVWstore [off1+int32(off2)] {sym} ptr val mem)
766 (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
767 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
768 (MOVDstore [off1+int32(off2)] {sym} ptr val mem)
769 (STP [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) && is32Bit(int64(off1)+off2)
770 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
771 (STP [off1+int32(off2)] {sym} ptr val1 val2 mem)
772 (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
773 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
774 (FMOVSstore [off1+int32(off2)] {sym} ptr val mem)
775 (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
776 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
777 (FMOVDstore [off1+int32(off2)] {sym} ptr val mem)
778 (FMOVQstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(int64(off1)+off2)
779 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
780 (FMOVQstore [off1+int32(off2)] {sym} ptr val mem)
781 (FSTPQ [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) && is32Bit(int64(off1)+off2)
782 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
783 (FSTPQ [off1+int32(off2)] {sym} ptr val1 val2 mem)
784
785 // register indexed store
786 (MOVDstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVDstoreidx ptr idx val mem)
787 (MOVWstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVWstoreidx ptr idx val mem)
788 (MOVHstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVHstoreidx ptr idx val mem)
789 (MOVBstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVBstoreidx ptr idx val mem)
790 (FMOVDstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (FMOVDstoreidx ptr idx val mem)
791 (FMOVSstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (FMOVSstoreidx ptr idx val mem)
792 (MOVDstoreidx ptr (MOVDconst [c]) val mem) && is32Bit(c) => (MOVDstore [int32(c)] ptr val mem)
793 (MOVDstoreidx (MOVDconst [c]) idx val mem) && is32Bit(c) => (MOVDstore [int32(c)] idx val mem)
794 (MOVWstoreidx ptr (MOVDconst [c]) val mem) && is32Bit(c) => (MOVWstore [int32(c)] ptr val mem)
795 (MOVWstoreidx (MOVDconst [c]) idx val mem) && is32Bit(c) => (MOVWstore [int32(c)] idx val mem)
796 (MOVHstoreidx ptr (MOVDconst [c]) val mem) && is32Bit(c) => (MOVHstore [int32(c)] ptr val mem)
797 (MOVHstoreidx (MOVDconst [c]) idx val mem) && is32Bit(c) => (MOVHstore [int32(c)] idx val mem)
798 (MOVBstoreidx ptr (MOVDconst [c]) val mem) && is32Bit(c) => (MOVBstore [int32(c)] ptr val mem)
799 (MOVBstoreidx (MOVDconst [c]) idx val mem) && is32Bit(c) => (MOVBstore [int32(c)] idx val mem)
800 (FMOVDstoreidx ptr (MOVDconst [c]) val mem) && is32Bit(c) => (FMOVDstore [int32(c)] ptr val mem)
801 (FMOVDstoreidx (MOVDconst [c]) idx val mem) && is32Bit(c) => (FMOVDstore [int32(c)] idx val mem)
802 (FMOVSstoreidx ptr (MOVDconst [c]) val mem) && is32Bit(c) => (FMOVSstore [int32(c)] ptr val mem)
803 (FMOVSstoreidx (MOVDconst [c]) idx val mem) && is32Bit(c) => (FMOVSstore [int32(c)] idx val mem)
804
805 // shifted register indexed store
806 (MOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) && off == 0 && sym == nil => (MOVDstoreidx8 ptr idx val mem)
807 (MOVWstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) && off == 0 && sym == nil => (MOVWstoreidx4 ptr idx val mem)
808 (MOVHstore [off] {sym} (ADDshiftLL [1] ptr idx) val mem) && off == 0 && sym == nil => (MOVHstoreidx2 ptr idx val mem)
809 (MOVDstoreidx ptr (SLLconst [3] idx) val mem) => (MOVDstoreidx8 ptr idx val mem)
810 (MOVWstoreidx ptr (SLLconst [2] idx) val mem) => (MOVWstoreidx4 ptr idx val mem)
811 (MOVHstoreidx ptr (SLLconst [1] idx) val mem) => (MOVHstoreidx2 ptr idx val mem)
812 (MOVHstoreidx ptr (ADD idx idx) val mem) => (MOVHstoreidx2 ptr idx val mem)
813 (MOVDstoreidx (SLLconst [3] idx) ptr val mem) => (MOVDstoreidx8 ptr idx val mem)
814 (MOVWstoreidx (SLLconst [2] idx) ptr val mem) => (MOVWstoreidx4 ptr idx val mem)
815 (MOVHstoreidx (SLLconst [1] idx) ptr val mem) => (MOVHstoreidx2 ptr idx val mem)
816 (MOVHstoreidx (ADD idx idx) ptr val mem) => (MOVHstoreidx2 ptr idx val mem)
817 (MOVDstoreidx8 ptr (MOVDconst [c]) val mem) && is32Bit(c<<3) => (MOVDstore [int32(c)<<3] ptr val mem)
818 (MOVWstoreidx4 ptr (MOVDconst [c]) val mem) && is32Bit(c<<2) => (MOVWstore [int32(c)<<2] ptr val mem)
819 (MOVHstoreidx2 ptr (MOVDconst [c]) val mem) && is32Bit(c<<1) => (MOVHstore [int32(c)<<1] ptr val mem)
820
821 (FMOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) && off == 0 && sym == nil => (FMOVDstoreidx8 ptr idx val mem)
822 (FMOVSstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) && off == 0 && sym == nil => (FMOVSstoreidx4 ptr idx val mem)
823 (FMOVDstoreidx ptr (SLLconst [3] idx) val mem) => (FMOVDstoreidx8 ptr idx val mem)
824 (FMOVSstoreidx ptr (SLLconst [2] idx) val mem) => (FMOVSstoreidx4 ptr idx val mem)
825 (FMOVDstoreidx (SLLconst [3] idx) ptr val mem) => (FMOVDstoreidx8 ptr idx val mem)
826 (FMOVSstoreidx (SLLconst [2] idx) ptr val mem) => (FMOVSstoreidx4 ptr idx val mem)
827 (FMOVDstoreidx8 ptr (MOVDconst [c]) val mem) && is32Bit(c<<3) => (FMOVDstore [int32(c)<<3] ptr val mem)
828 (FMOVSstoreidx4 ptr (MOVDconst [c]) val mem) && is32Bit(c<<2) => (FMOVSstore [int32(c)<<2] ptr val mem)
829
830 (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
831 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
832 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
833 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
834 (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
835 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
836 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
837 (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
838 (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
839 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
840 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
841 (MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
842 (MOVHUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
843 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
844 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
845 (MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
846 (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
847 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
848 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
849 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
850 (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
851 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
852 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
853 (MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
854 (MOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
855 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
856 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
857 (MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
858 (LDP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
859 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
860 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
861 (LDP [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
862 (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
863 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
864 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
865 (FMOVSload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
866 (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
867 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
868 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
869 (FMOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
870 (FMOVQload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
871 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
872 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
873 (FMOVQload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
874 (FLDPQ [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
875 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
876 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
877 (FLDPQ [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
878
879 (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
880 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
881 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
882 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
883 (MOVHstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
884 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
885 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
886 (MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
887 (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
888 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
889 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
890 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
891 (MOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
892 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
893 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
894 (MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
895 (STP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem)
896 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
897 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
898 (STP [off1+off2] {mergeSym(sym1,sym2)} ptr val1 val2 mem)
899 (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
900 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
901 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
902 (FMOVSstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
903 (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
904 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
905 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
906 (FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
907 (FMOVQstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
908 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
909 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
910 (FMOVQstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
911 (FSTPQ [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem)
912 && canMergeSym(sym1,sym2) && is32Bit(int64(off1)+int64(off2))
913 && (ptr.Op != OpSB || !config.ctxt.Flag_dynlink) =>
914 (FSTPQ [off1+off2] {mergeSym(sym1,sym2)} ptr val1 val2 mem)
915
916 // replace load from same location as preceding store with zero/sign extension (or copy in case of full width)
917 // these seem to have bad interaction with other rules, resulting in slower code
918 //(MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBreg x)
919 //(MOVBUload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBUreg x)
920 //(MOVHload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHreg x)
921 //(MOVHUload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHUreg x)
922 //(MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWreg x)
923 //(MOVWUload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWUreg x)
924 //(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
925 //(FMOVSload [off] {sym} ptr (FMOVSstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
926 //(FMOVDload [off] {sym} ptr (FMOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
927 //(LDP [off] {sym} ptr (STP [off2] {sym2} ptr2 x y _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x y
928
929 // don't extend before store
930 (MOVBstore [off] {sym} ptr (MOVBreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
931 (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
932 (MOVBstore [off] {sym} ptr (MOVHreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
933 (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
934 (MOVBstore [off] {sym} ptr (MOVWreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
935 (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
936 (MOVHstore [off] {sym} ptr (MOVHreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
937 (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
938 (MOVHstore [off] {sym} ptr (MOVWreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
939 (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
940 (MOVWstore [off] {sym} ptr (MOVWreg x) mem) => (MOVWstore [off] {sym} ptr x mem)
941 (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVWstore [off] {sym} ptr x mem)
942 (MOVBstoreidx ptr idx (MOVBreg x) mem) => (MOVBstoreidx ptr idx x mem)
943 (MOVBstoreidx ptr idx (MOVBUreg x) mem) => (MOVBstoreidx ptr idx x mem)
944 (MOVBstoreidx ptr idx (MOVHreg x) mem) => (MOVBstoreidx ptr idx x mem)
945 (MOVBstoreidx ptr idx (MOVHUreg x) mem) => (MOVBstoreidx ptr idx x mem)
946 (MOVBstoreidx ptr idx (MOVWreg x) mem) => (MOVBstoreidx ptr idx x mem)
947 (MOVBstoreidx ptr idx (MOVWUreg x) mem) => (MOVBstoreidx ptr idx x mem)
948 (MOVHstoreidx ptr idx (MOVHreg x) mem) => (MOVHstoreidx ptr idx x mem)
949 (MOVHstoreidx ptr idx (MOVHUreg x) mem) => (MOVHstoreidx ptr idx x mem)
950 (MOVHstoreidx ptr idx (MOVWreg x) mem) => (MOVHstoreidx ptr idx x mem)
951 (MOVHstoreidx ptr idx (MOVWUreg x) mem) => (MOVHstoreidx ptr idx x mem)
952 (MOVWstoreidx ptr idx (MOVWreg x) mem) => (MOVWstoreidx ptr idx x mem)
953 (MOVWstoreidx ptr idx (MOVWUreg x) mem) => (MOVWstoreidx ptr idx x mem)
954 (MOVHstoreidx2 ptr idx (MOVHreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
955 (MOVHstoreidx2 ptr idx (MOVHUreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
956 (MOVHstoreidx2 ptr idx (MOVWreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
957 (MOVHstoreidx2 ptr idx (MOVWUreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
958 (MOVWstoreidx4 ptr idx (MOVWreg x) mem) => (MOVWstoreidx4 ptr idx x mem)
959 (MOVWstoreidx4 ptr idx (MOVWUreg x) mem) => (MOVWstoreidx4 ptr idx x mem)
960
961 // if a register move has only 1 use, just use the same register without emitting instruction
962 // MOVDnop doesn't emit instruction, only for ensuring the type.
963 (MOVDreg x) && x.Uses == 1 => (MOVDnop x)
964
965 // TODO: we should be able to get rid of MOVDnop all together.
966 // But for now, this is enough to get rid of lots of them.
967 (MOVDnop (MOVDconst [c])) => (MOVDconst [c])
968
969 // fold constant into arithmetic ops
970 (ADD x (MOVDconst <t> [c])) && !t.IsPtr() => (ADDconst [c] x)
971 (SUB x (MOVDconst [c])) => (SUBconst [c] x)
972 (AND x (MOVDconst [c])) => (ANDconst [c] x)
973 (OR x (MOVDconst [c])) => (ORconst [c] x)
974 (XOR x (MOVDconst [c])) => (XORconst [c] x)
975 (TST x (MOVDconst [c])) => (TSTconst [c] x)
976 (TSTW x (MOVDconst [c])) => (TSTWconst [int32(c)] x)
977 (CMN x (MOVDconst [c])) => (CMNconst [c] x)
978 (CMNW x (MOVDconst [c])) => (CMNWconst [int32(c)] x)
979 (BIC x (MOVDconst [c])) => (ANDconst [^c] x)
980 (EON x (MOVDconst [c])) => (XORconst [^c] x)
981 (ORN x (MOVDconst [c])) => (ORconst [^c] x)
982
983 (SLL x (MOVDconst [c])) => (SLLconst x [c&63])
984 (SRL x (MOVDconst [c])) => (SRLconst x [c&63])
985 (SRA x (MOVDconst [c])) => (SRAconst x [c&63])
986 (SLL x (ANDconst [63] y)) => (SLL x y)
987 (SRL x (ANDconst [63] y)) => (SRL x y)
988 (SRA x (ANDconst [63] y)) => (SRA x y)
989
990 (CMP x (MOVDconst [c])) => (CMPconst [c] x)
991 (CMP (MOVDconst [c]) x) => (InvertFlags (CMPconst [c] x))
992 (CMPW x (MOVDconst [c])) => (CMPWconst [int32(c)] x)
993 (CMPW (MOVDconst [c]) x) => (InvertFlags (CMPWconst [int32(c)] x))
994
995 (ROR x (MOVDconst [c])) => (RORconst x [c&63])
996 (RORW x (MOVDconst [c])) => (RORWconst x [c&31])
997
998 (ADDSflags x (MOVDconst [c])) => (ADDSconstflags [c] x)
999
1000 (ADDconst [c] y) && c < 0 => (SUBconst [-c] y)
1001
1002 // Canonicalize the order of arguments to comparisons - helps with CSE.
1003 ((CMP|CMPW) x y) && canonLessThan(x,y) => (InvertFlags ((CMP|CMPW) y x))
1004
1005 // mul-neg => mneg
1006 (NEG (MUL x y)) => (MNEG x y)
1007 (NEG (MULW x y)) && v.Type.Size() <= 4 => (MNEGW x y)
1008 (MUL (NEG x) y) => (MNEG x y)
1009 (MULW (NEG x) y) => (MNEGW x y)
1010
1011 // madd/msub
1012 (ADD a l:(MUL x y)) && l.Uses==1 && clobber(l) => (MADD a x y)
1013 (SUB a l:(MUL x y)) && l.Uses==1 && clobber(l) => (MSUB a x y)
1014 (ADD a l:(MNEG x y)) && l.Uses==1 && clobber(l) => (MSUB a x y)
1015 (SUB a l:(MNEG x y)) && l.Uses==1 && clobber(l) => (MADD a x y)
1016
1017 (ADD a l:(MULW x y)) && v.Type.Size() <= 4 && l.Uses==1 && clobber(l) => (MADDW a x y)
1018 (SUB a l:(MULW x y)) && v.Type.Size() <= 4 && l.Uses==1 && clobber(l) => (MSUBW a x y)
1019 (ADD a l:(MNEGW x y)) && v.Type.Size() <= 4 && l.Uses==1 && clobber(l) => (MSUBW a x y)
1020 (SUB a l:(MNEGW x y)) && v.Type.Size() <= 4 && l.Uses==1 && clobber(l) => (MADDW a x y)
1021
1022 // madd/msub can't take constant arguments, so do a bit of reordering if a non-constant is available.
1023 // Note: don't reorder arithmetic concerning pointers, as we must ensure that
1024 // no intermediate computations are invalid pointers.
1025 (ADD <t> a p:(ADDconst [c] m:((MUL|MULW|MNEG|MNEGW) _ _))) && p.Uses==1 && m.Uses==1 && !t.IsPtrShaped() => (ADDconst [c] (ADD <v.Type> a m))
1026 (ADD <t> a p:(SUBconst [c] m:((MUL|MULW|MNEG|MNEGW) _ _))) && p.Uses==1 && m.Uses==1 && !t.IsPtrShaped() => (SUBconst [c] (ADD <v.Type> a m))
1027 (SUB <t> a p:(ADDconst [c] m:((MUL|MULW|MNEG|MNEGW) _ _))) && p.Uses==1 && m.Uses==1 && !t.IsPtrShaped() => (SUBconst [c] (SUB <v.Type> a m))
1028 (SUB <t> a p:(SUBconst [c] m:((MUL|MULW|MNEG|MNEGW) _ _))) && p.Uses==1 && m.Uses==1 && !t.IsPtrShaped() => (ADDconst [c] (SUB <v.Type> a m))
1029
1030 // optimize ADCSflags, SBCSflags and friends
1031 (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] (ADCzerocarry <typ.UInt64> c)))) => (ADCSflags x y c)
1032 (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] (MOVDconst [0])))) => (ADDSflags x y)
1033 (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags (NEG <typ.UInt64> (NGCzerocarry <typ.UInt64> bo))))) => (SBCSflags x y bo)
1034 (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags (MOVDconst [0])))) => (SUBSflags x y)
1035
1036 // mul by constant
1037 (MUL _ (MOVDconst [0])) => (MOVDconst [0])
1038 (MUL x (MOVDconst [1])) => x
1039
1040 (MULW _ (MOVDconst [c])) && int32(c)==0 => (MOVDconst [0])
1041 (MULW x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg x)
1042
1043 (MUL x (MOVDconst [c])) && canMulStrengthReduce(config, c) => {mulStrengthReduce(v, x, c)}
1044 (MULW x (MOVDconst [c])) && v.Type.Size() <= 4 && canMulStrengthReduce32(config, int32(c)) => {mulStrengthReduce32(v, x, int32(c))}
1045
1046 // mneg by constant
1047 (MNEG x (MOVDconst [-1])) => x
1048 (MNEG _ (MOVDconst [0])) => (MOVDconst [0])
1049 (MNEG x (MOVDconst [1])) => (NEG x)
1050 (MNEG x (MOVDconst [c])) && isPowerOfTwo(c) => (NEG (SLLconst <x.Type> [log64(c)] x))
1051 (MNEG x (MOVDconst [c])) && isPowerOfTwo(c-1) && c >= 3 => (NEG (ADDshiftLL <x.Type> x x [log64(c-1)]))
1052 (MNEG x (MOVDconst [c])) && isPowerOfTwo(c+1) && c >= 7 => (NEG (ADDshiftLL <x.Type> (NEG <x.Type> x) x [log64(c+1)]))
1053 (MNEG x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) => (SLLconst <x.Type> [log64(c/3)] (SUBshiftLL <x.Type> x x [2]))
1054 (MNEG x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) => (NEG (SLLconst <x.Type> [log64(c/5)] (ADDshiftLL <x.Type> x x [2])))
1055 (MNEG x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) => (SLLconst <x.Type> [log64(c/7)] (SUBshiftLL <x.Type> x x [3]))
1056 (MNEG x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) => (NEG (SLLconst <x.Type> [log64(c/9)] (ADDshiftLL <x.Type> x x [3])))
1057
1058
1059 (MNEGW x (MOVDconst [c])) && int32(c)==-1 => (MOVWUreg x)
1060 (MNEGW _ (MOVDconst [c])) && int32(c)==0 => (MOVDconst [0])
1061 (MNEGW x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg (NEG <x.Type> x))
1062 (MNEGW x (MOVDconst [c])) && isPowerOfTwo(c) => (NEG (SLLconst <x.Type> [log64(c)] x))
1063 (MNEGW x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c) >= 3 => (MOVWUreg (NEG <x.Type> (ADDshiftLL <x.Type> x x [log64(c-1)])))
1064 (MNEGW x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c) >= 7 => (MOVWUreg (NEG <x.Type> (ADDshiftLL <x.Type> (NEG <x.Type> x) x [log64(c+1)])))
1065 (MNEGW x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) => (MOVWUreg (SLLconst <x.Type> [log64(c/3)] (SUBshiftLL <x.Type> x x [2])))
1066 (MNEGW x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) => (MOVWUreg (NEG <x.Type> (SLLconst <x.Type> [log64(c/5)] (ADDshiftLL <x.Type> x x [2]))))
1067 (MNEGW x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) => (MOVWUreg (SLLconst <x.Type> [log64(c/7)] (SUBshiftLL <x.Type> x x [3])))
1068 (MNEGW x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) => (MOVWUreg (NEG <x.Type> (SLLconst <x.Type> [log64(c/9)] (ADDshiftLL <x.Type> x x [3]))))
1069
1070
1071 (MADD a x (MOVDconst [-1])) => (SUB a x)
1072 (MADD a _ (MOVDconst [0])) => a
1073 (MADD a x (MOVDconst [1])) => (ADD a x)
1074 (MADD a x (MOVDconst [c])) && isPowerOfTwo(c) => (ADDshiftLL a x [log64(c)])
1075 (MADD a x (MOVDconst [c])) && isPowerOfTwo(c-1) && c>=3 => (ADD a (ADDshiftLL <x.Type> x x [log64(c-1)]))
1076 (MADD a x (MOVDconst [c])) && isPowerOfTwo(c+1) && c>=7 => (SUB a (SUBshiftLL <x.Type> x x [log64(c+1)]))
1077 (MADD a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)])
1078 (MADD a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)])
1079 (MADD a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)])
1080 (MADD a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)])
1081
1082 (MADD a (MOVDconst [-1]) x) => (SUB a x)
1083 (MADD a (MOVDconst [0]) _) => a
1084 (MADD a (MOVDconst [1]) x) => (ADD a x)
1085 (MADD a (MOVDconst [c]) x) && isPowerOfTwo(c) => (ADDshiftLL a x [log64(c)])
1086 (MADD a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && c>=3 => (ADD a (ADDshiftLL <x.Type> x x [log64(c-1)]))
1087 (MADD a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && c>=7 => (SUB a (SUBshiftLL <x.Type> x x [log64(c+1)]))
1088 (MADD a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)])
1089 (MADD a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)])
1090 (MADD a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)])
1091 (MADD a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)])
1092
1093 (MADDW a x (MOVDconst [c])) && int32(c)==-1 => (MOVWUreg (SUB <a.Type> a x))
1094 (MADDW a _ (MOVDconst [c])) && int32(c)==0 => (MOVWUreg a)
1095 (MADDW a x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg (ADD <a.Type> a x))
1096 (MADDW a x (MOVDconst [c])) && isPowerOfTwo(c) => (MOVWUreg (ADDshiftLL <a.Type> a x [log64(c)]))
1097 (MADDW a x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (ADD <a.Type> a (ADDshiftLL <x.Type> x x [log64(c-1)])))
1098 (MADDW a x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (SUB <a.Type> a (SUBshiftLL <x.Type> x x [log64(c+1)])))
1099 (MADDW a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)]))
1100 (MADDW a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)]))
1101 (MADDW a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)]))
1102 (MADDW a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)]))
1103
1104 (MADDW a (MOVDconst [c]) x) && int32(c)==-1 => (MOVWUreg (SUB <a.Type> a x))
1105 (MADDW a (MOVDconst [c]) _) && int32(c)==0 => (MOVWUreg a)
1106 (MADDW a (MOVDconst [c]) x) && int32(c)==1 => (MOVWUreg (ADD <a.Type> a x))
1107 (MADDW a (MOVDconst [c]) x) && isPowerOfTwo(c) => (MOVWUreg (ADDshiftLL <a.Type> a x [log64(c)]))
1108 (MADDW a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (ADD <a.Type> a (ADDshiftLL <x.Type> x x [log64(c-1)])))
1109 (MADDW a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (SUB <a.Type> a (SUBshiftLL <x.Type> x x [log64(c+1)])))
1110 (MADDW a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)]))
1111 (MADDW a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)]))
1112 (MADDW a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)]))
1113 (MADDW a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)]))
1114
1115 (MSUB a x (MOVDconst [-1])) => (ADD a x)
1116 (MSUB a _ (MOVDconst [0])) => a
1117 (MSUB a x (MOVDconst [1])) => (SUB a x)
1118 (MSUB a x (MOVDconst [c])) && isPowerOfTwo(c) => (SUBshiftLL a x [log64(c)])
1119 (MSUB a x (MOVDconst [c])) && isPowerOfTwo(c-1) && c>=3 => (SUB a (ADDshiftLL <x.Type> x x [log64(c-1)]))
1120 (MSUB a x (MOVDconst [c])) && isPowerOfTwo(c+1) && c>=7 => (ADD a (SUBshiftLL <x.Type> x x [log64(c+1)]))
1121 (MSUB a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)])
1122 (MSUB a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)])
1123 (MSUB a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)])
1124 (MSUB a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)])
1125
1126 (MSUB a (MOVDconst [-1]) x) => (ADD a x)
1127 (MSUB a (MOVDconst [0]) _) => a
1128 (MSUB a (MOVDconst [1]) x) => (SUB a x)
1129 (MSUB a (MOVDconst [c]) x) && isPowerOfTwo(c) => (SUBshiftLL a x [log64(c)])
1130 (MSUB a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && c>=3 => (SUB a (ADDshiftLL <x.Type> x x [log64(c-1)]))
1131 (MSUB a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && c>=7 => (ADD a (SUBshiftLL <x.Type> x x [log64(c+1)]))
1132 (MSUB a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)])
1133 (MSUB a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)])
1134 (MSUB a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)])
1135 (MSUB a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)])
1136
1137 (MSUBW a x (MOVDconst [c])) && int32(c)==-1 => (MOVWUreg (ADD <a.Type> a x))
1138 (MSUBW a _ (MOVDconst [c])) && int32(c)==0 => (MOVWUreg a)
1139 (MSUBW a x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg (SUB <a.Type> a x))
1140 (MSUBW a x (MOVDconst [c])) && isPowerOfTwo(c) => (MOVWUreg (SUBshiftLL <a.Type> a x [log64(c)]))
1141 (MSUBW a x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (SUB <a.Type> a (ADDshiftLL <x.Type> x x [log64(c-1)])))
1142 (MSUBW a x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (ADD <a.Type> a (SUBshiftLL <x.Type> x x [log64(c+1)])))
1143 (MSUBW a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)]))
1144 (MSUBW a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)]))
1145 (MSUBW a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)]))
1146 (MSUBW a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)]))
1147
1148 (MSUBW a (MOVDconst [c]) x) && int32(c)==-1 => (MOVWUreg (ADD <a.Type> a x))
1149 (MSUBW a (MOVDconst [c]) _) && int32(c)==0 => (MOVWUreg a)
1150 (MSUBW a (MOVDconst [c]) x) && int32(c)==1 => (MOVWUreg (SUB <a.Type> a x))
1151 (MSUBW a (MOVDconst [c]) x) && isPowerOfTwo(c) => (MOVWUreg (SUBshiftLL <a.Type> a x [log64(c)]))
1152 (MSUBW a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (SUB <a.Type> a (ADDshiftLL <x.Type> x x [log64(c-1)])))
1153 (MSUBW a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (ADD <a.Type> a (SUBshiftLL <x.Type> x x [log64(c+1)])))
1154 (MSUBW a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [2]) [log64(c/3)]))
1155 (MSUBW a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [2]) [log64(c/5)]))
1156 (MSUBW a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) => (MOVWUreg (ADDshiftLL <a.Type> a (SUBshiftLL <x.Type> x x [3]) [log64(c/7)]))
1157 (MSUBW a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) => (MOVWUreg (SUBshiftLL <a.Type> a (ADDshiftLL <x.Type> x x [3]) [log64(c/9)]))
1158
1159 // div by constant
1160 (UDIV x (MOVDconst [1])) => x
1161 (UDIV x (MOVDconst [c])) && isPowerOfTwo(c) => (SRLconst [log64(c)] x)
1162 (UDIVW x (MOVDconst [c])) && uint32(c)==1 => (MOVWUreg x)
1163 (UDIVW x (MOVDconst [c])) && isPowerOfTwo(c) && is32Bit(c) => (SRLconst [log64(c)] (MOVWUreg <v.Type> x))
1164 (UMOD _ (MOVDconst [1])) => (MOVDconst [0])
1165 (UMOD x (MOVDconst [c])) && isPowerOfTwo(c) => (ANDconst [c-1] x)
1166 (UMODW _ (MOVDconst [c])) && uint32(c)==1 => (MOVDconst [0])
1167 (UMODW x (MOVDconst [c])) && isPowerOfTwo(c) && is32Bit(c) => (ANDconst [c-1] x)
1168
1169 // generic simplifications
1170 (ADD x (NEG y)) => (SUB x y)
1171 (SUB x (NEG y)) => (ADD x y)
1172 (SUB x x) => (MOVDconst [0])
1173 (AND x x) => x
1174 (OR x x) => x
1175 (XOR x x) => (MOVDconst [0])
1176 (BIC x x) => (MOVDconst [0])
1177 (EON x x) => (MOVDconst [-1])
1178 (ORN x x) => (MOVDconst [-1])
1179 (AND x (MVN y)) => (BIC x y)
1180 (XOR x (MVN y)) => (EON x y)
1181 (OR x (MVN y)) => (ORN x y)
1182 (MVN (XOR x y)) => (EON x y)
1183 (NEG (SUB x y)) => (SUB y x)
1184 (NEG (NEG x)) => x
1185
1186 (CSEL [cc] (MOVDconst [-1]) (MOVDconst [0]) flag) => (CSETM [cc] flag)
1187 (CSEL [cc] (MOVDconst [0]) (MOVDconst [-1]) flag) => (CSETM [arm64Negate(cc)] flag)
1188 (CSEL [cc] x (MOVDconst [0]) flag) => (CSEL0 [cc] x flag)
1189 (CSEL [cc] (MOVDconst [0]) y flag) => (CSEL0 [arm64Negate(cc)] y flag)
1190 (CSEL [cc] x (ADDconst [1] a) flag) => (CSINC [cc] x a flag)
1191 (CSEL [cc] (ADDconst [1] a) x flag) => (CSINC [arm64Negate(cc)] x a flag)
1192 (CSEL [cc] x (MVN a) flag) => (CSINV [cc] x a flag)
1193 (CSEL [cc] (MVN a) x flag) => (CSINV [arm64Negate(cc)] x a flag)
1194 (CSEL [cc] x (NEG a) flag) => (CSNEG [cc] x a flag)
1195 (CSEL [cc] (NEG a) x flag) => (CSNEG [arm64Negate(cc)] x a flag)
1196
1197 (SUB x (SUB y z)) => (SUB (ADD <v.Type> x z) y)
1198 (SUB (SUB x y) z) => (SUB x (ADD <y.Type> y z))
1199
1200 // remove redundant *const ops
1201 (ADDconst [0] x) => x
1202 (SUBconst [0] x) => x
1203 (ANDconst [0] _) => (MOVDconst [0])
1204 (ANDconst [-1] x) => x
1205 (ORconst [0] x) => x
1206 (ORconst [-1] _) => (MOVDconst [-1])
1207 (XORconst [0] x) => x
1208 (XORconst [-1] x) => (MVN x)
1209
1210 // generic constant folding
1211 (ADDconst [c] (MOVDconst [d])) => (MOVDconst [c+d])
1212 (ADDconst [c] (ADDconst [d] x)) => (ADDconst [c+d] x)
1213 (ADDconst [c] (SUBconst [d] x)) => (ADDconst [c-d] x)
1214 (SUBconst [c] (MOVDconst [d])) => (MOVDconst [d-c])
1215 (SUBconst [c] (SUBconst [d] x)) => (ADDconst [-c-d] x)
1216 (SUBconst [c] (ADDconst [d] x)) => (ADDconst [-c+d] x)
1217 (SLLconst [c] (MOVDconst [d])) => (MOVDconst [d<<uint64(c)])
1218 (SRLconst [c] (MOVDconst [d])) => (MOVDconst [int64(uint64(d)>>uint64(c))])
1219 (SRAconst [c] (MOVDconst [d])) => (MOVDconst [d>>uint64(c)])
1220 (MUL (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [c*d])
1221 (MNEG (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [-c*d])
1222 (MULW (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [int64(uint32(c*d))])
1223 (MNEGW (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [int64(uint32(-c*d))])
1224 (MADD (MOVDconst [c]) x y) => (ADDconst [c] (MUL <x.Type> x y))
1225 (MSUB (MOVDconst [c]) x y) => (ADDconst [c] (MNEG <x.Type> x y))
1226 (MADD a (MOVDconst [c]) (MOVDconst [d])) => (ADDconst [c*d] a)
1227 (MSUB a (MOVDconst [c]) (MOVDconst [d])) => (SUBconst [c*d] a)
1228 (MADDW (MOVDconst [c]) x y) => (MOVWUreg (ADDconst <x.Type> [c] (MULW <x.Type> x y)))
1229 (MSUBW (MOVDconst [c]) x y) => (MOVWUreg (ADDconst <x.Type> [c] (MNEGW <x.Type> x y)))
1230 (MADDW a (MOVDconst [c]) (MOVDconst [d])) => (MOVWUreg (ADDconst <a.Type> [c*d] a))
1231 (MSUBW a (MOVDconst [c]) (MOVDconst [d])) => (MOVWUreg (SUBconst <a.Type> [c*d] a))
1232 (DIV (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [c/d])
1233 (UDIV (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint64(c)/uint64(d))])
1234 (DIVW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(int32(c)/int32(d)))])
1235 (UDIVW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(c)/uint32(d))])
1236 (MOD (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [c%d])
1237 (UMOD (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint64(c)%uint64(d))])
1238 (MODW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(int32(c)%int32(d)))])
1239 (UMODW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(c)%uint32(d))])
1240 (ANDconst [c] (MOVDconst [d])) => (MOVDconst [c&d])
1241 (ANDconst [c] (ANDconst [d] x)) => (ANDconst [c&d] x)
1242 (ANDconst [c] (MOVWUreg x)) => (ANDconst [c&(1<<32-1)] x)
1243 (ANDconst [c] (MOVHUreg x)) => (ANDconst [c&(1<<16-1)] x)
1244 (ANDconst [c] (MOVBUreg x)) => (ANDconst [c&(1<<8-1)] x)
1245 (MOVWUreg (ANDconst [c] x)) => (ANDconst [c&(1<<32-1)] x)
1246 (MOVHUreg (ANDconst [c] x)) => (ANDconst [c&(1<<16-1)] x)
1247 (MOVBUreg (ANDconst [c] x)) => (ANDconst [c&(1<<8-1)] x)
1248 (ORconst [c] (MOVDconst [d])) => (MOVDconst [c|d])
1249 (ORconst [c] (ORconst [d] x)) => (ORconst [c|d] x)
1250 (XORconst [c] (MOVDconst [d])) => (MOVDconst [c^d])
1251 (XORconst [c] (XORconst [d] x)) => (XORconst [c^d] x)
1252 (MVN (MOVDconst [c])) => (MOVDconst [^c])
1253 (NEG (MOVDconst [c])) => (MOVDconst [-c])
1254 (MOVBreg (MOVDconst [c])) => (MOVDconst [int64(int8(c))])
1255 (MOVBUreg (MOVDconst [c])) => (MOVDconst [int64(uint8(c))])
1256 (MOVHreg (MOVDconst [c])) => (MOVDconst [int64(int16(c))])
1257 (MOVHUreg (MOVDconst [c])) => (MOVDconst [int64(uint16(c))])
1258 (MOVWreg (MOVDconst [c])) => (MOVDconst [int64(int32(c))])
1259 (MOVWUreg (MOVDconst [c])) => (MOVDconst [int64(uint32(c))])
1260 (MOVDreg (MOVDconst [c])) => (MOVDconst [c])
1261
1262 // constant comparisons
1263 (CMPconst (MOVDconst [x]) [y]) => (FlagConstant [subFlags64(x,y)])
1264 (CMPWconst (MOVDconst [x]) [y]) => (FlagConstant [subFlags32(int32(x),y)])
1265 (TSTconst (MOVDconst [x]) [y]) => (FlagConstant [logicFlags64(x&y)])
1266 (TSTWconst (MOVDconst [x]) [y]) => (FlagConstant [logicFlags32(int32(x)&y)])
1267 (CMNconst (MOVDconst [x]) [y]) => (FlagConstant [addFlags64(x,y)])
1268 (CMNWconst (MOVDconst [x]) [y]) => (FlagConstant [addFlags32(int32(x),y)])
1269
1270 // other known comparisons
1271 (CMPconst (MOVBUreg _) [c]) && 0xff < c => (FlagConstant [subFlags64(0,1)])
1272 (CMPconst (MOVHUreg _) [c]) && 0xffff < c => (FlagConstant [subFlags64(0,1)])
1273 (CMPconst (MOVWUreg _) [c]) && 0xffffffff < c => (FlagConstant [subFlags64(0,1)])
1274 (CMPconst (ANDconst _ [m]) [n]) && 0 <= m && m < n => (FlagConstant [subFlags64(0,1)])
1275 (CMPconst (SRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 63 && (1<<uint64(64-c)) <= uint64(n) => (FlagConstant [subFlags64(0,1)])
1276 (CMPWconst (MOVBUreg _) [c]) && 0xff < c => (FlagConstant [subFlags64(0,1)])
1277 (CMPWconst (MOVHUreg _) [c]) && 0xffff < c => (FlagConstant [subFlags64(0,1)])
1278
1279 // absorb flag constants into branches
1280 (EQ (FlagConstant [fc]) yes no) && fc.eq() => (First yes no)
1281 (EQ (FlagConstant [fc]) yes no) && !fc.eq() => (First no yes)
1282
1283 (NE (FlagConstant [fc]) yes no) && fc.ne() => (First yes no)
1284 (NE (FlagConstant [fc]) yes no) && !fc.ne() => (First no yes)
1285
1286 (LT (FlagConstant [fc]) yes no) && fc.lt() => (First yes no)
1287 (LT (FlagConstant [fc]) yes no) && !fc.lt() => (First no yes)
1288
1289 (LE (FlagConstant [fc]) yes no) && fc.le() => (First yes no)
1290 (LE (FlagConstant [fc]) yes no) && !fc.le() => (First no yes)
1291
1292 (GT (FlagConstant [fc]) yes no) && fc.gt() => (First yes no)
1293 (GT (FlagConstant [fc]) yes no) && !fc.gt() => (First no yes)
1294
1295 (GE (FlagConstant [fc]) yes no) && fc.ge() => (First yes no)
1296 (GE (FlagConstant [fc]) yes no) && !fc.ge() => (First no yes)
1297
1298 (ULT (FlagConstant [fc]) yes no) && fc.ult() => (First yes no)
1299 (ULT (FlagConstant [fc]) yes no) && !fc.ult() => (First no yes)
1300
1301 (ULE (FlagConstant [fc]) yes no) && fc.ule() => (First yes no)
1302 (ULE (FlagConstant [fc]) yes no) && !fc.ule() => (First no yes)
1303
1304 (UGT (FlagConstant [fc]) yes no) && fc.ugt() => (First yes no)
1305 (UGT (FlagConstant [fc]) yes no) && !fc.ugt() => (First no yes)
1306
1307 (UGE (FlagConstant [fc]) yes no) && fc.uge() => (First yes no)
1308 (UGE (FlagConstant [fc]) yes no) && !fc.uge() => (First no yes)
1309
1310 (LTnoov (FlagConstant [fc]) yes no) && fc.ltNoov() => (First yes no)
1311 (LTnoov (FlagConstant [fc]) yes no) && !fc.ltNoov() => (First no yes)
1312
1313 (LEnoov (FlagConstant [fc]) yes no) && fc.leNoov() => (First yes no)
1314 (LEnoov (FlagConstant [fc]) yes no) && !fc.leNoov() => (First no yes)
1315
1316 (GTnoov (FlagConstant [fc]) yes no) && fc.gtNoov() => (First yes no)
1317 (GTnoov (FlagConstant [fc]) yes no) && !fc.gtNoov() => (First no yes)
1318
1319 (GEnoov (FlagConstant [fc]) yes no) && fc.geNoov() => (First yes no)
1320 (GEnoov (FlagConstant [fc]) yes no) && !fc.geNoov() => (First no yes)
1321
1322 (Z (MOVDconst [0]) yes no) => (First yes no)
1323 (Z (MOVDconst [c]) yes no) && c != 0 => (First no yes)
1324 (NZ (MOVDconst [0]) yes no) => (First no yes)
1325 (NZ (MOVDconst [c]) yes no) && c != 0 => (First yes no)
1326 (ZW (MOVDconst [c]) yes no) && int32(c) == 0 => (First yes no)
1327 (ZW (MOVDconst [c]) yes no) && int32(c) != 0 => (First no yes)
1328 (NZW (MOVDconst [c]) yes no) && int32(c) == 0 => (First no yes)
1329 (NZW (MOVDconst [c]) yes no) && int32(c) != 0 => (First yes no)
1330
1331 // absorb InvertFlags into branches
1332 (LT (InvertFlags cmp) yes no) => (GT cmp yes no)
1333 (GT (InvertFlags cmp) yes no) => (LT cmp yes no)
1334 (LE (InvertFlags cmp) yes no) => (GE cmp yes no)
1335 (GE (InvertFlags cmp) yes no) => (LE cmp yes no)
1336 (ULT (InvertFlags cmp) yes no) => (UGT cmp yes no)
1337 (UGT (InvertFlags cmp) yes no) => (ULT cmp yes no)
1338 (ULE (InvertFlags cmp) yes no) => (UGE cmp yes no)
1339 (UGE (InvertFlags cmp) yes no) => (ULE cmp yes no)
1340 (EQ (InvertFlags cmp) yes no) => (EQ cmp yes no)
1341 (NE (InvertFlags cmp) yes no) => (NE cmp yes no)
1342 (FLT (InvertFlags cmp) yes no) => (FGT cmp yes no)
1343 (FGT (InvertFlags cmp) yes no) => (FLT cmp yes no)
1344 (FLE (InvertFlags cmp) yes no) => (FGE cmp yes no)
1345 (FGE (InvertFlags cmp) yes no) => (FLE cmp yes no)
1346 (LTnoov (InvertFlags cmp) yes no) => (GTnoov cmp yes no)
1347 (GEnoov (InvertFlags cmp) yes no) => (LEnoov cmp yes no)
1348 (LEnoov (InvertFlags cmp) yes no) => (GEnoov cmp yes no)
1349 (GTnoov (InvertFlags cmp) yes no) => (LTnoov cmp yes no)
1350
1351 // absorb InvertFlags into conditional instructions
1352 (CSEL [cc] x y (InvertFlags cmp)) => (CSEL [arm64Invert(cc)] x y cmp)
1353 (CSEL0 [cc] x (InvertFlags cmp)) => (CSEL0 [arm64Invert(cc)] x cmp)
1354 (CSETM [cc] (InvertFlags cmp)) => (CSETM [arm64Invert(cc)] cmp)
1355 (CSINC [cc] x y (InvertFlags cmp)) => (CSINC [arm64Invert(cc)] x y cmp)
1356 (CSINV [cc] x y (InvertFlags cmp)) => (CSINV [arm64Invert(cc)] x y cmp)
1357 (CSNEG [cc] x y (InvertFlags cmp)) => (CSNEG [arm64Invert(cc)] x y cmp)
1358
1359 // absorb flag constants into boolean values
1360 (Equal (FlagConstant [fc])) => (MOVDconst [b2i(fc.eq())])
1361 (NotEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.ne())])
1362 (LessThan (FlagConstant [fc])) => (MOVDconst [b2i(fc.lt())])
1363 (LessThanU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ult())])
1364 (LessEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.le())])
1365 (LessEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ule())])
1366 (GreaterThan (FlagConstant [fc])) => (MOVDconst [b2i(fc.gt())])
1367 (GreaterThanU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ugt())])
1368 (GreaterEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.ge())])
1369 (GreaterEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.uge())])
1370 (LessThanNoov (FlagConstant [fc])) => (MOVDconst [b2i(fc.ltNoov())])
1371 (GreaterEqualNoov (FlagConstant [fc])) => (MOVDconst [b2i(fc.geNoov())])
1372
1373 // absorb InvertFlags into boolean values
1374 (Equal (InvertFlags x)) => (Equal x)
1375 (NotEqual (InvertFlags x)) => (NotEqual x)
1376 (LessThan (InvertFlags x)) => (GreaterThan x)
1377 (LessThanU (InvertFlags x)) => (GreaterThanU x)
1378 (GreaterThan (InvertFlags x)) => (LessThan x)
1379 (GreaterThanU (InvertFlags x)) => (LessThanU x)
1380 (LessEqual (InvertFlags x)) => (GreaterEqual x)
1381 (LessEqualU (InvertFlags x)) => (GreaterEqualU x)
1382 (GreaterEqual (InvertFlags x)) => (LessEqual x)
1383 (GreaterEqualU (InvertFlags x)) => (LessEqualU x)
1384 (LessThanF (InvertFlags x)) => (GreaterThanF x)
1385 (LessEqualF (InvertFlags x)) => (GreaterEqualF x)
1386 (GreaterThanF (InvertFlags x)) => (LessThanF x)
1387 (GreaterEqualF (InvertFlags x)) => (LessEqualF x)
1388 (LessThanNoov (InvertFlags x)) => (CSEL0 [OpARM64NotEqual] (GreaterEqualNoov <typ.Bool> x) x)
1389 (GreaterEqualNoov (InvertFlags x)) => (CSINC [OpARM64NotEqual] (LessThanNoov <typ.Bool> x) (MOVDconst [0]) x)
1390
1391 // Don't bother extending if we're not using the higher bits.
1392 (MOV(B|BU)reg x) && v.Type.Size() <= 1 => x
1393 (MOV(H|HU)reg x) && v.Type.Size() <= 2 => x
1394 (MOV(W|WU)reg x) && v.Type.Size() <= 4 => x
1395
1396 // omit sign extension
1397 (MOVWreg <t> (ANDconst x [c])) && uint64(c) & uint64(0xffffffff80000000) == 0 => (ANDconst <t> x [c])
1398 (MOVHreg <t> (ANDconst x [c])) && uint64(c) & uint64(0xffffffffffff8000) == 0 => (ANDconst <t> x [c])
1399 (MOVBreg <t> (ANDconst x [c])) && uint64(c) & uint64(0xffffffffffffff80) == 0 => (ANDconst <t> x [c])
1400
1401 // absorb flag constants into conditional instructions
1402 (CSEL [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1403 (CSEL [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => y
1404 (CSEL0 [cc] x flag) && ccARM64Eval(cc, flag) > 0 => x
1405 (CSEL0 [cc] _ flag) && ccARM64Eval(cc, flag) < 0 => (MOVDconst [0])
1406 (CSNEG [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1407 (CSNEG [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => (NEG y)
1408 (CSINV [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1409 (CSINV [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => (Not y)
1410 (CSINC [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1411 (CSINC [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => (ADDconst [1] y)
1412 (CSETM [cc] flag) && ccARM64Eval(cc, flag) > 0 => (MOVDconst [-1])
1413 (CSETM [cc] flag) && ccARM64Eval(cc, flag) < 0 => (MOVDconst [0])
1414
1415 // absorb flags back into boolean CSEL
1416 (CSEL [cc] x y (CMPWconst [0] boolval)) && cc == OpARM64NotEqual && flagArg(boolval) != nil =>
1417 (CSEL [boolval.Op] x y flagArg(boolval))
1418 (CSEL [cc] x y (CMPWconst [0] boolval)) && cc == OpARM64Equal && flagArg(boolval) != nil =>
1419 (CSEL [arm64Negate(boolval.Op)] x y flagArg(boolval))
1420 (CSEL0 [cc] x (CMPWconst [0] boolval)) && cc == OpARM64NotEqual && flagArg(boolval) != nil =>
1421 (CSEL0 [boolval.Op] x flagArg(boolval))
1422 (CSEL0 [cc] x (CMPWconst [0] boolval)) && cc == OpARM64Equal && flagArg(boolval) != nil =>
1423 (CSEL0 [arm64Negate(boolval.Op)] x flagArg(boolval))
1424
1425 // absorb shifts into ops
1426 (NEG x:(SLLconst [c] y)) && clobberIfDead(x) => (NEGshiftLL [c] y)
1427 (NEG x:(SRLconst [c] y)) && clobberIfDead(x) => (NEGshiftRL [c] y)
1428 (NEG x:(SRAconst [c] y)) && clobberIfDead(x) => (NEGshiftRA [c] y)
1429 (MVN x:(SLLconst [c] y)) && clobberIfDead(x) => (MVNshiftLL [c] y)
1430 (MVN x:(SRLconst [c] y)) && clobberIfDead(x) => (MVNshiftRL [c] y)
1431 (MVN x:(SRAconst [c] y)) && clobberIfDead(x) => (MVNshiftRA [c] y)
1432 (MVN x:(RORconst [c] y)) && clobberIfDead(x) => (MVNshiftRO [c] y)
1433 (ADD x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (ADDshiftLL x0 y [c])
1434 (ADD x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (ADDshiftRL x0 y [c])
1435 (ADD x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (ADDshiftRA x0 y [c])
1436 (SUB x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (SUBshiftLL x0 y [c])
1437 (SUB x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (SUBshiftRL x0 y [c])
1438 (SUB x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (SUBshiftRA x0 y [c])
1439 (AND x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (ANDshiftLL x0 y [c])
1440 (AND x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (ANDshiftRL x0 y [c])
1441 (AND x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (ANDshiftRA x0 y [c])
1442 (AND x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (ANDshiftRO x0 y [c])
1443 (OR x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (ORshiftLL x0 y [c]) // useful for combined load
1444 (OR x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (ORshiftRL x0 y [c])
1445 (OR x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (ORshiftRA x0 y [c])
1446 (OR x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (ORshiftRO x0 y [c])
1447 (XOR x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (XORshiftLL x0 y [c])
1448 (XOR x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (XORshiftRL x0 y [c])
1449 (XOR x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (XORshiftRA x0 y [c])
1450 (XOR x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (XORshiftRO x0 y [c])
1451 (BIC x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (BICshiftLL x0 y [c])
1452 (BIC x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (BICshiftRL x0 y [c])
1453 (BIC x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (BICshiftRA x0 y [c])
1454 (BIC x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (BICshiftRO x0 y [c])
1455 (ORN x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (ORNshiftLL x0 y [c])
1456 (ORN x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (ORNshiftRL x0 y [c])
1457 (ORN x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (ORNshiftRA x0 y [c])
1458 (ORN x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (ORNshiftRO x0 y [c])
1459 (EON x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (EONshiftLL x0 y [c])
1460 (EON x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (EONshiftRL x0 y [c])
1461 (EON x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (EONshiftRA x0 y [c])
1462 (EON x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (EONshiftRO x0 y [c])
1463 (CMP x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (CMPshiftLL x0 y [c])
1464 (CMP x0:(SLLconst [c] y) x1) && clobberIfDead(x0) => (InvertFlags (CMPshiftLL x1 y [c]))
1465 (CMP x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (CMPshiftRL x0 y [c])
1466 (CMP x0:(SRLconst [c] y) x1) && clobberIfDead(x0) => (InvertFlags (CMPshiftRL x1 y [c]))
1467 (CMP x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (CMPshiftRA x0 y [c])
1468 (CMP x0:(SRAconst [c] y) x1) && clobberIfDead(x0) => (InvertFlags (CMPshiftRA x1 y [c]))
1469 (CMN x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (CMNshiftLL x0 y [c])
1470 (CMN x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (CMNshiftRL x0 y [c])
1471 (CMN x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (CMNshiftRA x0 y [c])
1472 (TST x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) => (TSTshiftLL x0 y [c])
1473 (TST x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) => (TSTshiftRL x0 y [c])
1474 (TST x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) => (TSTshiftRA x0 y [c])
1475 (TST x0 x1:(RORconst [c] y)) && clobberIfDead(x1) => (TSTshiftRO x0 y [c])
1476
1477 // prefer *const ops to *shift ops
1478 (ADDshiftLL (MOVDconst [c]) x [d]) => (ADDconst [c] (SLLconst <x.Type> x [d]))
1479 (ADDshiftRL (MOVDconst [c]) x [d]) => (ADDconst [c] (SRLconst <x.Type> x [d]))
1480 (ADDshiftRA (MOVDconst [c]) x [d]) => (ADDconst [c] (SRAconst <x.Type> x [d]))
1481 (ANDshiftLL (MOVDconst [c]) x [d]) => (ANDconst [c] (SLLconst <x.Type> x [d]))
1482 (ANDshiftRL (MOVDconst [c]) x [d]) => (ANDconst [c] (SRLconst <x.Type> x [d]))
1483 (ANDshiftRA (MOVDconst [c]) x [d]) => (ANDconst [c] (SRAconst <x.Type> x [d]))
1484 (ANDshiftRO (MOVDconst [c]) x [d]) => (ANDconst [c] (RORconst <x.Type> x [d]))
1485 (ORshiftLL (MOVDconst [c]) x [d]) => (ORconst [c] (SLLconst <x.Type> x [d]))
1486 (ORshiftRL (MOVDconst [c]) x [d]) => (ORconst [c] (SRLconst <x.Type> x [d]))
1487 (ORshiftRA (MOVDconst [c]) x [d]) => (ORconst [c] (SRAconst <x.Type> x [d]))
1488 (ORshiftRO (MOVDconst [c]) x [d]) => (ORconst [c] (RORconst <x.Type> x [d]))
1489 (XORshiftLL (MOVDconst [c]) x [d]) => (XORconst [c] (SLLconst <x.Type> x [d]))
1490 (XORshiftRL (MOVDconst [c]) x [d]) => (XORconst [c] (SRLconst <x.Type> x [d]))
1491 (XORshiftRA (MOVDconst [c]) x [d]) => (XORconst [c] (SRAconst <x.Type> x [d]))
1492 (XORshiftRO (MOVDconst [c]) x [d]) => (XORconst [c] (RORconst <x.Type> x [d]))
1493 (CMPshiftLL (MOVDconst [c]) x [d]) => (InvertFlags (CMPconst [c] (SLLconst <x.Type> x [d])))
1494 (CMPshiftRL (MOVDconst [c]) x [d]) => (InvertFlags (CMPconst [c] (SRLconst <x.Type> x [d])))
1495 (CMPshiftRA (MOVDconst [c]) x [d]) => (InvertFlags (CMPconst [c] (SRAconst <x.Type> x [d])))
1496 (CMNshiftLL (MOVDconst [c]) x [d]) => (CMNconst [c] (SLLconst <x.Type> x [d]))
1497 (CMNshiftRL (MOVDconst [c]) x [d]) => (CMNconst [c] (SRLconst <x.Type> x [d]))
1498 (CMNshiftRA (MOVDconst [c]) x [d]) => (CMNconst [c] (SRAconst <x.Type> x [d]))
1499 (TSTshiftLL (MOVDconst [c]) x [d]) => (TSTconst [c] (SLLconst <x.Type> x [d]))
1500 (TSTshiftRL (MOVDconst [c]) x [d]) => (TSTconst [c] (SRLconst <x.Type> x [d]))
1501 (TSTshiftRA (MOVDconst [c]) x [d]) => (TSTconst [c] (SRAconst <x.Type> x [d]))
1502 (TSTshiftRO (MOVDconst [c]) x [d]) => (TSTconst [c] (RORconst <x.Type> x [d]))
1503
1504 // constant folding in *shift ops
1505 (MVNshiftLL (MOVDconst [c]) [d]) => (MOVDconst [^int64(uint64(c)<<uint64(d))])
1506 (MVNshiftRL (MOVDconst [c]) [d]) => (MOVDconst [^int64(uint64(c)>>uint64(d))])
1507 (MVNshiftRA (MOVDconst [c]) [d]) => (MOVDconst [^(c>>uint64(d))])
1508 (MVNshiftRO (MOVDconst [c]) [d]) => (MOVDconst [^rotateRight64(c, d)])
1509 (NEGshiftLL (MOVDconst [c]) [d]) => (MOVDconst [-int64(uint64(c)<<uint64(d))])
1510 (NEGshiftRL (MOVDconst [c]) [d]) => (MOVDconst [-int64(uint64(c)>>uint64(d))])
1511 (NEGshiftRA (MOVDconst [c]) [d]) => (MOVDconst [-(c>>uint64(d))])
1512 (ADDshiftLL x (MOVDconst [c]) [d]) => (ADDconst x [int64(uint64(c)<<uint64(d))])
1513 (ADDshiftRL x (MOVDconst [c]) [d]) => (ADDconst x [int64(uint64(c)>>uint64(d))])
1514 (ADDshiftRA x (MOVDconst [c]) [d]) => (ADDconst x [c>>uint64(d)])
1515 (SUBshiftLL x (MOVDconst [c]) [d]) => (SUBconst x [int64(uint64(c)<<uint64(d))])
1516 (SUBshiftRL x (MOVDconst [c]) [d]) => (SUBconst x [int64(uint64(c)>>uint64(d))])
1517 (SUBshiftRA x (MOVDconst [c]) [d]) => (SUBconst x [c>>uint64(d)])
1518 (ANDshiftLL x (MOVDconst [c]) [d]) => (ANDconst x [int64(uint64(c)<<uint64(d))])
1519 (ANDshiftRL x (MOVDconst [c]) [d]) => (ANDconst x [int64(uint64(c)>>uint64(d))])
1520 (ANDshiftRA x (MOVDconst [c]) [d]) => (ANDconst x [c>>uint64(d)])
1521 (ANDshiftRO x (MOVDconst [c]) [d]) => (ANDconst x [rotateRight64(c, d)])
1522 (ORshiftLL x (MOVDconst [c]) [d]) => (ORconst x [int64(uint64(c)<<uint64(d))])
1523 (ORshiftRL x (MOVDconst [c]) [d]) => (ORconst x [int64(uint64(c)>>uint64(d))])
1524 (ORshiftRA x (MOVDconst [c]) [d]) => (ORconst x [c>>uint64(d)])
1525 (ORshiftRO x (MOVDconst [c]) [d]) => (ORconst x [rotateRight64(c, d)])
1526 (XORshiftLL x (MOVDconst [c]) [d]) => (XORconst x [int64(uint64(c)<<uint64(d))])
1527 (XORshiftRL x (MOVDconst [c]) [d]) => (XORconst x [int64(uint64(c)>>uint64(d))])
1528 (XORshiftRA x (MOVDconst [c]) [d]) => (XORconst x [c>>uint64(d)])
1529 (XORshiftRO x (MOVDconst [c]) [d]) => (XORconst x [rotateRight64(c, d)])
1530 (BICshiftLL x (MOVDconst [c]) [d]) => (ANDconst x [^int64(uint64(c)<<uint64(d))])
1531 (BICshiftRL x (MOVDconst [c]) [d]) => (ANDconst x [^int64(uint64(c)>>uint64(d))])
1532 (BICshiftRA x (MOVDconst [c]) [d]) => (ANDconst x [^(c>>uint64(d))])
1533 (BICshiftRO x (MOVDconst [c]) [d]) => (ANDconst x [^rotateRight64(c, d)])
1534 (ORNshiftLL x (MOVDconst [c]) [d]) => (ORconst x [^int64(uint64(c)<<uint64(d))])
1535 (ORNshiftRL x (MOVDconst [c]) [d]) => (ORconst x [^int64(uint64(c)>>uint64(d))])
1536 (ORNshiftRA x (MOVDconst [c]) [d]) => (ORconst x [^(c>>uint64(d))])
1537 (ORNshiftRO x (MOVDconst [c]) [d]) => (ORconst x [^rotateRight64(c, d)])
1538 (EONshiftLL x (MOVDconst [c]) [d]) => (XORconst x [^int64(uint64(c)<<uint64(d))])
1539 (EONshiftRL x (MOVDconst [c]) [d]) => (XORconst x [^int64(uint64(c)>>uint64(d))])
1540 (EONshiftRA x (MOVDconst [c]) [d]) => (XORconst x [^(c>>uint64(d))])
1541 (EONshiftRO x (MOVDconst [c]) [d]) => (XORconst x [^rotateRight64(c, d)])
1542 (CMPshiftLL x (MOVDconst [c]) [d]) => (CMPconst x [int64(uint64(c)<<uint64(d))])
1543 (CMPshiftRL x (MOVDconst [c]) [d]) => (CMPconst x [int64(uint64(c)>>uint64(d))])
1544 (CMPshiftRA x (MOVDconst [c]) [d]) => (CMPconst x [c>>uint64(d)])
1545 (CMNshiftLL x (MOVDconst [c]) [d]) => (CMNconst x [int64(uint64(c)<<uint64(d))])
1546 (CMNshiftRL x (MOVDconst [c]) [d]) => (CMNconst x [int64(uint64(c)>>uint64(d))])
1547 (CMNshiftRA x (MOVDconst [c]) [d]) => (CMNconst x [c>>uint64(d)])
1548 (TSTshiftLL x (MOVDconst [c]) [d]) => (TSTconst x [int64(uint64(c)<<uint64(d))])
1549 (TSTshiftRL x (MOVDconst [c]) [d]) => (TSTconst x [int64(uint64(c)>>uint64(d))])
1550 (TSTshiftRA x (MOVDconst [c]) [d]) => (TSTconst x [c>>uint64(d)])
1551 (TSTshiftRO x (MOVDconst [c]) [d]) => (TSTconst x [rotateRight64(c, d)])
1552
1553 // simplification with *shift ops
1554 (SUBshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [0])
1555 (SUBshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [0])
1556 (SUBshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [0])
1557 (ANDshiftLL y:(SLLconst x [c]) x [c]) => y
1558 (ANDshiftRL y:(SRLconst x [c]) x [c]) => y
1559 (ANDshiftRA y:(SRAconst x [c]) x [c]) => y
1560 (ANDshiftRO y:(RORconst x [c]) x [c]) => y
1561 (ORshiftLL y:(SLLconst x [c]) x [c]) => y
1562 (ORshiftRL y:(SRLconst x [c]) x [c]) => y
1563 (ORshiftRA y:(SRAconst x [c]) x [c]) => y
1564 (ORshiftRO y:(RORconst x [c]) x [c]) => y
1565 (XORshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [0])
1566 (XORshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [0])
1567 (XORshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [0])
1568 (XORshiftRO (RORconst x [c]) x [c]) => (MOVDconst [0])
1569 (BICshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [0])
1570 (BICshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [0])
1571 (BICshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [0])
1572 (BICshiftRO (RORconst x [c]) x [c]) => (MOVDconst [0])
1573 (EONshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [-1])
1574 (EONshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [-1])
1575 (EONshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [-1])
1576 (EONshiftRO (RORconst x [c]) x [c]) => (MOVDconst [-1])
1577 (ORNshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [-1])
1578 (ORNshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [-1])
1579 (ORNshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [-1])
1580 (ORNshiftRO (RORconst x [c]) x [c]) => (MOVDconst [-1])
1581
1582 // rev16w | rev16
1583 // ((x>>8) | (x<<8)) => (REV16W x), the type of x is uint16, "|" can also be "^" or "+".
1584 ((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (UBFX <typ.UInt16> [armBFAuxInt(8, 8)] x) x) => (REV16W x)
1585
1586 // ((x & 0xff00ff00)>>8) | ((x & 0x00ff00ff)<<8), "|" can also be "^" or "+".
1587 ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (UBFX [armBFAuxInt(8, 24)] (ANDconst [c1] x)) (ANDconst [c2] x))
1588 && uint32(c1) == 0xff00ff00 && uint32(c2) == 0x00ff00ff
1589 => (REV16W x)
1590
1591 // ((x & 0xff00ff00ff00ff00)>>8) | ((x & 0x00ff00ff00ff00ff)<<8), "|" can also be "^" or "+".
1592 ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (SRLconst [8] (ANDconst [c1] x)) (ANDconst [c2] x))
1593 && (uint64(c1) == 0xff00ff00ff00ff00 && uint64(c2) == 0x00ff00ff00ff00ff)
1594 => (REV16 x)
1595
1596 // ((x & 0xff00ff00)>>8) | ((x & 0x00ff00ff)<<8), "|" can also be "^" or "+".
1597 ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (SRLconst [8] (ANDconst [c1] x)) (ANDconst [c2] x))
1598 && (uint64(c1) == 0xff00ff00 && uint64(c2) == 0x00ff00ff)
1599 => (REV16 (ANDconst <x.Type> [0xffffffff] x))
1600
1601 (REV16 (MOVWUreg x)) => (REV16W x)
1602
1603 // Extract from reg pair
1604 (ADDshiftLL [c] (SRLconst x [64-c]) x2) => (EXTRconst [64-c] x2 x)
1605 ( ORshiftLL [c] (SRLconst x [64-c]) x2) => (EXTRconst [64-c] x2 x)
1606 (XORshiftLL [c] (SRLconst x [64-c]) x2) => (EXTRconst [64-c] x2 x)
1607
1608 (ADDshiftLL <t> [c] (UBFX [bfc] x) x2) && c < 32 && t.Size() == 4 && bfc == armBFAuxInt(32-c, c)
1609 => (EXTRWconst [32-c] x2 x)
1610 ( ORshiftLL <t> [c] (UBFX [bfc] x) x2) && c < 32 && t.Size() == 4 && bfc == armBFAuxInt(32-c, c)
1611 => (EXTRWconst [32-c] x2 x)
1612 (XORshiftLL <t> [c] (UBFX [bfc] x) x2) && c < 32 && t.Size() == 4 && bfc == armBFAuxInt(32-c, c)
1613 => (EXTRWconst [32-c] x2 x)
1614
1615 // Rewrite special pairs of shifts to AND.
1616 // On ARM64 the bitmask can fit into an instruction.
1617 (SRLconst [c] (SLLconst [c] x)) && 0 < c && c < 64 => (ANDconst [1<<uint(64-c)-1] x) // mask out high bits
1618 (SLLconst [c] (SRLconst [c] x)) && 0 < c && c < 64 => (ANDconst [^(1<<uint(c)-1)] x) // mask out low bits
1619
1620 // Special case setting bit as 1. An example is math.Copysign(c,-1)
1621 (ORconst [c1] (ANDconst [c2] x)) && c2|c1 == ^0 => (ORconst [c1] x)
1622
1623 // If the shift amount is larger than the datasize(32, 16, 8), we can optimize to constant 0.
1624 (MOVWUreg (SLLconst [lc] x)) && lc >= 32 => (MOVDconst [0])
1625 (MOVHUreg (SLLconst [lc] x)) && lc >= 16 => (MOVDconst [0])
1626 (MOVBUreg (SLLconst [lc] x)) && lc >= 8 => (MOVDconst [0])
1627
1628 // After zero extension, the upper (64-datasize(32|16|8)) bits are zero, we can optimiza to constant 0.
1629 (SRLconst [rc] (MOVWUreg x)) && rc >= 32 => (MOVDconst [0])
1630 (SRLconst [rc] (MOVHUreg x)) && rc >= 16 => (MOVDconst [0])
1631 (SRLconst [rc] (MOVBUreg x)) && rc >= 8 => (MOVDconst [0])
1632
1633 // Special cases for slice operations
1634 (ADD x0 x1:(ANDshiftRA x2:(SLLconst [sl] y) z [63])) && x1.Uses == 1 && x2.Uses == 1 => (ADDshiftLL x0 (ANDshiftRA <y.Type> y z [63]) [sl])
1635 (ADD x0 x1:(ANDshiftLL x2:(SRAconst [63] z) y [sl])) && x1.Uses == 1 && x2.Uses == 1 => (ADDshiftLL x0 (ANDshiftRA <y.Type> y z [63]) [sl])
1636
1637 // bitfield ops
1638
1639 // sbfiz
1640 // (x << lc) >> rc
1641 (SRAconst [rc] (SLLconst [lc] x)) && lc > rc => (SBFIZ [armBFAuxInt(lc-rc, 64-lc)] x)
1642 // int64(x << lc)
1643 (MOVWreg (SLLconst [lc] x)) && lc < 32 => (SBFIZ [armBFAuxInt(lc, 32-lc)] x)
1644 (MOVHreg (SLLconst [lc] x)) && lc < 16 => (SBFIZ [armBFAuxInt(lc, 16-lc)] x)
1645 (MOVBreg (SLLconst [lc] x)) && lc < 8 => (SBFIZ [armBFAuxInt(lc, 8-lc)] x)
1646 // int64(x) << lc
1647 (SLLconst [lc] (MOVWreg x)) => (SBFIZ [armBFAuxInt(lc, min(32, 64-lc))] x)
1648 (SLLconst [lc] (MOVHreg x)) => (SBFIZ [armBFAuxInt(lc, min(16, 64-lc))] x)
1649 (SLLconst [lc] (MOVBreg x)) => (SBFIZ [armBFAuxInt(lc, min(8, 64-lc))] x)
1650
1651 // sbfx
1652 // (x << lc) >> rc
1653 (SRAconst [rc] (SLLconst [lc] x)) && lc <= rc => (SBFX [armBFAuxInt(rc-lc, 64-rc)] x)
1654 // int64(x) >> rc
1655 (SRAconst [rc] (MOVWreg x)) && rc < 32 => (SBFX [armBFAuxInt(rc, 32-rc)] x)
1656 (SRAconst [rc] (MOVHreg x)) && rc < 16 => (SBFX [armBFAuxInt(rc, 16-rc)] x)
1657 (SRAconst [rc] (MOVBreg x)) && rc < 8 => (SBFX [armBFAuxInt(rc, 8-rc)] x)
1658 // merge sbfx and sign-extension into sbfx
1659 (MOVWreg (SBFX [bfc] x)) && bfc.width() <= 32 => (SBFX [bfc] x)
1660 (MOVHreg (SBFX [bfc] x)) && bfc.width() <= 16 => (SBFX [bfc] x)
1661 (MOVBreg (SBFX [bfc] x)) && bfc.width() <= 8 => (SBFX [bfc] x)
1662
1663 // sbfiz/sbfx combinations: merge shifts into bitfield ops
1664 (SRAconst [sc] (SBFIZ [bfc] x)) && sc < bfc.lsb()
1665 => (SBFIZ [armBFAuxInt(bfc.lsb()-sc, bfc.width())] x)
1666 (SRAconst [sc] (SBFIZ [bfc] x)) && sc >= bfc.lsb()
1667 && sc < bfc.lsb()+bfc.width()
1668 => (SBFX [armBFAuxInt(sc-bfc.lsb(), bfc.lsb()+bfc.width()-sc)] x)
1669 (SBFX [bfc] s:(SLLconst [sc] x))
1670 && s.Uses == 1
1671 && sc <= bfc.lsb()
1672 => (SBFX [armBFAuxInt(bfc.lsb() - sc, bfc.width())] x)
1673 (SBFX [bfc] s:(SLLconst [sc] x))
1674 && s.Uses == 1
1675 && sc > bfc.lsb()
1676 && sc < bfc.lsb()+bfc.width()
1677 => (SBFIZ [armBFAuxInt(sc - bfc.lsb(), bfc.width() - (sc-bfc.lsb()))] x)
1678
1679 // ubfiz
1680 // (x << lc) >> rc
1681 (SRLconst [rc] (SLLconst [lc] x)) && lc > rc => (UBFIZ [armBFAuxInt(lc-rc, 64-lc)] x)
1682 // uint64(x) << lc
1683 (SLLconst [lc] (MOVWUreg x)) => (UBFIZ [armBFAuxInt(lc, min(32, 64-lc))] x)
1684 (SLLconst [lc] (MOVHUreg x)) => (UBFIZ [armBFAuxInt(lc, min(16, 64-lc))] x)
1685 (SLLconst [lc] (MOVBUreg x)) => (UBFIZ [armBFAuxInt(lc, min(8, 64-lc))] x)
1686 // uint64(x << lc)
1687 (MOVWUreg (SLLconst [lc] x)) && lc < 32 => (UBFIZ [armBFAuxInt(lc, 32-lc)] x)
1688 (MOVHUreg (SLLconst [lc] x)) && lc < 16 => (UBFIZ [armBFAuxInt(lc, 16-lc)] x)
1689 (MOVBUreg (SLLconst [lc] x)) && lc < 8 => (UBFIZ [armBFAuxInt(lc, 8-lc)] x)
1690
1691 // merge ANDconst into ubfiz
1692 // (x & ac) << sc
1693 (SLLconst [sc] (ANDconst [ac] x)) && isARM64BFMask(sc, ac, 0)
1694 => (UBFIZ [armBFAuxInt(sc, arm64BFWidth(ac, 0))] x)
1695 // (x << sc) & ac
1696 (ANDconst [ac] (SLLconst [sc] x)) && isARM64BFMask(sc, ac, sc)
1697 => (UBFIZ [armBFAuxInt(sc, arm64BFWidth(ac, sc))] x)
1698
1699 // ubfx
1700 // (x << lc) >> rc
1701 (SRLconst [rc] (SLLconst [lc] x)) && lc < rc => (UBFX [armBFAuxInt(rc-lc, 64-rc)] x)
1702 // uint64(x) >> rc
1703 (SRLconst [rc] (MOVWUreg x)) && rc < 32 => (UBFX [armBFAuxInt(rc, 32-rc)] x)
1704 (SRLconst [rc] (MOVHUreg x)) && rc < 16 => (UBFX [armBFAuxInt(rc, 16-rc)] x)
1705 (SRLconst [rc] (MOVBUreg x)) && rc < 8 => (UBFX [armBFAuxInt(rc, 8-rc)] x)
1706 // uint64(x >> rc)
1707 (MOVWUreg (SRLconst [rc] x)) && rc < 32 => (UBFX [armBFAuxInt(rc, 32)] x)
1708 (MOVHUreg (SRLconst [rc] x)) && rc < 16 => (UBFX [armBFAuxInt(rc, 16)] x)
1709 (MOVBUreg (SRLconst [rc] x)) && rc < 8 => (UBFX [armBFAuxInt(rc, 8)] x)
1710 // merge ANDconst into ubfx
1711 // (x >> sc) & ac
1712 (ANDconst [ac] (SRLconst [sc] x)) && isARM64BFMask(sc, ac, 0)
1713 => (UBFX [armBFAuxInt(sc, arm64BFWidth(ac, 0))] x)
1714 // (x & ac) >> sc
1715 (SRLconst [sc] (ANDconst [ac] x)) && isARM64BFMask(sc, ac, sc)
1716 => (UBFX [armBFAuxInt(sc, arm64BFWidth(ac, sc))] x)
1717 // merge ANDconst and ubfx into ubfx
1718 (ANDconst [c] (UBFX [bfc] x)) && isARM64BFMask(0, c, 0) =>
1719 (UBFX [armBFAuxInt(bfc.lsb(), min(bfc.width(), arm64BFWidth(c, 0)))] x)
1720 (UBFX [bfc] (ANDconst [c] x)) && isARM64BFMask(0, c, 0) && bfc.lsb() + bfc.width() <= arm64BFWidth(c, 0) =>
1721 (UBFX [bfc] x)
1722 // merge ubfx and zero-extension into ubfx
1723 (MOVWUreg (UBFX [bfc] x)) && bfc.width() <= 32 => (UBFX [bfc] x)
1724 (MOVHUreg (UBFX [bfc] x)) && bfc.width() <= 16 => (UBFX [bfc] x)
1725 (MOVBUreg (UBFX [bfc] x)) && bfc.width() <= 8 => (UBFX [bfc] x)
1726
1727 // Extracting bits from across a zero-extension boundary.
1728 (UBFX [bfc] e:(MOVWUreg x))
1729 && e.Uses == 1
1730 && bfc.lsb() < 32
1731 => (UBFX [armBFAuxInt(bfc.lsb(), min(bfc.width(), 32-bfc.lsb()))] x)
1732 (UBFX [bfc] e:(MOVHUreg x))
1733 && e.Uses == 1
1734 && bfc.lsb() < 16
1735 => (UBFX [armBFAuxInt(bfc.lsb(), min(bfc.width(), 16-bfc.lsb()))] x)
1736 (UBFX [bfc] e:(MOVBUreg x))
1737 && e.Uses == 1
1738 && bfc.lsb() < 8
1739 => (UBFX [armBFAuxInt(bfc.lsb(), min(bfc.width(), 8-bfc.lsb()))] x)
1740
1741 // ubfiz/ubfx combinations: merge shifts into bitfield ops
1742 (SRLconst [sc] (UBFX [bfc] x)) && sc < bfc.width()
1743 => (UBFX [armBFAuxInt(bfc.lsb()+sc, bfc.width()-sc)] x)
1744 (UBFX [bfc] (SRLconst [sc] x)) && sc+bfc.width()+bfc.lsb() < 64
1745 => (UBFX [armBFAuxInt(bfc.lsb()+sc, bfc.width())] x)
1746 (SLLconst [sc] (UBFIZ [bfc] x)) && sc+bfc.width()+bfc.lsb() < 64
1747 => (UBFIZ [armBFAuxInt(bfc.lsb()+sc, bfc.width())] x)
1748 (UBFIZ [bfc] (SLLconst [sc] x)) && sc < bfc.width()
1749 => (UBFIZ [armBFAuxInt(bfc.lsb()+sc, bfc.width()-sc)] x)
1750 // ((x << c1) >> c2) >> c3
1751 (SRLconst [sc] (UBFIZ [bfc] x)) && sc == bfc.lsb()
1752 => (ANDconst [1<<uint(bfc.width())-1] x)
1753 (SRLconst [sc] (UBFIZ [bfc] x)) && sc < bfc.lsb()
1754 => (UBFIZ [armBFAuxInt(bfc.lsb()-sc, bfc.width())] x)
1755 (SRLconst [sc] (UBFIZ [bfc] x)) && sc > bfc.lsb()
1756 && sc < bfc.lsb()+bfc.width()
1757 => (UBFX [armBFAuxInt(sc-bfc.lsb(), bfc.lsb()+bfc.width()-sc)] x)
1758 // ((x << c1) << c2) >> c3
1759 (UBFX [bfc] (SLLconst [sc] x)) && sc == bfc.lsb()
1760 => (ANDconst [1<<uint(bfc.width())-1] x)
1761 (UBFX [bfc] (SLLconst [sc] x)) && sc < bfc.lsb()
1762 => (UBFX [armBFAuxInt(bfc.lsb()-sc, bfc.width())] x)
1763 (UBFX [bfc] (SLLconst [sc] x)) && sc > bfc.lsb()
1764 && sc < bfc.lsb()+bfc.width()
1765 => (UBFIZ [armBFAuxInt(sc-bfc.lsb(), bfc.lsb()+bfc.width()-sc)] x)
1766
1767 // bfi
1768 (OR (UBFIZ [bfc] x) (ANDconst [ac] y))
1769 && ac == ^((1<<uint(bfc.width())-1) << uint(bfc.lsb()))
1770 => (BFI [bfc] y x)
1771 (ORshiftLL [s] (ANDconst [xc] x) (ANDconst [yc] y))
1772 && xc == ^(yc << s) // opposite masks
1773 && yc & (yc+1) == 0 // power of 2 minus 1
1774 && yc > 0 // not 0, not all 64 bits (there are better rewrites in that case)
1775 && s+log64(yc+1) <= 64 // shifted mask doesn't overflow
1776 => (BFI [armBFAuxInt(s, log64(yc+1))] x y)
1777 (ORshiftRL [rc] (ANDconst [ac] x) (SLLconst [lc] y))
1778 && lc > rc && ac == ^((1<<uint(64-lc)-1) << uint64(lc-rc))
1779 => (BFI [armBFAuxInt(lc-rc, 64-lc)] x y)
1780 // bfxil
1781 (OR (UBFX [bfc] x) (ANDconst [ac] y)) && ac == ^(1<<uint(bfc.width())-1)
1782 => (BFXIL [bfc] y x)
1783 (ORshiftLL [sc] (UBFX [bfc] x) (SRLconst [sc] y)) && sc == bfc.width()
1784 => (BFXIL [bfc] y x)
1785 (ORshiftRL [rc] (ANDconst [ac] y) (SLLconst [lc] x)) && lc < rc && ac == ^((1<<uint(64-rc)-1))
1786 => (BFXIL [armBFAuxInt(rc-lc, 64-rc)] y x)
1787
1788 // FP simplification
1789 (FNEGS (FMULS x y)) => (FNMULS x y)
1790 (FNEGD (FMULD x y)) => (FNMULD x y)
1791 (FMULS (FNEGS x) y) => (FNMULS x y)
1792 (FMULD (FNEGD x) y) => (FNMULD x y)
1793 (FNEGS (FNMULS x y)) => (FMULS x y)
1794 (FNEGD (FNMULD x y)) => (FMULD x y)
1795 (FNMULS (FNEGS x) y) => (FMULS x y)
1796 (FNMULD (FNEGD x) y) => (FMULD x y)
1797
1798 (FADDS a (FMULS x y)) && a.Block.Func.useFMA(v) => (FMADDS a x y)
1799 (FADDD a (FMULD x y)) && a.Block.Func.useFMA(v) => (FMADDD a x y)
1800 (FSUBS a (FMULS x y)) && a.Block.Func.useFMA(v) => (FMSUBS a x y)
1801 (FSUBD a (FMULD x y)) && a.Block.Func.useFMA(v) => (FMSUBD a x y)
1802 (FSUBS (FMULS x y) a) && a.Block.Func.useFMA(v) => (FNMSUBS a x y)
1803 (FSUBD (FMULD x y) a) && a.Block.Func.useFMA(v) => (FNMSUBD a x y)
1804 (FADDS a (FNMULS x y)) && a.Block.Func.useFMA(v) => (FMSUBS a x y)
1805 (FADDD a (FNMULD x y)) && a.Block.Func.useFMA(v) => (FMSUBD a x y)
1806 (FSUBS a (FNMULS x y)) && a.Block.Func.useFMA(v) => (FMADDS a x y)
1807 (FSUBD a (FNMULD x y)) && a.Block.Func.useFMA(v) => (FMADDD a x y)
1808 (FSUBS (FNMULS x y) a) && a.Block.Func.useFMA(v) => (FNMADDS a x y)
1809 (FSUBD (FNMULD x y) a) && a.Block.Func.useFMA(v) => (FNMADDD a x y)
1810
1811 (MOVBUload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(read8(sym, int64(off)))])
1812 (MOVHUload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(read16(sym, int64(off), config.ctxt.Arch.ByteOrder))])
1813 (MOVWUload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(read32(sym, int64(off), config.ctxt.Arch.ByteOrder))])
1814 (MOVDload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(read64(sym, int64(off), config.ctxt.Arch.ByteOrder))])
1815 (MOVBload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(int8(read8(sym, int64(off))))])
1816 (MOVHload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(int16(read16(sym, int64(off), config.ctxt.Arch.ByteOrder)))])
1817 (MOVWload [off] {sym} (SB) _) && symIsRO(sym) => (MOVDconst [int64(int32(read32(sym, int64(off), config.ctxt.Arch.ByteOrder)))])
1818
1819 // Prefetch instructions (aux is option: 0 - PLDL1KEEP; 1 - PLDL1STRM)
1820 (PrefetchCache addr mem) => (PRFM [0] addr mem)
1821 (PrefetchCacheStreamed addr mem) => (PRFM [1] addr mem)
1822
1823 // Arch-specific inlining for small or disjoint runtime.memmove
1824 (SelectN [0] call:(CALLstatic {sym} s1:(MOVDstore _ (MOVDconst [sz]) s2:(MOVDstore _ src s3:(MOVDstore {t} _ dst mem)))))
1825 && sz >= 0
1826 && isSameCall(sym, "runtime.memmove")
1827 && s1.Uses == 1 && s2.Uses == 1 && s3.Uses == 1
1828 && isInlinableMemmove(dst, src, sz, config)
1829 && clobber(s1, s2, s3, call)
1830 => (Move [sz] dst src mem)
1831
1832 // Match post-lowering calls, register version.
1833 (SelectN [0] call:(CALLstatic {sym} dst src (MOVDconst [sz]) mem))
1834 && sz >= 0
1835 && isSameCall(sym, "runtime.memmove")
1836 && call.Uses == 1
1837 && isInlinableMemmove(dst, src, sz, config)
1838 && clobber(call)
1839 => (Move [sz] dst src mem)
1840
1841 ((REV|REVW) ((REV|REVW) p)) => p
1842
1843 // internal/runtime/math.MulUintptr intrinsics
1844
1845 (Select0 (Mul64uover x y)) => (MUL x y)
1846 (Select1 (Mul64uover x y)) => (NotEqual (CMPconst (UMULH <typ.UInt64> x y) [0]))
1847
1848 // 32 mul 32 -> 64
1849 (MUL r:(MOVWUreg x) s:(MOVWUreg y)) && r.Uses == 1 && s.Uses == 1 => (UMULL x y)
1850 (MUL r:(MOVWreg x) s:(MOVWreg y)) && r.Uses == 1 && s.Uses == 1 => (MULL x y)
1851
1852 // ANDconst to zext
1853 (ANDconst [0xffffffff] x) => (MOVWUreg x)
1854 (ANDconst [0xffff ] x) => (MOVHUreg x)
1855 (ANDconst [0xff ] x) => (MOVBUreg x)
1856
1857 // SIMD zero
1858 (ZeroSIMD <t>) && t.Size() == 16 => (VMOVI16B [0] <t>)
1859
View as plain text