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 (FMA32 x y z) => (FMADDS z x y)
62
63 (Sqrt32 ...) => (FSQRTS ...)
64
65 (Min(64|32)F ...) => (FMIN(D|S) ...)
66 (Max(64|32)F ...) => (FMAX(D|S) ...)
67
68 // lowering rotates
69 // we do rotate detection in generic rules, if the following rules need to be changed, check generic rules first.
70 (RotateLeft8 <t> x (MOVDconst [c])) => (Or8 (Lsh8x64 <t> x (MOVDconst [c&7])) (Rsh8Ux64 <t> x (MOVDconst [-c&7])))
71 (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))))
72 (RotateLeft16 <t> x (MOVDconst [c])) => (Or16 (Lsh16x64 <t> x (MOVDconst [c&15])) (Rsh16Ux64 <t> x (MOVDconst [-c&15])))
73 (RotateLeft16 <t> x y) => (RORW <t> (ORshiftLL <typ.UInt32> (ZeroExt16to32 x) (ZeroExt16to32 x) [16]) (NEG <typ.Int64> y))
74 (RotateLeft32 x y) => (RORW x (NEG <y.Type> y))
75 (RotateLeft64 x y) => (ROR x (NEG <y.Type> y))
76
77 (Ctz(64|32|16|8)NonZero ...) => (Ctz(64|32|32|32) ...)
78
79 (Ctz64 <t> x) => (CLZ (RBIT <t> x))
80 (Ctz32 <t> x) => (CLZW (RBITW <t> x))
81 (Ctz16 <t> x) => (CLZW <t> (RBITW <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x)))
82 (Ctz8 <t> x) => (CLZW <t> (RBITW <typ.UInt32> (ORconst <typ.UInt32> [0x100] x)))
83
84 (PopCount64 <t> x) => (FMOVDfpgp <t> (VUADDLV <typ.Float64> (VCNT <typ.Float64> (FMOVDgpfp <typ.Float64> x))))
85 (PopCount32 <t> x) => (FMOVDfpgp <t> (VUADDLV <typ.Float64> (VCNT <typ.Float64> (FMOVDgpfp <typ.Float64> (ZeroExt32to64 x)))))
86 (PopCount16 <t> x) => (FMOVDfpgp <t> (VUADDLV <typ.Float64> (VCNT <typ.Float64> (FMOVDgpfp <typ.Float64> (ZeroExt16to64 x)))))
87
88 // Load args directly into the register class where it will be used.
89 (FMOVDgpfp <t> (Arg [off] {sym})) => @b.Func.Entry (Arg <t> [off] {sym})
90 (FMOVDfpgp <t> (Arg [off] {sym})) => @b.Func.Entry (Arg <t> [off] {sym})
91
92 // Similarly for stores, if we see a store after FPR <=> GPR move, then redirect store to use the other register set.
93 (MOVDstore [off] {sym} ptr (FMOVDfpgp val) mem) => (FMOVDstore [off] {sym} ptr val mem)
94 (FMOVDstore [off] {sym} ptr (FMOVDgpfp val) mem) => (MOVDstore [off] {sym} ptr val mem)
95 (MOVWstore [off] {sym} ptr (FMOVSfpgp val) mem) => (FMOVSstore [off] {sym} ptr val mem)
96 (FMOVSstore [off] {sym} ptr (FMOVSgpfp val) mem) => (MOVWstore [off] {sym} ptr val mem)
97
98 // float <=> int register moves, with no conversion.
99 // These come up when compiling math.{Float64bits, Float64frombits, Float32bits, Float32frombits}.
100 (MOVDload [off] {sym} ptr (FMOVDstore [off] {sym} ptr val _)) => (FMOVDfpgp val)
101 (FMOVDload [off] {sym} ptr (MOVDstore [off] {sym} ptr val _)) => (FMOVDgpfp val)
102 (MOVWUload [off] {sym} ptr (FMOVSstore [off] {sym} ptr val _)) => (FMOVSfpgp val)
103 (FMOVSload [off] {sym} ptr (MOVWstore [off] {sym} ptr val _)) => (FMOVSgpfp val)
104
105 (BitLen64 x) => (SUB (MOVDconst [64]) (CLZ <typ.Int> x))
106 (BitLen32 x) => (SUB (MOVDconst [32]) (CLZW <typ.Int> x))
107 (BitLen(16|8) x) => (BitLen64 (ZeroExt(16|8)to64 x))
108
109 (Bswap64 ...) => (REV ...)
110 (Bswap32 ...) => (REVW ...)
111 (Bswap16 ...) => (REV16W ...)
112
113 (BitRev64 ...) => (RBIT ...)
114 (BitRev32 ...) => (RBITW ...)
115 (BitRev16 x) => (SRLconst [48] (RBIT <typ.UInt64> x))
116 (BitRev8 x) => (SRLconst [56] (RBIT <typ.UInt64> x))
117
118 // In fact, UMOD will be translated into UREM instruction, and UREM is originally translated into
119 // UDIV and MSUB instructions. But if there is already an identical UDIV instruction just before or
120 // after UREM (case like quo, rem := z/y, z%y), then the second UDIV instruction becomes redundant.
121 // The purpose of this rule is to have this extra UDIV instruction removed in CSE pass.
122 (UMOD <typ.UInt64> x y) => (MSUB <typ.UInt64> x y (UDIV <typ.UInt64> x y))
123 (UMODW <typ.UInt32> x y) => (MSUBW <typ.UInt32> x y (UDIVW <typ.UInt32> x y))
124
125 // 64-bit addition with carry.
126 (Select0 (Add64carry x y c)) => (Select0 <typ.UInt64> (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] c))))
127 (Select1 (Add64carry x y c)) => (ADCzerocarry <typ.UInt64> (Select1 <types.TypeFlags> (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] c)))))
128
129 // 64-bit subtraction with borrowing.
130 (Select0 (Sub64borrow x y bo)) => (Select0 <typ.UInt64> (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags bo))))
131 (Select1 (Sub64borrow x y bo)) => (NEG <typ.UInt64> (NGCzerocarry <typ.UInt64> (Select1 <types.TypeFlags> (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags bo))))))
132
133 // boolean ops -- booleans are represented with 0=false, 1=true
134 (AndB ...) => (AND ...)
135 (OrB ...) => (OR ...)
136 (EqB x y) => (XOR (MOVDconst [1]) (XOR <typ.Bool> x y))
137 (NeqB ...) => (XOR ...)
138 (Not x) => (XOR (MOVDconst [1]) x)
139
140 // shifts
141 // hardware instruction uses only the low 6 bits of the shift
142 // we compare to 64 to ensure Go semantics for large shifts
143 // Rules about rotates with non-const shift are based on the following rules,
144 // if the following rules change, please also modify the rules based on them.
145
146 // check shiftIsBounded first, if shift value is proved to be valid then we
147 // can do the shift directly.
148 // left shift
149 (Lsh32x(64|32|16|8) ...) => (Lsh64x(64|32|16|8) ...)
150 (Lsh16x(64|32|16|8) ...) => (Lsh64x(64|32|16|8) ...)
151 (Lsh8x(64|32|16|8) ...) => (Lsh64x(64|32|16|8) ...)
152
153 (Lsh64x(64|32|16|8) <t> x y) && ssa.ShiftIsBounded(v) => (SLL <t> x y)
154
155 // signed right shift
156 (Rsh32x(64|32|16|8) <t> [bounded] x y) => (Rsh64x(64|32|16|8) <t> [bounded] (SignExt32to64 x) y)
157 (Rsh16x(64|32|16|8) <t> [bounded] x y) => (Rsh64x(64|32|16|8) <t> [bounded] (SignExt16to64 x) y)
158 (Rsh8x(64|32|16|8) <t> [bounded] x y) => (Rsh64x(64|32|16|8) <t> [bounded] (SignExt8to64 x) y)
159
160 (Rsh64x(64|32|16|8) <t> x y) && ssa.ShiftIsBounded(v) => (SRA <t> x y)
161
162 // unsigned right shift
163 (Rsh32Ux(64|32|16|8) <t> [bounded] x y) => (Rsh64Ux(64|32|16|8) <t> [bounded] (ZeroExt32to64 x) y)
164 (Rsh16Ux(64|32|16|8) <t> [bounded] x y) => (Rsh64Ux(64|32|16|8) <t> [bounded] (ZeroExt16to64 x) y)
165 (Rsh8Ux(64|32|16|8) <t> [bounded] x y) => (Rsh64Ux(64|32|16|8) <t> [bounded] (ZeroExt8to64 x) y)
166
167 (Rsh64Ux(64|32|16|8) <t> x y) && ssa.ShiftIsBounded(v) => (SRL <t> x y)
168
169 // shift value may be out of range, use CMP + CSEL instead
170 (Lsh64x64 <t> x y) && !ssa.ShiftIsBounded(v) => (CSEL [ssaop.OpARM64LessThanU] (SLL <t> x y) (Const64 <t> [0]) (CMPconst [64] y))
171 (Lsh64x32 <t> x y) && !ssa.ShiftIsBounded(v) => (CSEL [ssaop.OpARM64LessThanU] (SLL <t> x y) (Const64 <t> [0]) (CMPWconst [64] y))
172 (Lsh64x(16|8) <t> [bounded] x y) && !ssa.ShiftIsBounded(v) => (Lsh64x32 <t> [bounded] x (ZeroExt(16|8)to32 y))
173
174 (Rsh64Ux64 <t> x y) && !ssa.ShiftIsBounded(v) => (CSEL [ssaop.OpARM64LessThanU] (SRL <t> x y) (Const64 <t> [0]) (CMPconst [64] y))
175 (Rsh64Ux32 <t> x y) && !ssa.ShiftIsBounded(v) => (CSEL [ssaop.OpARM64LessThanU] (SRL <t> x y) (Const64 <t> [0]) (CMPWconst [64] y))
176 (Rsh64Ux(16|8) <t> [bounded] x y) && !ssa.ShiftIsBounded(v) => (Rsh64Ux32 <t> [bounded] x (ZeroExt(16|8)to32 y))
177
178 (Rsh64x64 <t> x y) && !ssa.ShiftIsBounded(v) => (SRA x (CSEL [ssaop.OpARM64LessThanU] <y.Type> y (Const64 <y.Type> [63]) (CMPconst [64] y)))
179 (Rsh64x32 <t> x y) && !ssa.ShiftIsBounded(v) => (SRA x (CSEL [ssaop.OpARM64LessThanU] <y.Type> y (Const64 <y.Type> [63]) (CMPWconst [64] y)))
180 (Rsh64x(16|8) <t> [bounded] x y) && !ssa.ShiftIsBounded(v) => (Rsh64x32 <t> [bounded] x (ZeroExt(16|8)to32 y))
181
182 // constants
183 (Const(64|32|16|8) [val]) => (MOVDconst [int64(val)])
184 (Const(32|64)F [val]) => (FMOV(S|D)const [float64(val)])
185 (ConstNil) => (MOVDconst [0])
186 (ConstBool [t]) => (MOVDconst [ssa.B2i(t)])
187
188 (Slicemask <t> x) => (SRAconst (NEG <t> x) [63])
189
190 // truncations
191 // Because we ignore high parts of registers, truncates are just copies.
192 (Trunc16to8 ...) => (Copy ...)
193 (Trunc32to8 ...) => (Copy ...)
194 (Trunc32to16 ...) => (Copy ...)
195 (Trunc64to8 ...) => (Copy ...)
196 (Trunc64to16 ...) => (Copy ...)
197 (Trunc64to32 ...) => (Copy ...)
198
199 // Zero-/Sign-extensions
200 (ZeroExt8to16 ...) => (MOVBUreg ...)
201 (ZeroExt8to32 ...) => (MOVBUreg ...)
202 (ZeroExt16to32 ...) => (MOVHUreg ...)
203 (ZeroExt8to64 ...) => (MOVBUreg ...)
204 (ZeroExt16to64 ...) => (MOVHUreg ...)
205 (ZeroExt32to64 ...) => (MOVWUreg ...)
206
207 (SignExt8to16 ...) => (MOVBreg ...)
208 (SignExt8to32 ...) => (MOVBreg ...)
209 (SignExt16to32 ...) => (MOVHreg ...)
210 (SignExt8to64 ...) => (MOVBreg ...)
211 (SignExt16to64 ...) => (MOVHreg ...)
212 (SignExt32to64 ...) => (MOVWreg ...)
213
214 // float <=> int conversion
215 (Cvt32to32F ...) => (SCVTFWS ...)
216 (Cvt32to64F ...) => (SCVTFWD ...)
217 (Cvt64to32F ...) => (SCVTFS ...)
218 (Cvt64to64F ...) => (SCVTFD ...)
219 (Cvt32Uto32F ...) => (UCVTFWS ...)
220 (Cvt32Uto64F ...) => (UCVTFWD ...)
221 (Cvt64Uto32F ...) => (UCVTFS ...)
222 (Cvt64Uto64F ...) => (UCVTFD ...)
223 (Cvt32Fto32 ...) => (FCVTZSSW ...)
224 (Cvt64Fto32 ...) => (FCVTZSDW ...)
225 (Cvt32Fto64 ...) => (FCVTZSS ...)
226 (Cvt64Fto64 ...) => (FCVTZSD ...)
227 (Cvt32Fto32U ...) => (FCVTZUSW ...)
228 (Cvt64Fto32U ...) => (FCVTZUDW ...)
229 (Cvt32Fto64U ...) => (FCVTZUS ...)
230 (Cvt64Fto64U ...) => (FCVTZUD ...)
231 (Cvt32Fto64F ...) => (FCVTSD ...)
232 (Cvt64Fto32F ...) => (FCVTDS ...)
233
234 (CvtBoolToUint8 ...) => (Copy ...)
235
236 (Round32F ...) => (LoweredRound32F ...)
237 (Round64F ...) => (LoweredRound64F ...)
238
239 // comparisons
240 (Eq8 x y) => (Equal (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
241 (Eq16 x y) => (Equal (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
242 (Eq32 x y) => (Equal (CMPW x y))
243 (Eq64 x y) => (Equal (CMP x y))
244 (EqPtr x y) => (Equal (CMP x y))
245 (Eq32F x y) => (Equal (FCMPS x y))
246 (Eq64F x y) => (Equal (FCMPD x y))
247
248 (Neq8 x y) => (NotEqual (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
249 (Neq16 x y) => (NotEqual (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
250 (Neq32 x y) => (NotEqual (CMPW x y))
251 (Neq64 x y) => (NotEqual (CMP x y))
252 (NeqPtr x y) => (NotEqual (CMP x y))
253 (Neq(32|64)F x y) => (NotEqual (FCMP(S|D) x y))
254
255 (Less(8|16) x y) => (LessThan (CMPW (SignExt(8|16)to32 x) (SignExt(8|16)to32 y)))
256 (Less32 x y) => (LessThan (CMPW x y))
257 (Less64 x y) => (LessThan (CMP x y))
258
259 // Set condition flags for floating-point comparisons "x < y"
260 // and "x <= y". Because if either or both of the operands are
261 // NaNs, all three of (x < y), (x == y) and (x > y) are false,
262 // and ARM Manual says FCMP instruction sets PSTATE.<N,Z,C,V>
263 // of this case to (0, 0, 1, 1).
264 (Less32F x y) => (LessThanF (FCMPS x y))
265 (Less64F x y) => (LessThanF (FCMPD x y))
266
267 // For an unsigned integer x, the following rules are useful when combining branch
268 // 0 < x => x != 0
269 // x <= 0 => x == 0
270 // x < 1 => x == 0
271 // 1 <= x => x != 0
272 (Less(8U|16U|32U|64U) zero:(MOVDconst [0]) x) => (Neq(8|16|32|64) zero x)
273 (Leq(8U|16U|32U|64U) x zero:(MOVDconst [0])) => (Eq(8|16|32|64) x zero)
274 (Less(8U|16U|32U|64U) x (MOVDconst [1])) => (Eq(8|16|32|64) x (MOVDconst [0]))
275 (Leq(8U|16U|32U|64U) (MOVDconst [1]) x) => (Neq(8|16|32|64) (MOVDconst [0]) x)
276
277 (Less8U x y) => (LessThanU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
278 (Less16U x y) => (LessThanU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
279 (Less32U x y) => (LessThanU (CMPW x y))
280 (Less64U x y) => (LessThanU (CMP x y))
281
282 (Leq8 x y) => (LessEqual (CMPW (SignExt8to32 x) (SignExt8to32 y)))
283 (Leq16 x y) => (LessEqual (CMPW (SignExt16to32 x) (SignExt16to32 y)))
284 (Leq32 x y) => (LessEqual (CMPW x y))
285 (Leq64 x y) => (LessEqual (CMP x y))
286
287 // Refer to the comments for op Less64F above.
288 (Leq32F x y) => (LessEqualF (FCMPS x y))
289 (Leq64F x y) => (LessEqualF (FCMPD x y))
290
291 (Leq8U x y) => (LessEqualU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
292 (Leq16U x y) => (LessEqualU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
293 (Leq32U x y) => (LessEqualU (CMPW x y))
294 (Leq64U x y) => (LessEqualU (CMP x y))
295
296 // Optimize comparison between a floating-point value and 0.0 with "FCMP $(0.0), Fn"
297 (FCMPS x (FMOVSconst [0])) => (FCMPS0 x)
298 (FCMPS (FMOVSconst [0]) x) => (InvertFlags (FCMPS0 x))
299 (FCMPD x (FMOVDconst [0])) => (FCMPD0 x)
300 (FCMPD (FMOVDconst [0]) x) => (InvertFlags (FCMPD0 x))
301
302 // Float min/max comparison-select idioms lower to a compare plus FCSEL on the
303 // FP registers. The ops carry their semantics directly, so lowering always
304 // triggers.
305 (Min64FSel x y) => (FCSELD [ssaop.OpARM64LessThanF] x y (FCMPD x y))
306 (Min32FSel x y) => (FCSELS [ssaop.OpARM64LessThanF] x y (FCMPS x y))
307 (Max64FSel x y) => (FCSELD [ssaop.OpARM64GreaterThanF] x y (FCMPD x y))
308 (Max32FSel x y) => (FCSELS [ssaop.OpARM64GreaterThanF] x y (FCMPS x y))
309
310 // CSEL needs a flag-generating argument. Synthesize a TSTW if necessary.
311 (CondSelect x y boolval) && arm64CondFlagArg(boolval) != nil => (CSEL [boolval.Op] x y arm64CondFlagArg(boolval))
312 (CondSelect x y boolval) && arm64CondFlagArg(boolval) == nil => (CSEL [ssaop.OpARM64NotEqual] x y (TSTWconst [1] boolval))
313
314 (OffPtr [off] ptr:(SP)) && ssa.Is32Bit(off) => (MOVDaddr [int32(off)] ptr)
315 (OffPtr [off] ptr) => (ADDconst [off] ptr)
316
317 (Addr {sym} base) => (MOVDaddr {sym} base)
318 (LocalAddr <t> {sym} base mem) && t.Elem().HasPointers() => (MOVDaddr {sym} (SPanchored base mem))
319 (LocalAddr <t> {sym} base _) && !t.Elem().HasPointers() => (MOVDaddr {sym} base)
320
321 // loads
322 (Load <t> ptr mem) && t.IsBoolean() => (MOVBUload ptr mem)
323 (Load <t> ptr mem) && (ssa.Is8BitInt(t) && t.IsSigned()) => (MOVBload ptr mem)
324 (Load <t> ptr mem) && (ssa.Is8BitInt(t) && !t.IsSigned()) => (MOVBUload ptr mem)
325 (Load <t> ptr mem) && (ssa.Is16BitInt(t) && t.IsSigned()) => (MOVHload ptr mem)
326 (Load <t> ptr mem) && (ssa.Is16BitInt(t) && !t.IsSigned()) => (MOVHUload ptr mem)
327 (Load <t> ptr mem) && (ssa.Is32BitInt(t) && t.IsSigned()) => (MOVWload ptr mem)
328 (Load <t> ptr mem) && (ssa.Is32BitInt(t) && !t.IsSigned()) => (MOVWUload ptr mem)
329 (Load <t> ptr mem) && (ssa.Is64BitInt(t) ||ssa.IsPtr(t)) => (MOVDload ptr mem)
330 (Load <t> ptr mem) && ssa.Is32BitFloat(t) => (FMOVSload ptr mem)
331 (Load <t> ptr mem) && ssa.Is64BitFloat(t) => (FMOVDload ptr mem)
332 (Load <t> ptr mem) && t.Size() == 16 => (FMOVQload ptr mem)
333
334 // stores
335 (Store {t} ptr val mem) && t.Size() == 1 => (MOVBstore ptr val mem)
336 (Store {t} ptr val mem) && t.Size() == 2 => (MOVHstore ptr val mem)
337 (Store {t} ptr val mem) && t.Size() == 4 && !t.IsFloat() => (MOVWstore ptr val mem)
338 (Store {t} ptr val mem) && t.Size() == 8 && !t.IsFloat() && !t.IsSIMD() => (MOVDstore ptr val mem)
339 (Store {t} ptr val mem) && t.Size() == 4 && t.IsFloat() => (FMOVSstore ptr val mem)
340 (Store {t} ptr val mem) && t.Size() == 8 && t.IsFloat() => (FMOVDstore ptr val mem)
341 (Store {t} ptr val mem) && t.Size() == 16 => (FMOVQstore ptr val mem)
342
343 // zeroing
344 (Zero [0] _ mem) => mem
345 (Zero [1] ptr mem) => (MOVBstore ptr (MOVDconst [0]) mem)
346 (Zero [2] ptr mem) => (MOVHstore ptr (MOVDconst [0]) mem)
347 (Zero [4] ptr mem) => (MOVWstore ptr (MOVDconst [0]) mem)
348 (Zero [3] ptr mem) =>
349 (MOVBstore [2] ptr (MOVDconst [0])
350 (MOVHstore ptr (MOVDconst [0]) mem))
351 (Zero [5] ptr mem) =>
352 (MOVBstore [4] ptr (MOVDconst [0])
353 (MOVWstore ptr (MOVDconst [0]) mem))
354 (Zero [6] ptr mem) =>
355 (MOVHstore [4] ptr (MOVDconst [0])
356 (MOVWstore ptr (MOVDconst [0]) mem))
357 (Zero [7] ptr mem) =>
358 (MOVWstore [3] ptr (MOVDconst [0])
359 (MOVWstore ptr (MOVDconst [0]) mem))
360 (Zero [8] ptr mem) => (MOVDstore ptr (MOVDconst [0]) mem)
361 (Zero [9] ptr mem) =>
362 (MOVBstore [8] ptr (MOVDconst [0])
363 (MOVDstore ptr (MOVDconst [0]) mem))
364 (Zero [10] ptr mem) =>
365 (MOVHstore [8] ptr (MOVDconst [0])
366 (MOVDstore ptr (MOVDconst [0]) mem))
367 (Zero [11] ptr mem) =>
368 (MOVDstore [3] ptr (MOVDconst [0])
369 (MOVDstore ptr (MOVDconst [0]) mem))
370 (Zero [12] ptr mem) =>
371 (MOVWstore [8] ptr (MOVDconst [0])
372 (MOVDstore ptr (MOVDconst [0]) mem))
373 (Zero [13] ptr mem) =>
374 (MOVDstore [5] ptr (MOVDconst [0])
375 (MOVDstore ptr (MOVDconst [0]) mem))
376 (Zero [14] ptr mem) =>
377 (MOVDstore [6] ptr (MOVDconst [0])
378 (MOVDstore ptr (MOVDconst [0]) mem))
379 (Zero [15] ptr mem) =>
380 (MOVDstore [7] ptr (MOVDconst [0])
381 (MOVDstore ptr (MOVDconst [0]) mem))
382 (Zero [16] ptr mem) =>
383 (STP [0] ptr (MOVDconst [0]) (MOVDconst [0]) mem)
384
385 (Zero [s] ptr mem) && s > 16 && s < 192 => (LoweredZero [s] ptr mem)
386 (Zero [s] ptr mem) && s >= 192 => (LoweredZeroLoop [s] ptr mem)
387
388 // moves
389 (Move [0] _ _ mem) => mem
390 (Move [1] dst src mem) => (MOVBstore dst (MOVBUload src mem) mem)
391 (Move [2] dst src mem) => (MOVHstore dst (MOVHUload src mem) mem)
392 (Move [3] dst src mem) =>
393 (MOVBstore [2] dst (MOVBUload [2] src mem)
394 (MOVHstore dst (MOVHUload src mem) mem))
395 (Move [4] dst src mem) => (MOVWstore dst (MOVWUload src mem) mem)
396 (Move [5] dst src mem) =>
397 (MOVBstore [4] dst (MOVBUload [4] src mem)
398 (MOVWstore dst (MOVWUload src mem) mem))
399 (Move [6] dst src mem) =>
400 (MOVHstore [4] dst (MOVHUload [4] src mem)
401 (MOVWstore dst (MOVWUload src mem) mem))
402 (Move [7] dst src mem) =>
403 (MOVWstore [3] dst (MOVWUload [3] src mem)
404 (MOVWstore dst (MOVWUload src mem) mem))
405 (Move [8] dst src mem) => (MOVDstore dst (MOVDload src mem) mem)
406 (Move [9] dst src mem) =>
407 (MOVBstore [8] dst (MOVBUload [8] src mem)
408 (MOVDstore dst (MOVDload src mem) mem))
409 (Move [10] dst src mem) =>
410 (MOVHstore [8] dst (MOVHUload [8] src mem)
411 (MOVDstore dst (MOVDload src mem) mem))
412 (Move [11] dst src mem) =>
413 (MOVDstore [3] dst (MOVDload [3] src mem)
414 (MOVDstore dst (MOVDload src mem) mem))
415 (Move [12] dst src mem) =>
416 (MOVWstore [8] dst (MOVWUload [8] src mem)
417 (MOVDstore dst (MOVDload src mem) mem))
418 (Move [13] dst src mem) =>
419 (MOVDstore [5] dst (MOVDload [5] src mem)
420 (MOVDstore dst (MOVDload src mem) mem))
421 (Move [14] dst src mem) =>
422 (MOVDstore [6] dst (MOVDload [6] src mem)
423 (MOVDstore dst (MOVDload src mem) mem))
424 (Move [15] dst src mem) =>
425 (MOVDstore [7] dst (MOVDload [7] src mem)
426 (MOVDstore dst (MOVDload src mem) mem))
427 (Move [16] dst src mem) => (FMOVQstore dst (FMOVQload src mem) mem)
428
429 (Move [s] dst src mem) && s > 16 && s <= 24 =>
430 (MOVDstore [int32(s-8)] dst (MOVDload [int32(s-8)] src mem)
431 (FMOVQstore dst (FMOVQload src mem) mem))
432 (Move [s] dst src mem) && s > 24 && s < 32 =>
433 (FMOVQstore [int32(s-16)] dst (FMOVQload [int32(s-16)] src mem)
434 (FMOVQstore dst (FMOVQload src mem) mem))
435 (Move [32] dst src mem) =>
436 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem)
437 (Move [s] dst src mem) && s > 32 && s <= 40 =>
438 (MOVDstore [int32(s-8)] dst (MOVDload [int32(s-8)] src mem)
439 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem))
440 (Move [s] dst src mem) && s > 40 && s <= 48 =>
441 (FMOVQstore [int32(s-16)] dst (FMOVQload [int32(s-16)] src mem)
442 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem))
443 (Move [s] dst src mem) && s > 48 && s <= 64 =>
444 (FSTPQ [int32(s-32)] dst (Select0 <typ.Vec128> (FLDPQ [int32(s-32)] src mem)) (Select1 <typ.Vec128> (FLDPQ [int32(s-32)] src mem))
445 (FSTPQ dst (Select0 <typ.Vec128> (FLDPQ src mem)) (Select1 <typ.Vec128> (FLDPQ src mem)) mem))
446
447 (Move [s] dst src mem) && s > 64 && s < 192 && ssa.LogLargeCopyValue(v, s) => (LoweredMove [s] dst src mem)
448 (Move [s] dst src mem) && s >= 192 && ssa.LogLargeCopyValue(v, s) => (LoweredMoveLoop [s] dst src mem)
449
450 // calls
451 (StaticCall ...) => (CALLstatic ...)
452 (ClosureCall ...) => (CALLclosure ...)
453 (InterCall ...) => (CALLinter ...)
454 (TailCall ...) => (CALLtail ...)
455 (TailCallInter ...) => (CALLtailinter ...)
456
457 // checks
458 (NilCheck ...) => (LoweredNilCheck ...)
459 (IsNonNil ptr) => (NotEqual (CMPconst [0] ptr))
460 (IsInBounds idx len) => (LessThanU (CMP idx len))
461 (IsSliceInBounds idx len) => (LessEqualU (CMP idx len))
462
463 // pseudo-ops
464 (GetClosurePtr ...) => (LoweredGetClosurePtr ...)
465 (GetCallerSP ...) => (LoweredGetCallerSP ...)
466 (GetCallerPC ...) => (LoweredGetCallerPC ...)
467 (MemEq ...) => (LoweredMemEq ...)
468
469 // Absorb pseudo-ops into blocks.
470 (If (Equal cc) yes no) => (EQ cc yes no)
471 (If (NotEqual cc) yes no) => (NE cc yes no)
472 (If (LessThan cc) yes no) => (LT cc yes no)
473 (If (LessThanU cc) yes no) => (ULT cc yes no)
474 (If (LessEqual cc) yes no) => (LE cc yes no)
475 (If (LessEqualU cc) yes no) => (ULE cc yes no)
476 (If (GreaterThan cc) yes no) => (GT cc yes no)
477 (If (GreaterThanU cc) yes no) => (UGT cc yes no)
478 (If (GreaterEqual cc) yes no) => (GE cc yes no)
479 (If (GreaterEqualU cc) yes no) => (UGE cc yes no)
480 (If (LessThanF cc) yes no) => (FLT cc yes no)
481 (If (LessEqualF cc) yes no) => (FLE cc yes no)
482 (If (GreaterThanF cc) yes no) => (FGT cc yes no)
483 (If (GreaterEqualF cc) yes no) => (FGE cc yes no)
484
485 (If cond yes no) => (TBNZ [0] cond yes no)
486
487 (JumpTable idx) => (JUMPTABLE {ssa.MakeJumpTableSym(b)} idx (MOVDaddr <typ.Uintptr> {ssa.MakeJumpTableSym(b)} (SB)))
488
489 // atomic intrinsics
490 // Note: these ops do not accept offset.
491 (AtomicLoad8 ...) => (LDARB ...)
492 (AtomicLoad32 ...) => (LDARW ...)
493 (AtomicLoad64 ...) => (LDAR ...)
494 (AtomicLoadPtr ...) => (LDAR ...)
495
496 (AtomicStore8 ...) => (STLRB ...)
497 (AtomicStore32 ...) => (STLRW ...)
498 (AtomicStore64 ...) => (STLR ...)
499 (AtomicStorePtrNoWB ...) => (STLR ...)
500
501 (AtomicExchange(8|32|64) ...) => (LoweredAtomicExchange(8|32|64) ...)
502 (AtomicAdd(32|64) ...) => (LoweredAtomicAdd(32|64) ...)
503 (AtomicCompareAndSwap(32|64) ...) => (LoweredAtomicCas(32|64) ...)
504
505 (AtomicAdd(32|64)Variant ...) => (LoweredAtomicAdd(32|64)Variant ...)
506 (AtomicExchange(8|32|64)Variant ...) => (LoweredAtomicExchange(8|32|64)Variant ...)
507 (AtomicCompareAndSwap(32|64)Variant ...) => (LoweredAtomicCas(32|64)Variant ...)
508
509 // Return old contents.
510 (AtomicAnd(64|32|8)value ...) => (LoweredAtomicAnd(64|32|8) ...)
511 (AtomicOr(64|32|8)value ...) => (LoweredAtomicOr(64|32|8) ...)
512 (AtomicAnd(64|32|8)valueVariant ...) => (LoweredAtomicAnd(64|32|8)Variant ...)
513 (AtomicOr(64|32|8)valueVariant ...) => (LoweredAtomicOr(64|32|8)Variant ...)
514
515 // Write barrier.
516 (WB ...) => (LoweredWB ...)
517
518 // Publication barrier (0xe is ST option)
519 (PubBarrier mem) => (DMB [0xe] mem)
520
521 (PanicBounds ...) => (LoweredPanicBoundsRR ...)
522 (LoweredPanicBoundsRR [kind] x (MOVDconst [c]) mem) => (LoweredPanicBoundsRC [kind] x {ssa.PanicBoundsC{C:c}} mem)
523 (LoweredPanicBoundsRR [kind] (MOVDconst [c]) y mem) => (LoweredPanicBoundsCR [kind] {ssa.PanicBoundsC{C:c}} y mem)
524 (LoweredPanicBoundsRC [kind] {p} (MOVDconst [c]) mem) => (LoweredPanicBoundsCC [kind] {ssa.PanicBoundsCC{Cx:c, Cy:p.C}} mem)
525 (LoweredPanicBoundsCR [kind] {p} (MOVDconst [c]) mem) => (LoweredPanicBoundsCC [kind] {ssa.PanicBoundsCC{Cx:p.C, Cy:c}} mem)
526
527 // Optimizations
528
529 // Replace widen -> wide_unop -> narrow with narrow_unop when one exists.
530 (FCVTDS (F(ABS|SQRT|RINTP|RINTM|RINTA|RINTN|RINTZ)D (FCVTSD x))) =>
531 (F(ABS|SQRT|RINTP|RINTM|RINTA|RINTN|RINTZ)S x)
532
533
534 // Absorb boolean tests into block
535 (NZ (Equal cc) yes no) => (EQ cc yes no)
536 (NZ (NotEqual cc) yes no) => (NE cc yes no)
537 (NZ (LessThan cc) yes no) => (LT cc yes no)
538 (NZ (LessThanU cc) yes no) => (ULT cc yes no)
539 (NZ (LessEqual cc) yes no) => (LE cc yes no)
540 (NZ (LessEqualU cc) yes no) => (ULE cc yes no)
541 (NZ (GreaterThan cc) yes no) => (GT cc yes no)
542 (NZ (GreaterThanU cc) yes no) => (UGT cc yes no)
543 (NZ (GreaterEqual cc) yes no) => (GE cc yes no)
544 (NZ (GreaterEqualU cc) yes no) => (UGE cc yes no)
545 (NZ (LessThanF cc) yes no) => (FLT cc yes no)
546 (NZ (LessEqualF cc) yes no) => (FLE cc yes no)
547 (NZ (GreaterThanF cc) yes no) => (FGT cc yes no)
548 (NZ (GreaterEqualF cc) yes no) => (FGE cc yes no)
549
550 (TBNZ [0] (Equal cc) yes no) => (EQ cc yes no)
551 (TBNZ [0] (NotEqual cc) yes no) => (NE cc yes no)
552 (TBNZ [0] (LessThan cc) yes no) => (LT cc yes no)
553 (TBNZ [0] (LessThanU cc) yes no) => (ULT cc yes no)
554 (TBNZ [0] (LessEqual cc) yes no) => (LE cc yes no)
555 (TBNZ [0] (LessEqualU cc) yes no) => (ULE cc yes no)
556 (TBNZ [0] (GreaterThan cc) yes no) => (GT cc yes no)
557 (TBNZ [0] (GreaterThanU cc) yes no) => (UGT cc yes no)
558 (TBNZ [0] (GreaterEqual cc) yes no) => (GE cc yes no)
559 (TBNZ [0] (GreaterEqualU cc) yes no) => (UGE cc yes no)
560 (TBNZ [0] (LessThanF cc) yes no) => (FLT cc yes no)
561 (TBNZ [0] (LessEqualF cc) yes no) => (FLE cc yes no)
562 (TBNZ [0] (GreaterThanF cc) yes no) => (FGT cc yes no)
563 (TBNZ [0] (GreaterEqualF cc) yes no) => (FGE cc yes no)
564
565 (TB(Z|NZ) [0] (XORconst [1] x) yes no) => (TB(NZ|Z) [0] x yes no)
566
567 ((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)
568 ((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)
569 ((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)
570 ((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)
571
572 // For conditional instructions such as CSET, CSEL.
573 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPconst [0] z:(AND x y))) && z.Uses == 1 =>
574 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TST x y))
575 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 =>
576 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TSTWconst [int32(c)] y))
577 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPWconst [0] z:(AND x y))) && z.Uses == 1 =>
578 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TSTW x y))
579 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (CMPconst [0] x:(ANDconst [c] y))) && x.Uses == 1 =>
580 ((Equal|NotEqual|LessThan|LessEqual|GreaterThan|GreaterEqual) (TSTconst [c] y))
581
582 ((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)
583 ((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)
584 ((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)
585 ((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)
586
587 // CMP(x,-y) -> CMN(x,y) is only valid for unordered comparison, if y can be -1<<63
588 ((EQ|NE) (CMP x z:(NEG y)) yes no) && z.Uses == 1 => ((EQ|NE) (CMN x y) yes no)
589 ((Equal|NotEqual) (CMP x z:(NEG y))) && z.Uses == 1 => ((Equal|NotEqual) (CMN x y))
590
591 // CMPW(x,-y) -> CMNW(x,y) is only valid for unordered comparison, if y can be -1<<31
592 ((EQ|NE) (CMPW x z:(NEG y)) yes no) && z.Uses == 1 => ((EQ|NE) (CMNW x y) yes no)
593 ((Equal|NotEqual) (CMPW x z:(NEG y))) && z.Uses == 1 => ((Equal|NotEqual) (CMNW x y))
594
595 // For conditional instructions such as CSET, CSEL.
596 // TODO: add support for LE, GT, overflow needs to be considered.
597 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPconst [0] x:(ADDconst [c] y))) && x.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNconst [c] y))
598 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPWconst [0] x:(ADDconst [c] y))) && x.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNWconst [int32(c)] y))
599 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPconst [0] z:(ADD x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMN x y))
600 ((Equal|NotEqual|LessThan|GreaterEqual) (CMPWconst [0] z:(ADD x y))) && z.Uses == 1 => ((Equal|NotEqual|LessThanNoov|GreaterEqualNoov) (CMNW x y))
601 ((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)))
602 ((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)))
603
604 // Skip LessThan/GreaterEqual in the following rewrites.
605 // MSUB[W] a x y is a-x*y, which folds to a CMP.
606 // That can end up being reversed into InvertFlags.
607 // But absorbing InvertFlags into a no-overflow comparison flips < and >,
608 // which is wrong when the difference is the minimum int.
609 ((Equal|NotEqual) (CMPconst [0] z:(MSUB a x y))) && z.Uses == 1 => ((Equal|NotEqual) (CMP a (MUL <x.Type> x y)))
610 ((Equal|NotEqual) (CMPWconst [0] z:(MSUBW a x y))) && z.Uses == 1 => ((Equal|NotEqual) (CMPW a (MULW <x.Type> x y)))
611
612 ((CMPconst|CMNconst) [c] y) && c < 0 && c != -1<<63 => ((CMNconst|CMPconst) [-c] y)
613 ((CMPWconst|CMNWconst) [c] y) && c < 0 && c != -1<<31 => ((CMNWconst|CMPWconst) [-c] y)
614
615 ((EQ|NE) (CMPconst [0] x) yes no) => ((Z|NZ) x yes no)
616 ((EQ|NE) (CMPWconst [0] x) yes no) => ((ZW|NZW) x yes no)
617
618 ((ULE|UGT) (CMPconst [0] x)) => ((EQ|NE) (CMPconst [0] x))
619 ((ULE|UGT) (CMPWconst [0] x)) => ((EQ|NE) (CMPWconst [0] x))
620
621 ((Z|NZ) sub:(SUB x y)) && sub.Uses == 1 => ((EQ|NE) (CMP x y))
622 ((ZW|NZW) sub:(SUB x y)) && sub.Uses == 1 => ((EQ|NE) (CMPW x y))
623 ((Z|NZ) sub:(SUBconst [c] y)) && sub.Uses == 1 => ((EQ|NE) (CMPconst [c] y))
624 ((ZW|NZW) sub:(SUBconst [c] y)) && sub.Uses == 1 => ((EQ|NE) (CMPWconst [int32(c)] y))
625
626 ((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)
627 ((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)
628 // No ordering ops here; see comments above about MSUB[W].
629 ((EQ|NE) (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 => ((EQ|NE) (CMP a (MUL <x.Type> x y)) yes no)
630 ((EQ|NE) (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 => ((EQ|NE) (CMPW a (MULW <x.Type> x y)) yes no)
631
632 // Absorb bit-tests into block
633 (Z (ANDconst [c] x) yes no) && ssa.OneBit(c) => (TBZ [int64(ssa.Ntz64(c))] x yes no)
634 (NZ (ANDconst [c] x) yes no) && ssa.OneBit(c) => (TBNZ [int64(ssa.Ntz64(c))] x yes no)
635 (ZW (ANDconst [c] x) yes no) && ssa.OneBit(int64(uint32(c))) => (TBZ [int64(ssa.Ntz64(int64(uint32(c))))] x yes no)
636 (NZW (ANDconst [c] x) yes no) && ssa.OneBit(int64(uint32(c))) => (TBNZ [int64(ssa.Ntz64(int64(uint32(c))))] x yes no)
637 (EQ (TSTconst [c] x) yes no) && ssa.OneBit(c) => (TBZ [int64(ssa.Ntz64(c))] x yes no)
638 (NE (TSTconst [c] x) yes no) && ssa.OneBit(c) => (TBNZ [int64(ssa.Ntz64(c))] x yes no)
639 (EQ (TSTWconst [c] x) yes no) && ssa.OneBit(int64(uint32(c))) => (TBZ [int64(ssa.Ntz64(int64(uint32(c))))] x yes no)
640 (NE (TSTWconst [c] x) yes no) && ssa.OneBit(int64(uint32(c))) => (TBNZ [int64(ssa.Ntz64(int64(uint32(c))))] x yes no)
641
642 ((Z|NZ) s:(SRLconst [63] x) yes no) && s.Uses == 1 => (TB(Z|NZ) [63] x yes no)
643 ((Z|NZ) s:(SRAconst [63] x) yes no) && s.Uses == 1 => (TB(Z|NZ) [63] x yes no)
644
645 // Merge more operations into TBZ & TBNZ
646 (TB(Z|NZ) [t] sv:(SRLconst [s] x) yes no) && t+s < 64 && sv.Uses == 1 => (TB(Z|NZ) [t+s] x yes no )
647 (TBZ [t] (SRLconst [s] x) yes no) && t+s >= 64 => (First yes no )
648 (TBNZ [t] (SRLconst [s] x) yes no) && t+s >= 64 => (First no yes)
649
650 (TB(Z|NZ) [t] sv:(SLLconst [s] x) yes no) && t-s >= 0 && sv.Uses == 1 => (TB(Z|NZ) [t-s] x yes no )
651 (TBZ [t] (SLLconst [s] x) yes no) && t-s < 0 => (First yes no )
652 (TBNZ [t] (SLLconst [s] x) yes no) && t-s < 0 => (First no yes)
653
654 (TB(Z|NZ) [t] rv:(RORconst [r] x) yes no) && rv.Uses == 1 => (TB(Z|NZ) [int64(uint64(t+r)%64)] x yes no)
655
656 (TB(Z|NZ) [t] sv:(SRAconst [s] x) yes no) && t+s < 64 && sv.Uses == 1 => (TB(Z|NZ) [t+s] x yes no)
657 (TB(Z|NZ) [t] sv:(SRAconst [s] x) yes no) && t+s >= 64 && sv.Uses == 1 => (TB(Z|NZ) [63 ] x yes no)
658
659 // Test sign-bit for signed comparisons against zero
660 (GE (CMPWconst [0] x) yes no) => (TBZ [31] x yes no)
661 (GE (CMPconst [0] x) yes no) => (TBZ [63] x yes no)
662 (LT (CMPWconst [0] x) yes no) => (TBNZ [31] x yes no)
663 (LT (CMPconst [0] x) yes no) => (TBNZ [63] x yes no)
664
665 // A byte value (a zero-extended-byte op, so provably in [0,255]) compared
666 // against 128 (=2^7) is a bit-7 test, for both compare widths and both
667 // signednesses: with the value in [0,255] the signed and unsigned orderings
668 // against 128 coincide.
669 ((UGE|ULT) (CMPWconst [128] x) yes no) && ssa.ZeroUpper56Bits(x) => ((TBNZ|TBZ) [7] x yes no)
670 ((UGE|ULT) (CMPconst [128] x) yes no) && ssa.ZeroUpper56Bits(x) => ((TBNZ|TBZ) [7] x yes no)
671 ((GE|LT) (CMPWconst [128] x) yes no) && ssa.ZeroUpper56Bits(x) => ((TBNZ|TBZ) [7] x yes no)
672 ((GE|LT) (CMPconst [128] x) yes no) && ssa.ZeroUpper56Bits(x) => ((TBNZ|TBZ) [7] x yes no)
673
674 // fold offset into address
675 (ADDconst [off1] (MOVDaddr [off2] {sym} ptr)) && ssa.Is32Bit(off1+int64(off2)) =>
676 (MOVDaddr [int32(off1)+off2] {sym} ptr)
677
678 // fold address into load/store.
679 // Do not fold global variable access in -dynlink mode, where it will
680 // be rewritten to use the GOT via REGTMP, which currently cannot handle
681 // large offset.
682 (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
683 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
684 (MOVBload [off1+int32(off2)] {sym} ptr mem)
685 (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
686 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
687 (MOVBUload [off1+int32(off2)] {sym} ptr mem)
688 (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
689 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
690 (MOVHload [off1+int32(off2)] {sym} ptr mem)
691 (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
692 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
693 (MOVHUload [off1+int32(off2)] {sym} ptr mem)
694 (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
695 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
696 (MOVWload [off1+int32(off2)] {sym} ptr mem)
697 (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
698 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
699 (MOVWUload [off1+int32(off2)] {sym} ptr mem)
700 (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
701 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
702 (MOVDload [off1+int32(off2)] {sym} ptr mem)
703 (LDP [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
704 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
705 (LDP [off1+int32(off2)] {sym} ptr mem)
706 (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
707 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
708 (FMOVSload [off1+int32(off2)] {sym} ptr mem)
709 (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
710 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
711 (FMOVDload [off1+int32(off2)] {sym} ptr mem)
712 (FMOVQload [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
713 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
714 (FMOVQload [off1+int32(off2)] {sym} ptr mem)
715 (FLDPQ [off1] {sym} (ADDconst [off2] ptr) mem) && ssa.Is32Bit(int64(off1)+off2)
716 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
717 (FLDPQ [off1+int32(off2)] {sym} ptr mem)
718
719 // register indexed load
720 (MOVDload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVDloadidx ptr idx mem)
721 (MOVWUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVWUloadidx ptr idx mem)
722 (MOVWload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVWloadidx ptr idx mem)
723 (MOVHUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVHUloadidx ptr idx mem)
724 (MOVHload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVHloadidx ptr idx mem)
725 (MOVBUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVBUloadidx ptr idx mem)
726 (MOVBload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (MOVBloadidx ptr idx mem)
727 (FMOVSload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (FMOVSloadidx ptr idx mem)
728 (FMOVDload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil => (FMOVDloadidx ptr idx mem)
729
730 (MOVDloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVDload [int32(c)] ptr mem)
731 (MOVDloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVDload [int32(c)] ptr mem)
732 (MOVWUloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVWUload [int32(c)] ptr mem)
733 (MOVWUloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVWUload [int32(c)] ptr mem)
734 (MOVWloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVWload [int32(c)] ptr mem)
735 (MOVWloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVWload [int32(c)] ptr mem)
736 (MOVHUloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVHUload [int32(c)] ptr mem)
737 (MOVHUloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVHUload [int32(c)] ptr mem)
738 (MOVHloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVHload [int32(c)] ptr mem)
739 (MOVHloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVHload [int32(c)] ptr mem)
740 (MOVBUloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVBUload [int32(c)] ptr mem)
741 (MOVBUloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVBUload [int32(c)] ptr mem)
742 (MOVBloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (MOVBload [int32(c)] ptr mem)
743 (MOVBloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (MOVBload [int32(c)] ptr mem)
744 (FMOVSloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (FMOVSload [int32(c)] ptr mem)
745 (FMOVSloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (FMOVSload [int32(c)] ptr mem)
746 (FMOVDloadidx ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c) => (FMOVDload [int32(c)] ptr mem)
747 (FMOVDloadidx (MOVDconst [c]) ptr mem) && ssa.Is32Bit(c) => (FMOVDload [int32(c)] ptr mem)
748
749 // shifted register indexed load
750 (MOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) && off == 0 && sym == nil => (MOVDloadidx8 ptr idx mem)
751 (MOVWUload [off] {sym} (ADDshiftLL [2] ptr idx) mem) && off == 0 && sym == nil => (MOVWUloadidx4 ptr idx mem)
752 (MOVWload [off] {sym} (ADDshiftLL [2] ptr idx) mem) && off == 0 && sym == nil => (MOVWloadidx4 ptr idx mem)
753 (MOVHUload [off] {sym} (ADDshiftLL [1] ptr idx) mem) && off == 0 && sym == nil => (MOVHUloadidx2 ptr idx mem)
754 (MOVHload [off] {sym} (ADDshiftLL [1] ptr idx) mem) && off == 0 && sym == nil => (MOVHloadidx2 ptr idx mem)
755 (MOVDloadidx ptr (SLLconst [3] idx) mem) => (MOVDloadidx8 ptr idx mem)
756 (MOVWloadidx ptr (SLLconst [2] idx) mem) => (MOVWloadidx4 ptr idx mem)
757 (MOVWUloadidx ptr (SLLconst [2] idx) mem) => (MOVWUloadidx4 ptr idx mem)
758 (MOVHloadidx ptr (SLLconst [1] idx) mem) => (MOVHloadidx2 ptr idx mem)
759 (MOVHUloadidx ptr (SLLconst [1] idx) mem) => (MOVHUloadidx2 ptr idx mem)
760 (MOVHloadidx ptr (ADD idx idx) mem) => (MOVHloadidx2 ptr idx mem)
761 (MOVHUloadidx ptr (ADD idx idx) mem) => (MOVHUloadidx2 ptr idx mem)
762 (MOVDloadidx (SLLconst [3] idx) ptr mem) => (MOVDloadidx8 ptr idx mem)
763 (MOVWloadidx (SLLconst [2] idx) ptr mem) => (MOVWloadidx4 ptr idx mem)
764 (MOVWUloadidx (SLLconst [2] idx) ptr mem) => (MOVWUloadidx4 ptr idx mem)
765 (MOVHloadidx (ADD idx idx) ptr mem) => (MOVHloadidx2 ptr idx mem)
766 (MOVHUloadidx (ADD idx idx) ptr mem) => (MOVHUloadidx2 ptr idx mem)
767 (MOVDloadidx8 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<3) => (MOVDload [int32(c)<<3] ptr mem)
768 (MOVWUloadidx4 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<2) => (MOVWUload [int32(c)<<2] ptr mem)
769 (MOVWloadidx4 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<2) => (MOVWload [int32(c)<<2] ptr mem)
770 (MOVHUloadidx2 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<1) => (MOVHUload [int32(c)<<1] ptr mem)
771 (MOVHloadidx2 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<1) => (MOVHload [int32(c)<<1] ptr mem)
772
773 (FMOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) && off == 0 && sym == nil => (FMOVDloadidx8 ptr idx mem)
774 (FMOVSload [off] {sym} (ADDshiftLL [2] ptr idx) mem) && off == 0 && sym == nil => (FMOVSloadidx4 ptr idx mem)
775 (FMOVDloadidx ptr (SLLconst [3] idx) mem) => (FMOVDloadidx8 ptr idx mem)
776 (FMOVSloadidx ptr (SLLconst [2] idx) mem) => (FMOVSloadidx4 ptr idx mem)
777 (FMOVDloadidx (SLLconst [3] idx) ptr mem) => (FMOVDloadidx8 ptr idx mem)
778 (FMOVSloadidx (SLLconst [2] idx) ptr mem) => (FMOVSloadidx4 ptr idx mem)
779 (FMOVDloadidx8 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<3) => (FMOVDload ptr [int32(c)<<3] mem)
780 (FMOVSloadidx4 ptr (MOVDconst [c]) mem) && ssa.Is32Bit(c<<2) => (FMOVSload ptr [int32(c)<<2] mem)
781
782 (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
783 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
784 (MOVBstore [off1+int32(off2)] {sym} ptr val mem)
785 (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
786 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
787 (MOVHstore [off1+int32(off2)] {sym} ptr val mem)
788 (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
789 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
790 (MOVWstore [off1+int32(off2)] {sym} ptr val mem)
791 (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
792 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
793 (MOVDstore [off1+int32(off2)] {sym} ptr val mem)
794 (STP [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) && ssa.Is32Bit(int64(off1)+off2)
795 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
796 (STP [off1+int32(off2)] {sym} ptr val1 val2 mem)
797 (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
798 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
799 (FMOVSstore [off1+int32(off2)] {sym} ptr val mem)
800 (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
801 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
802 (FMOVDstore [off1+int32(off2)] {sym} ptr val mem)
803 (FMOVQstore [off1] {sym} (ADDconst [off2] ptr) val mem) && ssa.Is32Bit(int64(off1)+off2)
804 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
805 (FMOVQstore [off1+int32(off2)] {sym} ptr val mem)
806 (FSTPQ [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) && ssa.Is32Bit(int64(off1)+off2)
807 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
808 (FSTPQ [off1+int32(off2)] {sym} ptr val1 val2 mem)
809
810 // register indexed store
811 (MOVDstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVDstoreidx ptr idx val mem)
812 (MOVWstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVWstoreidx ptr idx val mem)
813 (MOVHstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVHstoreidx ptr idx val mem)
814 (MOVBstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (MOVBstoreidx ptr idx val mem)
815 (FMOVDstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (FMOVDstoreidx ptr idx val mem)
816 (FMOVSstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil => (FMOVSstoreidx ptr idx val mem)
817 (MOVDstoreidx ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c) => (MOVDstore [int32(c)] ptr val mem)
818 (MOVDstoreidx (MOVDconst [c]) idx val mem) && ssa.Is32Bit(c) => (MOVDstore [int32(c)] idx val mem)
819 (MOVWstoreidx ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c) => (MOVWstore [int32(c)] ptr val mem)
820 (MOVWstoreidx (MOVDconst [c]) idx val mem) && ssa.Is32Bit(c) => (MOVWstore [int32(c)] idx val mem)
821 (MOVHstoreidx ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c) => (MOVHstore [int32(c)] ptr val mem)
822 (MOVHstoreidx (MOVDconst [c]) idx val mem) && ssa.Is32Bit(c) => (MOVHstore [int32(c)] idx val mem)
823 (MOVBstoreidx ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c) => (MOVBstore [int32(c)] ptr val mem)
824 (MOVBstoreidx (MOVDconst [c]) idx val mem) && ssa.Is32Bit(c) => (MOVBstore [int32(c)] idx val mem)
825 (FMOVDstoreidx ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c) => (FMOVDstore [int32(c)] ptr val mem)
826 (FMOVDstoreidx (MOVDconst [c]) idx val mem) && ssa.Is32Bit(c) => (FMOVDstore [int32(c)] idx val mem)
827 (FMOVSstoreidx ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c) => (FMOVSstore [int32(c)] ptr val mem)
828 (FMOVSstoreidx (MOVDconst [c]) idx val mem) && ssa.Is32Bit(c) => (FMOVSstore [int32(c)] idx val mem)
829
830 // shifted register indexed store
831 (MOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) && off == 0 && sym == nil => (MOVDstoreidx8 ptr idx val mem)
832 (MOVWstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) && off == 0 && sym == nil => (MOVWstoreidx4 ptr idx val mem)
833 (MOVHstore [off] {sym} (ADDshiftLL [1] ptr idx) val mem) && off == 0 && sym == nil => (MOVHstoreidx2 ptr idx val mem)
834 (MOVDstoreidx ptr (SLLconst [3] idx) val mem) => (MOVDstoreidx8 ptr idx val mem)
835 (MOVWstoreidx ptr (SLLconst [2] idx) val mem) => (MOVWstoreidx4 ptr idx val mem)
836 (MOVHstoreidx ptr (SLLconst [1] idx) val mem) => (MOVHstoreidx2 ptr idx val mem)
837 (MOVHstoreidx ptr (ADD idx idx) val mem) => (MOVHstoreidx2 ptr idx val mem)
838 (MOVDstoreidx (SLLconst [3] idx) ptr val mem) => (MOVDstoreidx8 ptr idx val mem)
839 (MOVWstoreidx (SLLconst [2] idx) ptr val mem) => (MOVWstoreidx4 ptr idx val mem)
840 (MOVHstoreidx (SLLconst [1] idx) ptr val mem) => (MOVHstoreidx2 ptr idx val mem)
841 (MOVHstoreidx (ADD idx idx) ptr val mem) => (MOVHstoreidx2 ptr idx val mem)
842 (MOVDstoreidx8 ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c<<3) => (MOVDstore [int32(c)<<3] ptr val mem)
843 (MOVWstoreidx4 ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c<<2) => (MOVWstore [int32(c)<<2] ptr val mem)
844 (MOVHstoreidx2 ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c<<1) => (MOVHstore [int32(c)<<1] ptr val mem)
845
846 (FMOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) && off == 0 && sym == nil => (FMOVDstoreidx8 ptr idx val mem)
847 (FMOVSstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) && off == 0 && sym == nil => (FMOVSstoreidx4 ptr idx val mem)
848 (FMOVDstoreidx ptr (SLLconst [3] idx) val mem) => (FMOVDstoreidx8 ptr idx val mem)
849 (FMOVSstoreidx ptr (SLLconst [2] idx) val mem) => (FMOVSstoreidx4 ptr idx val mem)
850 (FMOVDstoreidx (SLLconst [3] idx) ptr val mem) => (FMOVDstoreidx8 ptr idx val mem)
851 (FMOVSstoreidx (SLLconst [2] idx) ptr val mem) => (FMOVSstoreidx4 ptr idx val mem)
852 (FMOVDstoreidx8 ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c<<3) => (FMOVDstore [int32(c)<<3] ptr val mem)
853 (FMOVSstoreidx4 ptr (MOVDconst [c]) val mem) && ssa.Is32Bit(c<<2) => (FMOVSstore [int32(c)<<2] ptr val mem)
854
855 (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
856 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
857 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
858 (MOVBload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
859 (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
860 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
861 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
862 (MOVBUload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
863 (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
864 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
865 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
866 (MOVHload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
867 (MOVHUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
868 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
869 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
870 (MOVHUload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
871 (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
872 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
873 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
874 (MOVWload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
875 (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
876 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
877 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
878 (MOVWUload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
879 (MOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
880 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
881 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
882 (MOVDload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
883 (LDP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
884 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
885 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
886 (LDP [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
887 (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
888 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
889 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
890 (FMOVSload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
891 (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
892 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
893 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
894 (FMOVDload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
895 (FMOVQload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
896 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
897 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
898 (FMOVQload [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
899 (FLDPQ [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
900 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
901 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
902 (FLDPQ [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr mem)
903
904 (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
905 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
906 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
907 (MOVBstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
908 (MOVHstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
909 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
910 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
911 (MOVHstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
912 (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
913 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
914 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
915 (MOVWstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
916 (MOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
917 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
918 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
919 (MOVDstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
920 (STP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem)
921 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
922 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
923 (STP [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val1 val2 mem)
924 (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
925 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
926 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
927 (FMOVSstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
928 (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
929 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
930 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
931 (FMOVDstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
932 (FMOVQstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
933 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
934 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
935 (FMOVQstore [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val mem)
936 (FSTPQ [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem)
937 && ssa.CanMergeSym(sym1,sym2) && ssa.Is32Bit(int64(off1)+int64(off2))
938 && (ptr.Op != ssaop.OpSB || !config.Ctxt.Flag_dynlink) =>
939 (FSTPQ [off1+off2] {ssa.MergeSym(sym1,sym2)} ptr val1 val2 mem)
940
941 // replace load from same location as preceding store with zero/sign extension (or copy in case of full width)
942 // these seem to have bad interaction with other rules, resulting in slower code
943 //(MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> (MOVBreg x)
944 //(MOVBUload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> (MOVBUreg x)
945 //(MOVHload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> (MOVHreg x)
946 //(MOVHUload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> (MOVHUreg x)
947 //(MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> (MOVWreg x)
948 //(MOVWUload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> (MOVWUreg x)
949 //(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> x
950 //(FMOVSload [off] {sym} ptr (FMOVSstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> x
951 //(FMOVDload [off] {sym} ptr (FMOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> x
952 //(LDP [off] {sym} ptr (STP [off2] {sym2} ptr2 x y _)) && sym == sym2 && off == off2 && ssa.IsSamePtr(ptr, ptr2) -> x y
953
954 // don't extend before store
955 (MOVBstore [off] {sym} ptr (MOVBreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
956 (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
957 (MOVBstore [off] {sym} ptr (MOVHreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
958 (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
959 (MOVBstore [off] {sym} ptr (MOVWreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
960 (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVBstore [off] {sym} ptr x mem)
961 (MOVHstore [off] {sym} ptr (MOVHreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
962 (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
963 (MOVHstore [off] {sym} ptr (MOVWreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
964 (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVHstore [off] {sym} ptr x mem)
965 (MOVWstore [off] {sym} ptr (MOVWreg x) mem) => (MOVWstore [off] {sym} ptr x mem)
966 (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) => (MOVWstore [off] {sym} ptr x mem)
967 (MOVBstoreidx ptr idx (MOVBreg x) mem) => (MOVBstoreidx ptr idx x mem)
968 (MOVBstoreidx ptr idx (MOVBUreg x) mem) => (MOVBstoreidx ptr idx x mem)
969 (MOVBstoreidx ptr idx (MOVHreg x) mem) => (MOVBstoreidx ptr idx x mem)
970 (MOVBstoreidx ptr idx (MOVHUreg x) mem) => (MOVBstoreidx ptr idx x mem)
971 (MOVBstoreidx ptr idx (MOVWreg x) mem) => (MOVBstoreidx ptr idx x mem)
972 (MOVBstoreidx ptr idx (MOVWUreg x) mem) => (MOVBstoreidx ptr idx x mem)
973 (MOVHstoreidx ptr idx (MOVHreg x) mem) => (MOVHstoreidx ptr idx x mem)
974 (MOVHstoreidx ptr idx (MOVHUreg x) mem) => (MOVHstoreidx ptr idx x mem)
975 (MOVHstoreidx ptr idx (MOVWreg x) mem) => (MOVHstoreidx ptr idx x mem)
976 (MOVHstoreidx ptr idx (MOVWUreg x) mem) => (MOVHstoreidx ptr idx x mem)
977 (MOVWstoreidx ptr idx (MOVWreg x) mem) => (MOVWstoreidx ptr idx x mem)
978 (MOVWstoreidx ptr idx (MOVWUreg x) mem) => (MOVWstoreidx ptr idx x mem)
979 (MOVHstoreidx2 ptr idx (MOVHreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
980 (MOVHstoreidx2 ptr idx (MOVHUreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
981 (MOVHstoreidx2 ptr idx (MOVWreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
982 (MOVHstoreidx2 ptr idx (MOVWUreg x) mem) => (MOVHstoreidx2 ptr idx x mem)
983 (MOVWstoreidx4 ptr idx (MOVWreg x) mem) => (MOVWstoreidx4 ptr idx x mem)
984 (MOVWstoreidx4 ptr idx (MOVWUreg x) mem) => (MOVWstoreidx4 ptr idx x mem)
985
986 // if a register move has only 1 use, just use the same register without emitting instruction
987 // MOVDnop doesn't emit instruction, only for ensuring the type.
988 (MOVDreg x) && x.Uses == 1 => (MOVDnop x)
989
990 // TODO: we should be able to get rid of MOVDnop all together.
991 // But for now, this is enough to get rid of lots of them.
992 (MOVDnop (MOVDconst [c])) => (MOVDconst [c])
993
994 // fold constant into arithmetic ops
995 (ADD x (MOVDconst <t> [c])) && !t.IsPtr() => (ADDconst [c] x)
996 (SUB x (MOVDconst [c])) => (SUBconst [c] x)
997 (AND x (MOVDconst [c])) => (ANDconst [c] x)
998 (OR x (MOVDconst [c])) => (ORconst [c] x)
999 (XOR x (MOVDconst [c])) => (XORconst [c] x)
1000 (TST x (MOVDconst [c])) => (TSTconst [c] x)
1001 (TSTW x (MOVDconst [c])) => (TSTWconst [int32(c)] x)
1002 (CMN x (MOVDconst [c])) => (CMNconst [c] x)
1003 (CMNW x (MOVDconst [c])) => (CMNWconst [int32(c)] x)
1004 (BIC x (MOVDconst [c])) => (ANDconst [^c] x)
1005 (EON x (MOVDconst [c])) => (XORconst [^c] x)
1006 (ORN x (MOVDconst [c])) => (ORconst [^c] x)
1007
1008 (SLL x (MOVDconst [c])) => (SLLconst x [c&63])
1009 (SRL x (MOVDconst [c])) => (SRLconst x [c&63])
1010 (SRA x (MOVDconst [c])) => (SRAconst x [c&63])
1011 (SLL x (ANDconst [63] y)) => (SLL x y)
1012 (SRL x (ANDconst [63] y)) => (SRL x y)
1013 (SRA x (ANDconst [63] y)) => (SRA x y)
1014
1015 (CMP x (MOVDconst [c])) => (CMPconst [c] x)
1016 (CMP (MOVDconst [c]) x) => (InvertFlags (CMPconst [c] x))
1017 (CMPW x (MOVDconst [c])) => (CMPWconst [int32(c)] x)
1018 (CMPW (MOVDconst [c]) x) => (InvertFlags (CMPWconst [int32(c)] x))
1019
1020 (ROR x (MOVDconst [c])) => (RORconst x [c&63])
1021 (RORW x (MOVDconst [c])) => (RORWconst x [c&31])
1022
1023 (ADDSflags x (MOVDconst [c])) => (ADDSconstflags [c] x)
1024
1025 (ADDconst [c] y) && c < 0 => (SUBconst [-c] y)
1026
1027 // Canonicalize the order of arguments to comparisons - helps with CSE.
1028 ((CMP|CMPW) x y) && ssa.CanonLessThan(x,y) => (InvertFlags ((CMP|CMPW) y x))
1029
1030 // mul-neg => mneg
1031 (NEG (MUL x y)) => (MNEG x y)
1032 (NEG (MULW x y)) && v.Type.Size() <= 4 => (MNEGW x y)
1033 (MUL (NEG x) y) => (MNEG x y)
1034 (MULW (NEG x) y) => (MNEGW x y)
1035
1036 // madd/msub
1037 (ADD a l:(MUL x y)) && l.Uses==1 && ssa.Clobber(l) => (MADD a x y)
1038 (SUB a l:(MUL x y)) && l.Uses==1 && ssa.Clobber(l) => (MSUB a x y)
1039 (ADD a l:(MNEG x y)) && l.Uses==1 && ssa.Clobber(l) => (MSUB a x y)
1040 (SUB a l:(MNEG x y)) && l.Uses==1 && ssa.Clobber(l) => (MADD a x y)
1041
1042 (ADD a l:(MULW x y)) && v.Type.Size() <= 4 && l.Uses==1 && ssa.Clobber(l) => (MADDW a x y)
1043 (SUB a l:(MULW x y)) && v.Type.Size() <= 4 && l.Uses==1 && ssa.Clobber(l) => (MSUBW a x y)
1044 (ADD a l:(MNEGW x y)) && v.Type.Size() <= 4 && l.Uses==1 && ssa.Clobber(l) => (MSUBW a x y)
1045 (SUB a l:(MNEGW x y)) && v.Type.Size() <= 4 && l.Uses==1 && ssa.Clobber(l) => (MADDW a x y)
1046
1047 // madd/msub can't take constant arguments, so do a bit of reordering if a non-constant is available.
1048 // Note: don't reorder arithmetic concerning pointers, as we must ensure that
1049 // no intermediate computations are invalid pointers.
1050 (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))
1051 (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))
1052 (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))
1053 (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))
1054
1055 // optimize ADCSflags, SBCSflags and friends
1056 (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] (ADCzerocarry <typ.UInt64> c)))) => (ADCSflags x y c)
1057 (ADCSflags x y (Select1 <types.TypeFlags> (ADDSconstflags [-1] (MOVDconst [0])))) => (ADDSflags x y)
1058 (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags (NEG <typ.UInt64> (NGCzerocarry <typ.UInt64> bo))))) => (SBCSflags x y bo)
1059 (SBCSflags x y (Select1 <types.TypeFlags> (NEGSflags (MOVDconst [0])))) => (SUBSflags x y)
1060
1061 // mul by constant
1062 (MUL _ (MOVDconst [0])) => (MOVDconst [0])
1063 (MUL x (MOVDconst [1])) => x
1064
1065 (MULW _ (MOVDconst [c])) && int32(c)==0 => (MOVDconst [0])
1066 (MULW x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg x)
1067
1068 (MUL x (MOVDconst [c])) && ssa.CanMulStrengthReduce(config, c) => {ssa.MulStrengthReduce(v, x, c)}
1069 (MULW x (MOVDconst [c])) && v.Type.Size() <= 4 && ssa.CanMulStrengthReduce32(config, int32(c)) => {ssa.MulStrengthReduce32(v, x, int32(c))}
1070
1071 // mneg by constant
1072 (MNEG x (MOVDconst [-1])) => x
1073 (MNEG _ (MOVDconst [0])) => (MOVDconst [0])
1074 (MNEG x (MOVDconst [1])) => (NEG x)
1075 (MNEG x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (NEG (SLLconst <x.Type> [ssa.Log64(c)] x))
1076 (MNEG x (MOVDconst [c])) && ssa.IsPowerOfTwo(c-1) && c >= 3 => (NEG (ADDshiftLL <x.Type> x x [ssa.Log64(c-1)]))
1077 (MNEG x (MOVDconst [c])) && ssa.IsPowerOfTwo(c+1) && c >= 7 => (NEG (ADDshiftLL <x.Type> (NEG <x.Type> x) x [ssa.Log64(c+1)]))
1078 (MNEG x (MOVDconst [c])) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) => (SLLconst <x.Type> [ssa.Log64(c/3)] (SUBshiftLL <x.Type> x x [2]))
1079 (MNEG x (MOVDconst [c])) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) => (NEG (SLLconst <x.Type> [ssa.Log64(c/5)] (ADDshiftLL <x.Type> x x [2])))
1080 (MNEG x (MOVDconst [c])) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) => (SLLconst <x.Type> [ssa.Log64(c/7)] (SUBshiftLL <x.Type> x x [3]))
1081 (MNEG x (MOVDconst [c])) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) => (NEG (SLLconst <x.Type> [ssa.Log64(c/9)] (ADDshiftLL <x.Type> x x [3])))
1082
1083
1084 (MNEGW x (MOVDconst [c])) && int32(c)==-1 => (MOVWUreg x)
1085 (MNEGW _ (MOVDconst [c])) && int32(c)==0 => (MOVDconst [0])
1086 (MNEGW x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg (NEG <v.Type> x))
1087 (MNEGW x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (MOVWUreg (NEG <v.Type> (SLLconst <v.Type> [ssa.Log64(c)] x)))
1088 (MNEGW x (MOVDconst [c])) && ssa.IsPowerOfTwo(c-1) && int32(c) >= 3 => (MOVWUreg (NEG <v.Type> (ADDshiftLL <v.Type> x x [ssa.Log64(c-1)])))
1089 (MNEGW x (MOVDconst [c])) && ssa.IsPowerOfTwo(c+1) && int32(c) >= 7 => (MOVWUreg (NEG <v.Type> (ADDshiftLL <v.Type> (NEG <v.Type> x) x [ssa.Log64(c+1)])))
1090 (MNEGW x (MOVDconst [c])) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) && ssa.Is32Bit(c) => (MOVWUreg (SLLconst <v.Type> [ssa.Log64(c/3)] (SUBshiftLL <v.Type> x x [2])))
1091 (MNEGW x (MOVDconst [c])) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) && ssa.Is32Bit(c) => (MOVWUreg (NEG <v.Type> (SLLconst <v.Type> [ssa.Log64(c/5)] (ADDshiftLL <v.Type> x x [2]))))
1092 (MNEGW x (MOVDconst [c])) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) && ssa.Is32Bit(c) => (MOVWUreg (SLLconst <v.Type> [ssa.Log64(c/7)] (SUBshiftLL <v.Type> x x [3])))
1093 (MNEGW x (MOVDconst [c])) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) && ssa.Is32Bit(c) => (MOVWUreg (NEG <v.Type> (SLLconst <v.Type> [ssa.Log64(c/9)] (ADDshiftLL <v.Type> x x [3]))))
1094
1095
1096 (MADD a x (MOVDconst [-1])) => (SUB a x)
1097 (MADD a _ (MOVDconst [0])) => a
1098 (MADD a x (MOVDconst [1])) => (ADD a x)
1099 (MADD a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (ADDshiftLL a x [ssa.Log64(c)])
1100 (MADD a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c-1) && c>=3 => (ADD a (ADDshiftLL <x.Type> x x [ssa.Log64(c-1)]))
1101 (MADD a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c+1) && c>=7 => (SUB a (SUBshiftLL <x.Type> x x [ssa.Log64(c+1)]))
1102 (MADD a x (MOVDconst [c])) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [2]) [ssa.Log64(c/3)])
1103 (MADD a x (MOVDconst [c])) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [2]) [ssa.Log64(c/5)])
1104 (MADD a x (MOVDconst [c])) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [3]) [ssa.Log64(c/7)])
1105 (MADD a x (MOVDconst [c])) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [3]) [ssa.Log64(c/9)])
1106
1107 (MADD a (MOVDconst [-1]) x) => (SUB a x)
1108 (MADD a (MOVDconst [0]) _) => a
1109 (MADD a (MOVDconst [1]) x) => (ADD a x)
1110 (MADD a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c) => (ADDshiftLL a x [ssa.Log64(c)])
1111 (MADD a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c-1) && c>=3 => (ADD a (ADDshiftLL <x.Type> x x [ssa.Log64(c-1)]))
1112 (MADD a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c+1) && c>=7 => (SUB a (SUBshiftLL <x.Type> x x [ssa.Log64(c+1)]))
1113 (MADD a (MOVDconst [c]) x) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [2]) [ssa.Log64(c/3)])
1114 (MADD a (MOVDconst [c]) x) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [2]) [ssa.Log64(c/5)])
1115 (MADD a (MOVDconst [c]) x) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) => (SUBshiftLL a (SUBshiftLL <x.Type> x x [3]) [ssa.Log64(c/7)])
1116 (MADD a (MOVDconst [c]) x) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) => (ADDshiftLL a (ADDshiftLL <x.Type> x x [3]) [ssa.Log64(c/9)])
1117
1118 (MADDW a x (MOVDconst [c])) && int32(c)==-1 => (MOVWUreg (SUB <v.Type> a x))
1119 (MADDW a _ (MOVDconst [c])) && int32(c)==0 => (MOVWUreg a)
1120 (MADDW a x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg (ADD <v.Type> a x))
1121 (MADDW a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (MOVWUreg (ADDshiftLL <v.Type> a x [ssa.Log64(c)]))
1122 (MADDW a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (ADD <v.Type> a (ADDshiftLL <v.Type> x x [ssa.Log64(c-1)])))
1123 (MADDW a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (SUB <v.Type> a (SUBshiftLL <v.Type> x x [ssa.Log64(c+1)])))
1124 (MADDW a x (MOVDconst [c])) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [2]) [ssa.Log64(c/3)]))
1125 (MADDW a x (MOVDconst [c])) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [2]) [ssa.Log64(c/5)]))
1126 (MADDW a x (MOVDconst [c])) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [3]) [ssa.Log64(c/7)]))
1127 (MADDW a x (MOVDconst [c])) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [3]) [ssa.Log64(c/9)]))
1128
1129 (MADDW a (MOVDconst [c]) x) && int32(c)==-1 => (MOVWUreg (SUB <v.Type> a x))
1130 (MADDW a (MOVDconst [c]) _) && int32(c)==0 => (MOVWUreg a)
1131 (MADDW a (MOVDconst [c]) x) && int32(c)==1 => (MOVWUreg (ADD <v.Type> a x))
1132 (MADDW a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c) => (MOVWUreg (ADDshiftLL <v.Type> a x [ssa.Log64(c)]))
1133 (MADDW a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (ADD <v.Type> a (ADDshiftLL <v.Type> x x [ssa.Log64(c-1)])))
1134 (MADDW a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (SUB <v.Type> a (SUBshiftLL <v.Type> x x [ssa.Log64(c+1)])))
1135 (MADDW a (MOVDconst [c]) x) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [2]) [ssa.Log64(c/3)]))
1136 (MADDW a (MOVDconst [c]) x) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [2]) [ssa.Log64(c/5)]))
1137 (MADDW a (MOVDconst [c]) x) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [3]) [ssa.Log64(c/7)]))
1138 (MADDW a (MOVDconst [c]) x) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [3]) [ssa.Log64(c/9)]))
1139
1140 (MSUB a x (MOVDconst [-1])) => (ADD a x)
1141 (MSUB a _ (MOVDconst [0])) => a
1142 (MSUB a x (MOVDconst [1])) => (SUB a x)
1143 (MSUB a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (SUBshiftLL a x [ssa.Log64(c)])
1144 (MSUB a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c-1) && c>=3 => (SUB a (ADDshiftLL <x.Type> x x [ssa.Log64(c-1)]))
1145 (MSUB a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c+1) && c>=7 => (ADD a (SUBshiftLL <x.Type> x x [ssa.Log64(c+1)]))
1146 (MSUB a x (MOVDconst [c])) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [2]) [ssa.Log64(c/3)])
1147 (MSUB a x (MOVDconst [c])) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [2]) [ssa.Log64(c/5)])
1148 (MSUB a x (MOVDconst [c])) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [3]) [ssa.Log64(c/7)])
1149 (MSUB a x (MOVDconst [c])) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [3]) [ssa.Log64(c/9)])
1150
1151 (MSUB a (MOVDconst [-1]) x) => (ADD a x)
1152 (MSUB a (MOVDconst [0]) _) => a
1153 (MSUB a (MOVDconst [1]) x) => (SUB a x)
1154 (MSUB a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c) => (SUBshiftLL a x [ssa.Log64(c)])
1155 (MSUB a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c-1) && c>=3 => (SUB a (ADDshiftLL <x.Type> x x [ssa.Log64(c-1)]))
1156 (MSUB a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c+1) && c>=7 => (ADD a (SUBshiftLL <x.Type> x x [ssa.Log64(c+1)]))
1157 (MSUB a (MOVDconst [c]) x) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [2]) [ssa.Log64(c/3)])
1158 (MSUB a (MOVDconst [c]) x) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [2]) [ssa.Log64(c/5)])
1159 (MSUB a (MOVDconst [c]) x) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) => (ADDshiftLL a (SUBshiftLL <x.Type> x x [3]) [ssa.Log64(c/7)])
1160 (MSUB a (MOVDconst [c]) x) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) => (SUBshiftLL a (ADDshiftLL <x.Type> x x [3]) [ssa.Log64(c/9)])
1161
1162 (MSUBW a x (MOVDconst [c])) && int32(c)==-1 => (MOVWUreg (ADD <v.Type> a x))
1163 (MSUBW a _ (MOVDconst [c])) && int32(c)==0 => (MOVWUreg a)
1164 (MSUBW a x (MOVDconst [c])) && int32(c)==1 => (MOVWUreg (SUB <v.Type> a x))
1165 (MSUBW a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (MOVWUreg (SUBshiftLL <v.Type> a x [ssa.Log64(c)]))
1166 (MSUBW a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (SUB <v.Type> a (ADDshiftLL <v.Type> x x [ssa.Log64(c-1)])))
1167 (MSUBW a x (MOVDconst [c])) && ssa.IsPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (ADD <v.Type> a (SUBshiftLL <v.Type> x x [ssa.Log64(c+1)])))
1168 (MSUBW a x (MOVDconst [c])) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [2]) [ssa.Log64(c/3)]))
1169 (MSUBW a x (MOVDconst [c])) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [2]) [ssa.Log64(c/5)]))
1170 (MSUBW a x (MOVDconst [c])) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [3]) [ssa.Log64(c/7)]))
1171 (MSUBW a x (MOVDconst [c])) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [3]) [ssa.Log64(c/9)]))
1172
1173 (MSUBW a (MOVDconst [c]) x) && int32(c)==-1 => (MOVWUreg (ADD <v.Type> a x))
1174 (MSUBW a (MOVDconst [c]) _) && int32(c)==0 => (MOVWUreg a)
1175 (MSUBW a (MOVDconst [c]) x) && int32(c)==1 => (MOVWUreg (SUB <v.Type> a x))
1176 (MSUBW a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c) => (MOVWUreg (SUBshiftLL <v.Type> a x [ssa.Log64(c)]))
1177 (MSUBW a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c-1) && int32(c)>=3 => (MOVWUreg (SUB <v.Type> a (ADDshiftLL <v.Type> x x [ssa.Log64(c-1)])))
1178 (MSUBW a (MOVDconst [c]) x) && ssa.IsPowerOfTwo(c+1) && int32(c)>=7 => (MOVWUreg (ADD <v.Type> a (SUBshiftLL <v.Type> x x [ssa.Log64(c+1)])))
1179 (MSUBW a (MOVDconst [c]) x) && c%3 == 0 && ssa.IsPowerOfTwo(c/3) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [2]) [ssa.Log64(c/3)]))
1180 (MSUBW a (MOVDconst [c]) x) && c%5 == 0 && ssa.IsPowerOfTwo(c/5) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [2]) [ssa.Log64(c/5)]))
1181 (MSUBW a (MOVDconst [c]) x) && c%7 == 0 && ssa.IsPowerOfTwo(c/7) && ssa.Is32Bit(c) => (MOVWUreg (ADDshiftLL <v.Type> a (SUBshiftLL <v.Type> x x [3]) [ssa.Log64(c/7)]))
1182 (MSUBW a (MOVDconst [c]) x) && c%9 == 0 && ssa.IsPowerOfTwo(c/9) && ssa.Is32Bit(c) => (MOVWUreg (SUBshiftLL <v.Type> a (ADDshiftLL <v.Type> x x [3]) [ssa.Log64(c/9)]))
1183
1184 // div by constant
1185 (UDIV x (MOVDconst [1])) => x
1186 (UDIV x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (SRLconst [ssa.Log64(c)] x)
1187 (UDIVW x (MOVDconst [c])) && uint32(c)==1 => (MOVWUreg x)
1188 (UDIVW x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) && ssa.Is32Bit(c) => (SRLconst [ssa.Log64(c)] (MOVWUreg <v.Type> x))
1189 (UMOD _ (MOVDconst [1])) => (MOVDconst [0])
1190 (UMOD x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) => (ANDconst [c-1] x)
1191 (UMODW _ (MOVDconst [c])) && uint32(c)==1 => (MOVDconst [0])
1192 (UMODW x (MOVDconst [c])) && ssa.IsPowerOfTwo(c) && ssa.Is32Bit(c) => (ANDconst [c-1] x)
1193
1194 // generic simplifications
1195 (ADD x (NEG y)) => (SUB x y)
1196 (SUB x (NEG y)) => (ADD x y)
1197 (SUB x x) => (MOVDconst [0])
1198 (AND x x) => x
1199 (OR x x) => x
1200 (XOR x x) => (MOVDconst [0])
1201 (BIC x x) => (MOVDconst [0])
1202 (EON x x) => (MOVDconst [-1])
1203 (ORN x x) => (MOVDconst [-1])
1204 (AND x (MVN y)) => (BIC x y)
1205 (XOR x (MVN y)) => (EON x y)
1206 (OR x (MVN y)) => (ORN x y)
1207 (MVN (XOR x y)) => (EON x y)
1208 (NEG (SUB x y)) => (SUB y x)
1209 (NEG (NEG x)) => x
1210
1211 (CSEL [cc] (MOVDconst [-1]) (MOVDconst [0]) flag) => (CSETM [cc] flag)
1212 (CSEL [cc] (MOVDconst [0]) (MOVDconst [-1]) flag) => (CSETM [arm64Negate(cc)] flag)
1213 (CSEL [cc] x (MOVDconst [0]) flag) => (CSEL0 [cc] x flag)
1214 (CSEL [cc] (MOVDconst [0]) y flag) => (CSEL0 [arm64Negate(cc)] y flag)
1215 (CSEL [cc] x (ADDconst [1] a) flag) => (CSINC [cc] x a flag)
1216 (CSEL [cc] (ADDconst [1] a) x flag) => (CSINC [arm64Negate(cc)] x a flag)
1217 (CSEL [cc] x (MVN a) flag) => (CSINV [cc] x a flag)
1218 (CSEL [cc] (MVN a) x flag) => (CSINV [arm64Negate(cc)] x a flag)
1219 (CSEL [cc] x (NEG a) flag) => (CSNEG [cc] x a flag)
1220 (CSEL [cc] (NEG a) x flag) => (CSNEG [arm64Negate(cc)] x a flag)
1221
1222 (SUB x (SUB y z)) => (SUB (ADD <v.Type> x z) y)
1223 (SUB (SUB x y) z) => (SUB x (ADD <v.Type> y z))
1224
1225 // remove redundant *const ops
1226 (ADDconst [0] x) => x
1227 (SUBconst [0] x) => x
1228 (ANDconst [0] _) => (MOVDconst [0])
1229 (ANDconst [-1] x) => x
1230 (ORconst [0] x) => x
1231 (ORconst [-1] _) => (MOVDconst [-1])
1232 (XORconst [0] x) => x
1233 (XORconst [-1] x) => (MVN x)
1234
1235 // generic constant folding
1236 (ADDconst [c] (MOVDconst [d])) => (MOVDconst [c+d])
1237 (ADDconst [c] (ADDconst [d] x)) => (ADDconst [c+d] x)
1238 (ADDconst [c] (SUBconst [d] x)) => (ADDconst [c-d] x)
1239 (SUBconst [c] (MOVDconst [d])) => (MOVDconst [d-c])
1240 (SUBconst [c] (SUBconst [d] x)) => (ADDconst [-c-d] x)
1241 (SUBconst [c] (ADDconst [d] x)) => (ADDconst [-c+d] x)
1242 (SLLconst [c] (MOVDconst [d])) => (MOVDconst [d<<uint64(c)])
1243 (SRLconst [c] (MOVDconst [d])) => (MOVDconst [int64(uint64(d)>>uint64(c))])
1244 (SRAconst [c] (MOVDconst [d])) => (MOVDconst [d>>uint64(c)])
1245 (MUL (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [c*d])
1246 (MNEG (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [-c*d])
1247 (MULW (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [int64(uint32(c*d))])
1248 (MNEGW (MOVDconst [c]) (MOVDconst [d])) => (MOVDconst [int64(uint32(-c*d))])
1249 (MADD (MOVDconst [c]) x y) => (ADDconst [c] (MUL <x.Type> x y))
1250 (MSUB (MOVDconst [c]) x y) => (ADDconst [c] (MNEG <x.Type> x y))
1251 (MADD a (MOVDconst [c]) (MOVDconst [d])) => (ADDconst [c*d] a)
1252 (MSUB a (MOVDconst [c]) (MOVDconst [d])) => (SUBconst [c*d] a)
1253 (MADDW (MOVDconst [c]) x y) => (MOVWUreg (ADDconst <v.Type> [c] (MULW <v.Type> x y)))
1254 (MSUBW (MOVDconst [c]) x y) => (MOVWUreg (ADDconst <v.Type> [c] (MNEGW <v.Type> x y)))
1255 (MADDW a (MOVDconst [c]) (MOVDconst [d])) => (MOVWUreg (ADDconst <v.Type> [c*d] a))
1256 (MSUBW a (MOVDconst [c]) (MOVDconst [d])) => (MOVWUreg (SUBconst <v.Type> [c*d] a))
1257 (DIV (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [c/d])
1258 (UDIV (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint64(c)/uint64(d))])
1259 (DIVW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(int32(c)/int32(d)))])
1260 (UDIVW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(c)/uint32(d))])
1261 (MOD (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [c%d])
1262 (UMOD (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint64(c)%uint64(d))])
1263 (MODW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(int32(c)%int32(d)))])
1264 (UMODW (MOVDconst [c]) (MOVDconst [d])) && d != 0 => (MOVDconst [int64(uint32(c)%uint32(d))])
1265 (ANDconst [c] (MOVDconst [d])) => (MOVDconst [c&d])
1266 (ANDconst [c] (ANDconst [d] x)) => (ANDconst [c&d] x)
1267 (ANDconst [c] (MOVWUreg x)) => (ANDconst [c&(1<<32-1)] x)
1268 (ANDconst [c] (MOVHUreg x)) => (ANDconst [c&(1<<16-1)] x)
1269 (ANDconst [c] (MOVBUreg x)) => (ANDconst [c&(1<<8-1)] x)
1270 (MOVWUreg (ANDconst [c] x)) => (ANDconst [c&(1<<32-1)] x)
1271 (MOVHUreg (ANDconst [c] x)) => (ANDconst [c&(1<<16-1)] x)
1272 (MOVBUreg (ANDconst [c] x)) => (ANDconst [c&(1<<8-1)] x)
1273 (ORconst [c] (MOVDconst [d])) => (MOVDconst [c|d])
1274 (ORconst [c] (ORconst [d] x)) => (ORconst [c|d] x)
1275 (XORconst [c] (MOVDconst [d])) => (MOVDconst [c^d])
1276 (XORconst [c] (XORconst [d] x)) => (XORconst [c^d] x)
1277 (MVN (MOVDconst [c])) => (MOVDconst [^c])
1278 (NEG (MOVDconst [c])) => (MOVDconst [-c])
1279 (MOVBreg (MOVDconst [c])) => (MOVDconst [int64(int8(c))])
1280 (MOVBUreg (MOVDconst [c])) => (MOVDconst [int64(uint8(c))])
1281 (MOVHreg (MOVDconst [c])) => (MOVDconst [int64(int16(c))])
1282 (MOVHUreg (MOVDconst [c])) => (MOVDconst [int64(uint16(c))])
1283 (MOVWreg (MOVDconst [c])) => (MOVDconst [int64(int32(c))])
1284 (MOVWUreg (MOVDconst [c])) => (MOVDconst [int64(uint32(c))])
1285 (MOVDreg (MOVDconst [c])) => (MOVDconst [c])
1286
1287 // constant comparisons
1288 (CMPconst (MOVDconst [x]) [y]) => (FlagConstant [ssa.SubFlags64(x,y)])
1289 (CMPWconst (MOVDconst [x]) [y]) => (FlagConstant [ssa.SubFlags32(int32(x),y)])
1290 (TSTconst (MOVDconst [x]) [y]) => (FlagConstant [ssa.LogicFlags64(x&y)])
1291 (TSTWconst (MOVDconst [x]) [y]) => (FlagConstant [ssa.LogicFlags32(int32(x)&y)])
1292 (CMNconst (MOVDconst [x]) [y]) => (FlagConstant [ssa.AddFlags64(x,y)])
1293 (CMNWconst (MOVDconst [x]) [y]) => (FlagConstant [ssa.AddFlags32(int32(x),y)])
1294
1295 // other known comparisons
1296 (CMPconst (MOVBUreg _) [c]) && 0xff < c => (FlagConstant [ssa.SubFlags64(0,1)])
1297 (CMPconst (MOVHUreg _) [c]) && 0xffff < c => (FlagConstant [ssa.SubFlags64(0,1)])
1298 (CMPconst (MOVWUreg _) [c]) && 0xffffffff < c => (FlagConstant [ssa.SubFlags64(0,1)])
1299 (CMPconst (ANDconst _ [m]) [n]) && 0 <= m && m < n => (FlagConstant [ssa.SubFlags64(0,1)])
1300 (CMPconst (SRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 63 && (1<<uint64(64-c)) <= uint64(n) => (FlagConstant [ssa.SubFlags64(0,1)])
1301 (CMPWconst (MOVBUreg _) [c]) && 0xff < c => (FlagConstant [ssa.SubFlags64(0,1)])
1302 (CMPWconst (MOVHUreg _) [c]) && 0xffff < c => (FlagConstant [ssa.SubFlags64(0,1)])
1303
1304 // absorb flag constants into branches
1305 (EQ (FlagConstant [fc]) yes no) && fc.Eq() => (First yes no)
1306 (EQ (FlagConstant [fc]) yes no) && !fc.Eq() => (First no yes)
1307
1308 (NE (FlagConstant [fc]) yes no) && fc.Ne() => (First yes no)
1309 (NE (FlagConstant [fc]) yes no) && !fc.Ne() => (First no yes)
1310
1311 (LT (FlagConstant [fc]) yes no) && fc.Lt() => (First yes no)
1312 (LT (FlagConstant [fc]) yes no) && !fc.Lt() => (First no yes)
1313
1314 (LE (FlagConstant [fc]) yes no) && fc.Le() => (First yes no)
1315 (LE (FlagConstant [fc]) yes no) && !fc.Le() => (First no yes)
1316
1317 (GT (FlagConstant [fc]) yes no) && fc.Gt() => (First yes no)
1318 (GT (FlagConstant [fc]) yes no) && !fc.Gt() => (First no yes)
1319
1320 (GE (FlagConstant [fc]) yes no) && fc.Ge() => (First yes no)
1321 (GE (FlagConstant [fc]) yes no) && !fc.Ge() => (First no yes)
1322
1323 (ULT (FlagConstant [fc]) yes no) && fc.Ult() => (First yes no)
1324 (ULT (FlagConstant [fc]) yes no) && !fc.Ult() => (First no yes)
1325
1326 (ULE (FlagConstant [fc]) yes no) && fc.Ule() => (First yes no)
1327 (ULE (FlagConstant [fc]) yes no) && !fc.Ule() => (First no yes)
1328
1329 (UGT (FlagConstant [fc]) yes no) && fc.Ugt() => (First yes no)
1330 (UGT (FlagConstant [fc]) yes no) && !fc.Ugt() => (First no yes)
1331
1332 (UGE (FlagConstant [fc]) yes no) && fc.Uge() => (First yes no)
1333 (UGE (FlagConstant [fc]) yes no) && !fc.Uge() => (First no yes)
1334
1335 (LTnoov (FlagConstant [fc]) yes no) && fc.LtNoov() => (First yes no)
1336 (LTnoov (FlagConstant [fc]) yes no) && !fc.LtNoov() => (First no yes)
1337
1338 (LEnoov (FlagConstant [fc]) yes no) && fc.LeNoov() => (First yes no)
1339 (LEnoov (FlagConstant [fc]) yes no) && !fc.LeNoov() => (First no yes)
1340
1341 (GTnoov (FlagConstant [fc]) yes no) && fc.GtNoov() => (First yes no)
1342 (GTnoov (FlagConstant [fc]) yes no) && !fc.GtNoov() => (First no yes)
1343
1344 (GEnoov (FlagConstant [fc]) yes no) && fc.GeNoov() => (First yes no)
1345 (GEnoov (FlagConstant [fc]) yes no) && !fc.GeNoov() => (First no yes)
1346
1347 (Z (MOVDconst [0]) yes no) => (First yes no)
1348 (Z (MOVDconst [c]) yes no) && c != 0 => (First no yes)
1349 (NZ (MOVDconst [0]) yes no) => (First no yes)
1350 (NZ (MOVDconst [c]) yes no) && c != 0 => (First yes no)
1351 (ZW (MOVDconst [c]) yes no) && int32(c) == 0 => (First yes no)
1352 (ZW (MOVDconst [c]) yes no) && int32(c) != 0 => (First no yes)
1353 (NZW (MOVDconst [c]) yes no) && int32(c) == 0 => (First no yes)
1354 (NZW (MOVDconst [c]) yes no) && int32(c) != 0 => (First yes no)
1355
1356 // absorb InvertFlags into branches
1357 (LT (InvertFlags cmp) yes no) => (GT cmp yes no)
1358 (GT (InvertFlags cmp) yes no) => (LT cmp yes no)
1359 (LE (InvertFlags cmp) yes no) => (GE cmp yes no)
1360 (GE (InvertFlags cmp) yes no) => (LE cmp yes no)
1361 (ULT (InvertFlags cmp) yes no) => (UGT cmp yes no)
1362 (UGT (InvertFlags cmp) yes no) => (ULT cmp yes no)
1363 (ULE (InvertFlags cmp) yes no) => (UGE cmp yes no)
1364 (UGE (InvertFlags cmp) yes no) => (ULE cmp yes no)
1365 (EQ (InvertFlags cmp) yes no) => (EQ cmp yes no)
1366 (NE (InvertFlags cmp) yes no) => (NE cmp yes no)
1367 (FLT (InvertFlags cmp) yes no) => (FGT cmp yes no)
1368 (FGT (InvertFlags cmp) yes no) => (FLT cmp yes no)
1369 (FLE (InvertFlags cmp) yes no) => (FGE cmp yes no)
1370 (FGE (InvertFlags cmp) yes no) => (FLE cmp yes no)
1371
1372 // absorb InvertFlags into conditional instructions
1373 (CSEL [cc] x y (InvertFlags cmp)) => (CSEL [arm64Invert(cc)] x y cmp)
1374 (CSEL0 [cc] x (InvertFlags cmp)) => (CSEL0 [arm64Invert(cc)] x cmp)
1375 (FCSELD [cc] x y (InvertFlags cmp)) => (FCSELD [arm64Invert(cc)] x y cmp)
1376 (FCSELS [cc] x y (InvertFlags cmp)) => (FCSELS [arm64Invert(cc)] x y cmp)
1377 (CSETM [cc] (InvertFlags cmp)) => (CSETM [arm64Invert(cc)] cmp)
1378 (CSINC [cc] x y (InvertFlags cmp)) => (CSINC [arm64Invert(cc)] x y cmp)
1379 (CSINV [cc] x y (InvertFlags cmp)) => (CSINV [arm64Invert(cc)] x y cmp)
1380 (CSNEG [cc] x y (InvertFlags cmp)) => (CSNEG [arm64Invert(cc)] x y cmp)
1381
1382 // absorb flag constants into boolean values
1383 (Equal (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Eq())])
1384 (NotEqual (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Ne())])
1385 (LessThan (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Lt())])
1386 (LessThanU (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Ult())])
1387 (LessEqual (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Le())])
1388 (LessEqualU (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Ule())])
1389 (GreaterThan (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Gt())])
1390 (GreaterThanU (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Ugt())])
1391 (GreaterEqual (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Ge())])
1392 (GreaterEqualU (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.Uge())])
1393 (LessThanNoov (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.LtNoov())])
1394 (GreaterEqualNoov (FlagConstant [fc])) => (MOVDconst [ssa.B2i(fc.GeNoov())])
1395
1396 // absorb InvertFlags into boolean values
1397 (Equal (InvertFlags x)) => (Equal x)
1398 (NotEqual (InvertFlags x)) => (NotEqual x)
1399 (LessThan (InvertFlags x)) => (GreaterThan x)
1400 (LessThanU (InvertFlags x)) => (GreaterThanU x)
1401 (GreaterThan (InvertFlags x)) => (LessThan x)
1402 (GreaterThanU (InvertFlags x)) => (LessThanU x)
1403 (LessEqual (InvertFlags x)) => (GreaterEqual x)
1404 (LessEqualU (InvertFlags x)) => (GreaterEqualU x)
1405 (GreaterEqual (InvertFlags x)) => (LessEqual x)
1406 (GreaterEqualU (InvertFlags x)) => (LessEqualU x)
1407 (LessThanF (InvertFlags x)) => (GreaterThanF x)
1408 (LessEqualF (InvertFlags x)) => (GreaterEqualF x)
1409 (GreaterThanF (InvertFlags x)) => (LessThanF x)
1410 (GreaterEqualF (InvertFlags x)) => (LessEqualF x)
1411
1412 (GreaterEqual (CMPconst x [0])) => (XORconst [1] (SRLconst <v.Type> [63] x))
1413 (LessThan (CMPconst x [0])) => (SRLconst [63] x)
1414 (GreaterEqual (CMPWconst x [0])) => (XORconst [1] (UBFX <v.Type> [ssa.ArmBFAuxInt(31,1)] x))
1415 (LessThan (CMPWconst x [0])) => (UBFX [ssa.ArmBFAuxInt(31,1)] x)
1416
1417 // Don't bother extending if we're not using the higher bits.
1418 (MOV(B|BU)reg x) && v.Type.Size() <= 1 => x
1419 (MOV(H|HU)reg x) && v.Type.Size() <= 2 => x
1420 (MOV(W|WU)reg x) && v.Type.Size() <= 4 => x
1421
1422 // omit sign extension
1423 (MOVWreg <t> (ANDconst x [c])) && uint64(c) & uint64(0xffffffff80000000) == 0 => (ANDconst <t> x [c])
1424 (MOVHreg <t> (ANDconst x [c])) && uint64(c) & uint64(0xffffffffffff8000) == 0 => (ANDconst <t> x [c])
1425 (MOVBreg <t> (ANDconst x [c])) && uint64(c) & uint64(0xffffffffffffff80) == 0 => (ANDconst <t> x [c])
1426
1427 // absorb flag constants into conditional instructions
1428 (CSEL [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1429 (CSEL [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => y
1430 (CSEL0 [cc] x flag) && ccARM64Eval(cc, flag) > 0 => x
1431 (CSEL0 [cc] _ flag) && ccARM64Eval(cc, flag) < 0 => (MOVDconst [0])
1432 (CSNEG [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1433 (CSNEG [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => (NEG y)
1434 (CSINV [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1435 (CSINV [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => (MVN y)
1436 (CSINC [cc] x _ flag) && ccARM64Eval(cc, flag) > 0 => x
1437 (CSINC [cc] _ y flag) && ccARM64Eval(cc, flag) < 0 => (ADDconst [1] y)
1438 (CSETM [cc] flag) && ccARM64Eval(cc, flag) > 0 => (MOVDconst [-1])
1439 (CSETM [cc] flag) && ccARM64Eval(cc, flag) < 0 => (MOVDconst [0])
1440
1441 // absorb flags back into boolean CSEL
1442 (CSEL [cc] x y (CMPWconst [0] boolval)) && cc == ssaop.OpARM64NotEqual && arm64CondFlagArg(boolval) != nil =>
1443 (CSEL [boolval.Op] x y arm64CondFlagArg(boolval))
1444 (CSEL [cc] x y (CMPWconst [0] boolval)) && cc == ssaop.OpARM64Equal && arm64CondFlagArg(boolval) != nil =>
1445 (CSEL [arm64Negate(boolval.Op)] x y arm64CondFlagArg(boolval))
1446 (CSEL0 [cc] x (CMPWconst [0] boolval)) && cc == ssaop.OpARM64NotEqual && arm64CondFlagArg(boolval) != nil =>
1447 (CSEL0 [boolval.Op] x arm64CondFlagArg(boolval))
1448 (CSEL0 [cc] x (CMPWconst [0] boolval)) && cc == ssaop.OpARM64Equal && arm64CondFlagArg(boolval) != nil =>
1449 (CSEL0 [arm64Negate(boolval.Op)] x arm64CondFlagArg(boolval))
1450
1451 // absorb shifts into ops
1452 (NEG x:(SLLconst [c] y)) && ssa.ClobberIfDead(x) => (NEGshiftLL [c] y)
1453 (NEG x:(SRLconst [c] y)) && ssa.ClobberIfDead(x) => (NEGshiftRL [c] y)
1454 (NEG x:(SRAconst [c] y)) && ssa.ClobberIfDead(x) => (NEGshiftRA [c] y)
1455 (MVN x:(SLLconst [c] y)) && ssa.ClobberIfDead(x) => (MVNshiftLL [c] y)
1456 (MVN x:(SRLconst [c] y)) && ssa.ClobberIfDead(x) => (MVNshiftRL [c] y)
1457 (MVN x:(SRAconst [c] y)) && ssa.ClobberIfDead(x) => (MVNshiftRA [c] y)
1458 (MVN x:(RORconst [c] y)) && ssa.ClobberIfDead(x) => (MVNshiftRO [c] y)
1459 (ADD x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (ADDshiftLL x0 y [c])
1460 (ADD x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (ADDshiftRL x0 y [c])
1461 (ADD x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (ADDshiftRA x0 y [c])
1462 (SUB x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (SUBshiftLL x0 y [c])
1463 (SUB x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (SUBshiftRL x0 y [c])
1464 (SUB x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (SUBshiftRA x0 y [c])
1465 (AND x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (ANDshiftLL x0 y [c])
1466 (AND x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (ANDshiftRL x0 y [c])
1467 (AND x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (ANDshiftRA x0 y [c])
1468 (AND x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (ANDshiftRO x0 y [c])
1469 (OR x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (ORshiftLL x0 y [c]) // useful for combined load
1470 (OR x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (ORshiftRL x0 y [c])
1471 (OR x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (ORshiftRA x0 y [c])
1472 (OR x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (ORshiftRO x0 y [c])
1473 (XOR x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (XORshiftLL x0 y [c])
1474 (XOR x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (XORshiftRL x0 y [c])
1475 (XOR x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (XORshiftRA x0 y [c])
1476 (XOR x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (XORshiftRO x0 y [c])
1477 (BIC x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (BICshiftLL x0 y [c])
1478 (BIC x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (BICshiftRL x0 y [c])
1479 (BIC x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (BICshiftRA x0 y [c])
1480 (BIC x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (BICshiftRO x0 y [c])
1481 (ORN x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (ORNshiftLL x0 y [c])
1482 (ORN x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (ORNshiftRL x0 y [c])
1483 (ORN x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (ORNshiftRA x0 y [c])
1484 (ORN x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (ORNshiftRO x0 y [c])
1485 (EON x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (EONshiftLL x0 y [c])
1486 (EON x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (EONshiftRL x0 y [c])
1487 (EON x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (EONshiftRA x0 y [c])
1488 (EON x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (EONshiftRO x0 y [c])
1489 (CMP x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (CMPshiftLL x0 y [c])
1490 (CMP x0:(SLLconst [c] y) x1) && ssa.ClobberIfDead(x0) => (InvertFlags (CMPshiftLL x1 y [c]))
1491 (CMP x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (CMPshiftRL x0 y [c])
1492 (CMP x0:(SRLconst [c] y) x1) && ssa.ClobberIfDead(x0) => (InvertFlags (CMPshiftRL x1 y [c]))
1493 (CMP x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (CMPshiftRA x0 y [c])
1494 (CMP x0:(SRAconst [c] y) x1) && ssa.ClobberIfDead(x0) => (InvertFlags (CMPshiftRA x1 y [c]))
1495 (CMN x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (CMNshiftLL x0 y [c])
1496 (CMN x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (CMNshiftRL x0 y [c])
1497 (CMN x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (CMNshiftRA x0 y [c])
1498 (TST x0 x1:(SLLconst [c] y)) && ssa.ClobberIfDead(x1) => (TSTshiftLL x0 y [c])
1499 (TST x0 x1:(SRLconst [c] y)) && ssa.ClobberIfDead(x1) => (TSTshiftRL x0 y [c])
1500 (TST x0 x1:(SRAconst [c] y)) && ssa.ClobberIfDead(x1) => (TSTshiftRA x0 y [c])
1501 (TST x0 x1:(RORconst [c] y)) && ssa.ClobberIfDead(x1) => (TSTshiftRO x0 y [c])
1502
1503 // prefer *const ops to *shift ops
1504 (ADDshiftLL (MOVDconst [c]) x [d]) => (ADDconst [c] (SLLconst <x.Type> x [d]))
1505 (ADDshiftRL (MOVDconst [c]) x [d]) => (ADDconst [c] (SRLconst <x.Type> x [d]))
1506 (ADDshiftRA (MOVDconst [c]) x [d]) => (ADDconst [c] (SRAconst <x.Type> x [d]))
1507 (ANDshiftLL (MOVDconst [c]) x [d]) => (ANDconst [c] (SLLconst <x.Type> x [d]))
1508 (ANDshiftRL (MOVDconst [c]) x [d]) => (ANDconst [c] (SRLconst <x.Type> x [d]))
1509 (ANDshiftRA (MOVDconst [c]) x [d]) => (ANDconst [c] (SRAconst <x.Type> x [d]))
1510 (ANDshiftRO (MOVDconst [c]) x [d]) => (ANDconst [c] (RORconst <x.Type> x [d]))
1511 (ORshiftLL (MOVDconst [c]) x [d]) => (ORconst [c] (SLLconst <x.Type> x [d]))
1512 (ORshiftRL (MOVDconst [c]) x [d]) => (ORconst [c] (SRLconst <x.Type> x [d]))
1513 (ORshiftRA (MOVDconst [c]) x [d]) => (ORconst [c] (SRAconst <x.Type> x [d]))
1514 (ORshiftRO (MOVDconst [c]) x [d]) => (ORconst [c] (RORconst <x.Type> x [d]))
1515 (XORshiftLL (MOVDconst [c]) x [d]) => (XORconst [c] (SLLconst <x.Type> x [d]))
1516 (XORshiftRL (MOVDconst [c]) x [d]) => (XORconst [c] (SRLconst <x.Type> x [d]))
1517 (XORshiftRA (MOVDconst [c]) x [d]) => (XORconst [c] (SRAconst <x.Type> x [d]))
1518 (XORshiftRO (MOVDconst [c]) x [d]) => (XORconst [c] (RORconst <x.Type> x [d]))
1519 (CMPshiftLL (MOVDconst [c]) x [d]) => (InvertFlags (CMPconst [c] (SLLconst <x.Type> x [d])))
1520 (CMPshiftRL (MOVDconst [c]) x [d]) => (InvertFlags (CMPconst [c] (SRLconst <x.Type> x [d])))
1521 (CMPshiftRA (MOVDconst [c]) x [d]) => (InvertFlags (CMPconst [c] (SRAconst <x.Type> x [d])))
1522 (CMNshiftLL (MOVDconst [c]) x [d]) => (CMNconst [c] (SLLconst <x.Type> x [d]))
1523 (CMNshiftRL (MOVDconst [c]) x [d]) => (CMNconst [c] (SRLconst <x.Type> x [d]))
1524 (CMNshiftRA (MOVDconst [c]) x [d]) => (CMNconst [c] (SRAconst <x.Type> x [d]))
1525 (TSTshiftLL (MOVDconst [c]) x [d]) => (TSTconst [c] (SLLconst <x.Type> x [d]))
1526 (TSTshiftRL (MOVDconst [c]) x [d]) => (TSTconst [c] (SRLconst <x.Type> x [d]))
1527 (TSTshiftRA (MOVDconst [c]) x [d]) => (TSTconst [c] (SRAconst <x.Type> x [d]))
1528 (TSTshiftRO (MOVDconst [c]) x [d]) => (TSTconst [c] (RORconst <x.Type> x [d]))
1529
1530 // constant folding in *shift ops
1531 (MVNshiftLL (MOVDconst [c]) [d]) => (MOVDconst [^int64(uint64(c)<<uint64(d))])
1532 (MVNshiftRL (MOVDconst [c]) [d]) => (MOVDconst [^int64(uint64(c)>>uint64(d))])
1533 (MVNshiftRA (MOVDconst [c]) [d]) => (MOVDconst [^(c>>uint64(d))])
1534 (MVNshiftRO (MOVDconst [c]) [d]) => (MOVDconst [^rotateRight64(c, d)])
1535 (NEGshiftLL (MOVDconst [c]) [d]) => (MOVDconst [-int64(uint64(c)<<uint64(d))])
1536 (NEGshiftRL (MOVDconst [c]) [d]) => (MOVDconst [-int64(uint64(c)>>uint64(d))])
1537 (NEGshiftRA (MOVDconst [c]) [d]) => (MOVDconst [-(c>>uint64(d))])
1538 (ADDshiftLL x (MOVDconst [c]) [d]) => (ADDconst x [int64(uint64(c)<<uint64(d))])
1539 (ADDshiftRL x (MOVDconst [c]) [d]) => (ADDconst x [int64(uint64(c)>>uint64(d))])
1540 (ADDshiftRA x (MOVDconst [c]) [d]) => (ADDconst x [c>>uint64(d)])
1541 (SUBshiftLL x (MOVDconst [c]) [d]) => (SUBconst x [int64(uint64(c)<<uint64(d))])
1542 (SUBshiftRL x (MOVDconst [c]) [d]) => (SUBconst x [int64(uint64(c)>>uint64(d))])
1543 (SUBshiftRA x (MOVDconst [c]) [d]) => (SUBconst x [c>>uint64(d)])
1544 (ANDshiftLL x (MOVDconst [c]) [d]) => (ANDconst x [int64(uint64(c)<<uint64(d))])
1545 (ANDshiftRL x (MOVDconst [c]) [d]) => (ANDconst x [int64(uint64(c)>>uint64(d))])
1546 (ANDshiftRA x (MOVDconst [c]) [d]) => (ANDconst x [c>>uint64(d)])
1547 (ANDshiftRO x (MOVDconst [c]) [d]) => (ANDconst x [rotateRight64(c, d)])
1548 (ORshiftLL x (MOVDconst [c]) [d]) => (ORconst x [int64(uint64(c)<<uint64(d))])
1549 (ORshiftRL x (MOVDconst [c]) [d]) => (ORconst x [int64(uint64(c)>>uint64(d))])
1550 (ORshiftRA x (MOVDconst [c]) [d]) => (ORconst x [c>>uint64(d)])
1551 (ORshiftRO x (MOVDconst [c]) [d]) => (ORconst x [rotateRight64(c, d)])
1552 (XORshiftLL x (MOVDconst [c]) [d]) => (XORconst x [int64(uint64(c)<<uint64(d))])
1553 (XORshiftRL x (MOVDconst [c]) [d]) => (XORconst x [int64(uint64(c)>>uint64(d))])
1554 (XORshiftRA x (MOVDconst [c]) [d]) => (XORconst x [c>>uint64(d)])
1555 (XORshiftRO x (MOVDconst [c]) [d]) => (XORconst x [rotateRight64(c, d)])
1556 (BICshiftLL x (MOVDconst [c]) [d]) => (ANDconst x [^int64(uint64(c)<<uint64(d))])
1557 (BICshiftRL x (MOVDconst [c]) [d]) => (ANDconst x [^int64(uint64(c)>>uint64(d))])
1558 (BICshiftRA x (MOVDconst [c]) [d]) => (ANDconst x [^(c>>uint64(d))])
1559 (BICshiftRO x (MOVDconst [c]) [d]) => (ANDconst x [^rotateRight64(c, d)])
1560 (ORNshiftLL x (MOVDconst [c]) [d]) => (ORconst x [^int64(uint64(c)<<uint64(d))])
1561 (ORNshiftRL x (MOVDconst [c]) [d]) => (ORconst x [^int64(uint64(c)>>uint64(d))])
1562 (ORNshiftRA x (MOVDconst [c]) [d]) => (ORconst x [^(c>>uint64(d))])
1563 (ORNshiftRO x (MOVDconst [c]) [d]) => (ORconst x [^rotateRight64(c, d)])
1564 (EONshiftLL x (MOVDconst [c]) [d]) => (XORconst x [^int64(uint64(c)<<uint64(d))])
1565 (EONshiftRL x (MOVDconst [c]) [d]) => (XORconst x [^int64(uint64(c)>>uint64(d))])
1566 (EONshiftRA x (MOVDconst [c]) [d]) => (XORconst x [^(c>>uint64(d))])
1567 (EONshiftRO x (MOVDconst [c]) [d]) => (XORconst x [^rotateRight64(c, d)])
1568 (CMPshiftLL x (MOVDconst [c]) [d]) => (CMPconst x [int64(uint64(c)<<uint64(d))])
1569 (CMPshiftRL x (MOVDconst [c]) [d]) => (CMPconst x [int64(uint64(c)>>uint64(d))])
1570 (CMPshiftRA x (MOVDconst [c]) [d]) => (CMPconst x [c>>uint64(d)])
1571 (CMNshiftLL x (MOVDconst [c]) [d]) => (CMNconst x [int64(uint64(c)<<uint64(d))])
1572 (CMNshiftRL x (MOVDconst [c]) [d]) => (CMNconst x [int64(uint64(c)>>uint64(d))])
1573 (CMNshiftRA x (MOVDconst [c]) [d]) => (CMNconst x [c>>uint64(d)])
1574 (TSTshiftLL x (MOVDconst [c]) [d]) => (TSTconst x [int64(uint64(c)<<uint64(d))])
1575 (TSTshiftRL x (MOVDconst [c]) [d]) => (TSTconst x [int64(uint64(c)>>uint64(d))])
1576 (TSTshiftRA x (MOVDconst [c]) [d]) => (TSTconst x [c>>uint64(d)])
1577 (TSTshiftRO x (MOVDconst [c]) [d]) => (TSTconst x [rotateRight64(c, d)])
1578
1579 // simplification with *shift ops
1580 (SUBshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [0])
1581 (SUBshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [0])
1582 (SUBshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [0])
1583 (ANDshiftLL y:(SLLconst x [c]) x [c]) => y
1584 (ANDshiftRL y:(SRLconst x [c]) x [c]) => y
1585 (ANDshiftRA y:(SRAconst x [c]) x [c]) => y
1586 (ANDshiftRO y:(RORconst x [c]) x [c]) => y
1587 (ORshiftLL y:(SLLconst x [c]) x [c]) => y
1588 (ORshiftRL y:(SRLconst x [c]) x [c]) => y
1589 (ORshiftRA y:(SRAconst x [c]) x [c]) => y
1590 (ORshiftRO y:(RORconst x [c]) x [c]) => y
1591 (XORshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [0])
1592 (XORshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [0])
1593 (XORshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [0])
1594 (XORshiftRO (RORconst x [c]) x [c]) => (MOVDconst [0])
1595 (BICshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [0])
1596 (BICshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [0])
1597 (BICshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [0])
1598 (BICshiftRO (RORconst x [c]) x [c]) => (MOVDconst [0])
1599 (EONshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [-1])
1600 (EONshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [-1])
1601 (EONshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [-1])
1602 (EONshiftRO (RORconst x [c]) x [c]) => (MOVDconst [-1])
1603 (ORNshiftLL (SLLconst x [c]) x [c]) => (MOVDconst [-1])
1604 (ORNshiftRL (SRLconst x [c]) x [c]) => (MOVDconst [-1])
1605 (ORNshiftRA (SRAconst x [c]) x [c]) => (MOVDconst [-1])
1606 (ORNshiftRO (RORconst x [c]) x [c]) => (MOVDconst [-1])
1607
1608 // rev16w | rev16
1609 // ((x>>8) | (x<<8)) => (REV16W x), the type of x is uint16, "|" can also be "^" or "+".
1610 ((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (UBFX <typ.UInt16> [ssa.ArmBFAuxInt(8, 8)] x) x) => (REV16W x)
1611
1612 // ((x & 0xff00ff00)>>8) | ((x & 0x00ff00ff)<<8), "|" can also be "^" or "+".
1613 ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (UBFX [ssa.ArmBFAuxInt(8, 24)] (ANDconst [c1] x)) (ANDconst [c2] x))
1614 && uint32(c1) == 0xff00ff00 && uint32(c2) == 0x00ff00ff
1615 => (REV16W x)
1616
1617 // ((x & 0xff00ff00ff00ff00)>>8) | ((x & 0x00ff00ff00ff00ff)<<8), "|" can also be "^" or "+".
1618 ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (SRLconst [8] (ANDconst [c1] x)) (ANDconst [c2] x))
1619 && (uint64(c1) == 0xff00ff00ff00ff00 && uint64(c2) == 0x00ff00ff00ff00ff)
1620 => (REV16 x)
1621
1622 // ((x & 0xff00ff00)>>8) | ((x & 0x00ff00ff)<<8), "|" can also be "^" or "+".
1623 ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (SRLconst [8] (ANDconst [c1] x)) (ANDconst [c2] x))
1624 && (uint64(c1) == 0xff00ff00 && uint64(c2) == 0x00ff00ff)
1625 => (REV16 (ANDconst <x.Type> [0xffffffff] x))
1626
1627 (REV16 (MOVWUreg x)) => (REV16W x)
1628
1629 // Extract from reg pair
1630 (ADDshiftLL [c] (SRLconst x [64-c]) x2) => (EXTRconst [64-c] x2 x)
1631 ( ORshiftLL [c] (SRLconst x [64-c]) x2) => (EXTRconst [64-c] x2 x)
1632 (XORshiftLL [c] (SRLconst x [64-c]) x2) => (EXTRconst [64-c] x2 x)
1633
1634 (ADDshiftLL <t> [c] (UBFX [bfc] x) x2) && c > 0 && c < 32 && t.Size() == 4 && bfc == ssa.ArmBFAuxInt(32-c, c)
1635 => (EXTRWconst [32-c] x2 x)
1636 ( ORshiftLL <t> [c] (UBFX [bfc] x) x2) && c > 0 && c < 32 && t.Size() == 4 && bfc == ssa.ArmBFAuxInt(32-c, c)
1637 => (EXTRWconst [32-c] x2 x)
1638 (XORshiftLL <t> [c] (UBFX [bfc] x) x2) && c > 0 && c < 32 && t.Size() == 4 && bfc == ssa.ArmBFAuxInt(32-c, c)
1639 => (EXTRWconst [32-c] x2 x)
1640
1641 // Rewrite special pairs of shifts to AND.
1642 // On ARM64 the bitmask can fit into an instruction.
1643 (SRLconst [c] (SLLconst [c] x)) && 0 < c && c < 64 => (ANDconst [1<<uint(64-c)-1] x) // mask out high bits
1644 (SLLconst [c] (SRLconst [c] x)) && 0 < c && c < 64 => (ANDconst [^(1<<uint(c)-1)] x) // mask out low bits
1645
1646 // Special case setting bit as 1. An example is math.Copysign(c,-1)
1647 (ORconst [c1] (ANDconst [c2] x)) && c2|c1 == ^0 => (ORconst [c1] x)
1648
1649 // If the shift amount is larger than the datasize(32, 16, 8), we can optimize to constant 0.
1650 (MOVWUreg (SLLconst [lc] x)) && lc >= 32 => (MOVDconst [0])
1651 (MOVHUreg (SLLconst [lc] x)) && lc >= 16 => (MOVDconst [0])
1652 (MOVBUreg (SLLconst [lc] x)) && lc >= 8 => (MOVDconst [0])
1653
1654 // After zero extension, the upper (64-datasize(32|16|8)) bits are zero, we can optimiza to constant 0.
1655 (SRLconst [rc] (MOVWUreg x)) && rc >= 32 => (MOVDconst [0])
1656 (SRLconst [rc] (MOVHUreg x)) && rc >= 16 => (MOVDconst [0])
1657 (SRLconst [rc] (MOVBUreg x)) && rc >= 8 => (MOVDconst [0])
1658
1659 // Special cases for slice operations
1660 (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])
1661 (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])
1662
1663 // bitfield ops
1664
1665 // sbfiz
1666 // (x << lc) >> rc
1667 (SRAconst [rc] (SLLconst [lc] x)) && lc > rc => (SBFIZ [ssa.ArmBFAuxInt(lc-rc, 64-lc)] x)
1668 // int64(x << lc)
1669 (MOVWreg (SLLconst [lc] x)) && lc < 32 => (SBFIZ [ssa.ArmBFAuxInt(lc, 32-lc)] x)
1670 (MOVHreg (SLLconst [lc] x)) && lc < 16 => (SBFIZ [ssa.ArmBFAuxInt(lc, 16-lc)] x)
1671 (MOVBreg (SLLconst [lc] x)) && lc < 8 => (SBFIZ [ssa.ArmBFAuxInt(lc, 8-lc)] x)
1672 // int64(x) << lc
1673 (SLLconst [lc] (MOVWreg x)) => (SBFIZ [ssa.ArmBFAuxInt(lc, min(32, 64-lc))] x)
1674 (SLLconst [lc] (MOVHreg x)) => (SBFIZ [ssa.ArmBFAuxInt(lc, min(16, 64-lc))] x)
1675 (SLLconst [lc] (MOVBreg x)) => (SBFIZ [ssa.ArmBFAuxInt(lc, min(8, 64-lc))] x)
1676
1677 // sbfx
1678 // (x << lc) >> rc
1679 (SRAconst [rc] (SLLconst [lc] x)) && lc <= rc => (SBFX [ssa.ArmBFAuxInt(rc-lc, 64-rc)] x)
1680 // int64(x) >> rc
1681 (SRAconst [rc] (MOVWreg x)) && rc < 32 => (SBFX [ssa.ArmBFAuxInt(rc, 32-rc)] x)
1682 (SRAconst [rc] (MOVHreg x)) && rc < 16 => (SBFX [ssa.ArmBFAuxInt(rc, 16-rc)] x)
1683 (SRAconst [rc] (MOVBreg x)) && rc < 8 => (SBFX [ssa.ArmBFAuxInt(rc, 8-rc)] x)
1684 // merge sbfx and sign-extension into sbfx
1685 (MOVWreg (SBFX [bfc] x)) && bfc.Width() <= 32 => (SBFX [bfc] x)
1686 (MOVHreg (SBFX [bfc] x)) && bfc.Width() <= 16 => (SBFX [bfc] x)
1687 (MOVBreg (SBFX [bfc] x)) && bfc.Width() <= 8 => (SBFX [bfc] x)
1688
1689 // sbfiz/sbfx combinations: merge shifts into bitfield ops
1690 (SRAconst [sc] (SBFIZ [bfc] x)) && sc < bfc.Lsb()
1691 => (SBFIZ [ssa.ArmBFAuxInt(bfc.Lsb()-sc, bfc.Width())] x)
1692 (SRAconst [sc] (SBFIZ [bfc] x)) && sc >= bfc.Lsb()
1693 && sc < bfc.Lsb()+bfc.Width()
1694 => (SBFX [ssa.ArmBFAuxInt(sc-bfc.Lsb(), bfc.Lsb()+bfc.Width()-sc)] x)
1695 (SBFX [bfc] s:(SLLconst [sc] x))
1696 && s.Uses == 1
1697 && sc <= bfc.Lsb()
1698 => (SBFX [ssa.ArmBFAuxInt(bfc.Lsb() - sc, bfc.Width())] x)
1699 (SBFX [bfc] s:(SLLconst [sc] x))
1700 && s.Uses == 1
1701 && sc > bfc.Lsb()
1702 && sc < bfc.Lsb()+bfc.Width()
1703 => (SBFIZ [ssa.ArmBFAuxInt(sc - bfc.Lsb(), bfc.Width() - (sc-bfc.Lsb()))] x)
1704
1705 // ubfiz
1706 // (x << lc) >> rc
1707 (SRLconst [rc] (SLLconst [lc] x)) && lc > rc => (UBFIZ [ssa.ArmBFAuxInt(lc-rc, 64-lc)] x)
1708 // uint64(x) << lc
1709 (SLLconst [lc] (MOVWUreg x)) => (UBFIZ [ssa.ArmBFAuxInt(lc, min(32, 64-lc))] x)
1710 (SLLconst [lc] (MOVHUreg x)) => (UBFIZ [ssa.ArmBFAuxInt(lc, min(16, 64-lc))] x)
1711 (SLLconst [lc] (MOVBUreg x)) => (UBFIZ [ssa.ArmBFAuxInt(lc, min(8, 64-lc))] x)
1712 // uint64(x << lc)
1713 (MOVWUreg (SLLconst [lc] x)) && lc < 32 => (UBFIZ [ssa.ArmBFAuxInt(lc, 32-lc)] x)
1714 (MOVHUreg (SLLconst [lc] x)) && lc < 16 => (UBFIZ [ssa.ArmBFAuxInt(lc, 16-lc)] x)
1715 (MOVBUreg (SLLconst [lc] x)) && lc < 8 => (UBFIZ [ssa.ArmBFAuxInt(lc, 8-lc)] x)
1716
1717 // merge ANDconst into ubfiz
1718 // (x & ac) << sc
1719 (SLLconst [sc] (ANDconst [ac] x)) && isARM64BFMask(sc, ac, 0)
1720 => (UBFIZ [ssa.ArmBFAuxInt(sc, arm64BFWidth(ac, 0))] x)
1721 // (x << sc) & ac
1722 (ANDconst [ac] (SLLconst [sc] x)) && isARM64BFMask(sc, ac, sc)
1723 => (UBFIZ [ssa.ArmBFAuxInt(sc, arm64BFWidth(ac, sc))] x)
1724
1725 // ubfx
1726 // (x << lc) >> rc
1727 (SRLconst [rc] (SLLconst [lc] x)) && lc < rc => (UBFX [ssa.ArmBFAuxInt(rc-lc, 64-rc)] x)
1728 // uint64(x) >> rc
1729 (SRLconst [rc] (MOVWUreg x)) && rc < 32 => (UBFX [ssa.ArmBFAuxInt(rc, 32-rc)] x)
1730 (SRLconst [rc] (MOVHUreg x)) && rc < 16 => (UBFX [ssa.ArmBFAuxInt(rc, 16-rc)] x)
1731 (SRLconst [rc] (MOVBUreg x)) && rc < 8 => (UBFX [ssa.ArmBFAuxInt(rc, 8-rc)] x)
1732 // uint64(x >> rc)
1733 (MOVWUreg (SRLconst [rc] x)) && rc < 32 => (UBFX [ssa.ArmBFAuxInt(rc, 32)] x)
1734 (MOVHUreg (SRLconst [rc] x)) && rc < 16 => (UBFX [ssa.ArmBFAuxInt(rc, 16)] x)
1735 (MOVBUreg (SRLconst [rc] x)) && rc < 8 => (UBFX [ssa.ArmBFAuxInt(rc, 8)] x)
1736 // merge ANDconst into ubfx
1737 // (x >> sc) & ac
1738 (ANDconst [ac] (SRLconst [sc] x)) && isARM64BFMask(sc, ac, 0)
1739 => (UBFX [ssa.ArmBFAuxInt(sc, arm64BFWidth(ac, 0))] x)
1740 // (x & ac) >> sc
1741 (SRLconst [sc] (ANDconst [ac] x)) && isARM64BFMask(sc, ac, sc)
1742 => (UBFX [ssa.ArmBFAuxInt(sc, arm64BFWidth(ac, sc))] x)
1743 // merge ANDconst and ubfx into ubfx
1744 (ANDconst [c] (UBFX [bfc] x)) && isARM64BFMask(0, c, 0) =>
1745 (UBFX [ssa.ArmBFAuxInt(bfc.Lsb(), min(bfc.Width(), arm64BFWidth(c, 0)))] x)
1746 (UBFX [bfc] (ANDconst [c] x)) && isARM64BFMask(0, c, 0) && bfc.Lsb() + bfc.Width() <= arm64BFWidth(c, 0) =>
1747 (UBFX [bfc] x)
1748 // merge ubfx and zero-extension into ubfx
1749 (MOVWUreg (UBFX [bfc] x)) && bfc.Width() <= 32 => (UBFX [bfc] x)
1750 (MOVHUreg (UBFX [bfc] x)) && bfc.Width() <= 16 => (UBFX [bfc] x)
1751 (MOVBUreg (UBFX [bfc] x)) && bfc.Width() <= 8 => (UBFX [bfc] x)
1752
1753 // Extracting bits from across a zero-extension boundary.
1754 (UBFX [bfc] e:(MOVWUreg x))
1755 && e.Uses == 1
1756 && bfc.Lsb() < 32
1757 => (UBFX [ssa.ArmBFAuxInt(bfc.Lsb(), min(bfc.Width(), 32-bfc.Lsb()))] x)
1758 (UBFX [bfc] e:(MOVHUreg x))
1759 && e.Uses == 1
1760 && bfc.Lsb() < 16
1761 => (UBFX [ssa.ArmBFAuxInt(bfc.Lsb(), min(bfc.Width(), 16-bfc.Lsb()))] x)
1762 (UBFX [bfc] e:(MOVBUreg x))
1763 && e.Uses == 1
1764 && bfc.Lsb() < 8
1765 => (UBFX [ssa.ArmBFAuxInt(bfc.Lsb(), min(bfc.Width(), 8-bfc.Lsb()))] x)
1766
1767 // ubfiz/ubfx combinations: merge shifts into bitfield ops
1768 (SRLconst [sc] (UBFX [bfc] x)) && sc < bfc.Width()
1769 => (UBFX [ssa.ArmBFAuxInt(bfc.Lsb()+sc, bfc.Width()-sc)] x)
1770 (UBFX [bfc] (SRLconst [sc] x)) && sc+bfc.Width()+bfc.Lsb() < 64
1771 => (UBFX [ssa.ArmBFAuxInt(bfc.Lsb()+sc, bfc.Width())] x)
1772 (SLLconst [sc] (UBFIZ [bfc] x)) && sc+bfc.Width()+bfc.Lsb() < 64
1773 => (UBFIZ [ssa.ArmBFAuxInt(bfc.Lsb()+sc, bfc.Width())] x)
1774 (UBFIZ [bfc] (SLLconst [sc] x)) && sc < bfc.Width()
1775 => (UBFIZ [ssa.ArmBFAuxInt(bfc.Lsb()+sc, bfc.Width()-sc)] x)
1776 // ((x << c1) >> c2) >> c3
1777 (SRLconst [sc] (UBFIZ [bfc] x)) && sc == bfc.Lsb()
1778 => (ANDconst [1<<uint(bfc.Width())-1] x)
1779 (SRLconst [sc] (UBFIZ [bfc] x)) && sc < bfc.Lsb()
1780 => (UBFIZ [ssa.ArmBFAuxInt(bfc.Lsb()-sc, bfc.Width())] x)
1781 (SRLconst [sc] (UBFIZ [bfc] x)) && sc > bfc.Lsb()
1782 && sc < bfc.Lsb()+bfc.Width()
1783 => (UBFX [ssa.ArmBFAuxInt(sc-bfc.Lsb(), bfc.Lsb()+bfc.Width()-sc)] x)
1784 // ((x << c1) << c2) >> c3
1785 (UBFX [bfc] (SLLconst [sc] x)) && sc == bfc.Lsb()
1786 => (ANDconst [1<<uint(bfc.Width())-1] x)
1787 (UBFX [bfc] (SLLconst [sc] x)) && sc < bfc.Lsb()
1788 => (UBFX [ssa.ArmBFAuxInt(bfc.Lsb()-sc, bfc.Width())] x)
1789 (UBFX [bfc] (SLLconst [sc] x)) && sc > bfc.Lsb()
1790 && sc < bfc.Lsb()+bfc.Width()
1791 => (UBFIZ [ssa.ArmBFAuxInt(sc-bfc.Lsb(), bfc.Lsb()+bfc.Width()-sc)] x)
1792
1793 // bfi
1794 (OR (UBFIZ [bfc] x) (ANDconst [ac] y))
1795 && ac == ^((1<<uint(bfc.Width())-1) << uint(bfc.Lsb()))
1796 => (BFI [bfc] y x)
1797 (ORshiftLL [s] (ANDconst [xc] x) (ANDconst [yc] y))
1798 && xc == ^(yc << s) // opposite masks
1799 && yc & (yc+1) == 0 // power of 2 minus 1
1800 && yc > 0 // not 0, not all 64 bits (there are better rewrites in that case)
1801 && s+ssa.Log64(yc+1) <= 64 // shifted mask doesn't overflow
1802 => (BFI [ssa.ArmBFAuxInt(s, ssa.Log64(yc+1))] x y)
1803 (ORshiftRL [rc] (ANDconst [ac] x) (SLLconst [lc] y))
1804 && lc > rc && ac == ^((1<<uint(64-lc)-1) << uint64(lc-rc))
1805 => (BFI [ssa.ArmBFAuxInt(lc-rc, 64-lc)] x y)
1806 // bfxil
1807 (OR (UBFX [bfc] x) (ANDconst [ac] y)) && ac == ^(1<<uint(bfc.Width())-1)
1808 => (BFXIL [bfc] y x)
1809 (ORshiftLL [sc] (UBFX [bfc] x) (SRLconst [sc] y)) && sc == bfc.Width()
1810 => (BFXIL [bfc] y x)
1811 (ORshiftRL [rc] (ANDconst [ac] y) (SLLconst [lc] x)) && lc < rc && ac == ^((1<<uint(64-rc)-1))
1812 => (BFXIL [ssa.ArmBFAuxInt(rc-lc, 64-rc)] y x)
1813
1814 // FP simplification
1815 (FNEGS (FMULS x y)) => (FNMULS x y)
1816 (FNEGD (FMULD x y)) => (FNMULD x y)
1817 (FMULS (FNEGS x) y) => (FNMULS x y)
1818 (FMULD (FNEGD x) y) => (FNMULD x y)
1819 (FNEGS (FNMULS x y)) => (FMULS x y)
1820 (FNEGD (FNMULD x y)) => (FMULD x y)
1821 (FNMULS (FNEGS x) y) => (FMULS x y)
1822 (FNMULD (FNEGD x) y) => (FMULD x y)
1823
1824 (FADDS a (FMULS x y)) && a.Block.Func.UseFMA(v) => (FMADDS a x y)
1825 (FADDD a (FMULD x y)) && a.Block.Func.UseFMA(v) => (FMADDD a x y)
1826 (FSUBS a (FMULS x y)) && a.Block.Func.UseFMA(v) => (FMSUBS a x y)
1827 (FSUBD a (FMULD x y)) && a.Block.Func.UseFMA(v) => (FMSUBD a x y)
1828 (FSUBS (FMULS x y) a) && a.Block.Func.UseFMA(v) => (FNMSUBS a x y)
1829 (FSUBD (FMULD x y) a) && a.Block.Func.UseFMA(v) => (FNMSUBD a x y)
1830 (FADDS a (FNMULS x y)) && a.Block.Func.UseFMA(v) => (FMSUBS a x y)
1831 (FADDD a (FNMULD x y)) && a.Block.Func.UseFMA(v) => (FMSUBD a x y)
1832 (FSUBS a (FNMULS x y)) && a.Block.Func.UseFMA(v) => (FMADDS a x y)
1833 (FSUBD a (FNMULD x y)) && a.Block.Func.UseFMA(v) => (FMADDD a x y)
1834 (FSUBS (FNMULS x y) a) && a.Block.Func.UseFMA(v) => (FNMADDS a x y)
1835 (FSUBD (FNMULD x y) a) && a.Block.Func.UseFMA(v) => (FNMADDD a x y)
1836
1837 (MOVBUload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(ssa.Read8(sym, int64(off)))])
1838 (MOVHUload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(ssa.Read16(sym, int64(off), config.Ctxt.Arch.ByteOrder))])
1839 (MOVWUload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(ssa.Read32(sym, int64(off), config.Ctxt.Arch.ByteOrder))])
1840 (MOVDload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(ssa.Read64(sym, int64(off), config.Ctxt.Arch.ByteOrder))])
1841 (MOVBload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(int8(ssa.Read8(sym, int64(off))))])
1842 (MOVHload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(int16(ssa.Read16(sym, int64(off), config.Ctxt.Arch.ByteOrder)))])
1843 (MOVWload [off] {sym} (SB) _) && ssa.SymIsRO(sym) => (MOVDconst [int64(int32(ssa.Read32(sym, int64(off), config.Ctxt.Arch.ByteOrder)))])
1844
1845 // Prefetch instructions (aux is option: 0 - PLDL1KEEP; 1 - PLDL1STRM)
1846 (PrefetchCache addr mem) => (PRFM [0] addr mem)
1847 (PrefetchCacheStreamed addr mem) => (PRFM [1] addr mem)
1848
1849 // Arch-specific inlining for small or disjoint runtime.memmove
1850 (SelectN [0] call:(CALLstatic {sym} s1:(MOVDstore _ (MOVDconst [sz]) s2:(MOVDstore _ src s3:(MOVDstore {t} _ dst mem)))))
1851 && sz >= 0
1852 && ssa.IsSameCall(sym, "runtime.memmove")
1853 && s1.Uses == 1 && s2.Uses == 1 && s3.Uses == 1
1854 && ssa.IsInlinableMemmove(dst, src, sz, config)
1855 && ssa.Clobber(s1, s2, s3, call)
1856 => (Move [sz] dst src mem)
1857
1858 // Match post-lowering calls, register version.
1859 (SelectN [0] call:(CALLstatic {sym} dst src (MOVDconst [sz]) mem))
1860 && sz >= 0
1861 && ssa.IsSameCall(sym, "runtime.memmove")
1862 && call.Uses == 1
1863 && ssa.IsInlinableMemmove(dst, src, sz, config)
1864 && ssa.Clobber(call)
1865 => (Move [sz] dst src mem)
1866
1867 (REV (REV p)) => p
1868 (REVW (REVW p)) => (MOVWUreg p)
1869
1870 // internal/runtime/math.MulUintptr intrinsics
1871
1872 (Select0 (Mul64uover x y)) => (MUL x y)
1873 (Select1 (Mul64uover x y)) => (NotEqual (CMPconst (UMULH <typ.UInt64> x y) [0]))
1874
1875 // 32 mul 32 -> 64
1876 (MUL r:(MOVWUreg x) s:(MOVWUreg y)) && r.Uses == 1 && s.Uses == 1 => (UMULL x y)
1877 (MUL r:(MOVWreg x) s:(MOVWreg y)) && r.Uses == 1 && s.Uses == 1 => (MULL x y)
1878
1879 // ANDconst to zext
1880 (ANDconst [0xffffffff] x) => (MOVWUreg x)
1881 (ANDconst [0xffff ] x) => (MOVHUreg x)
1882 (ANDconst [0xff ] x) => (MOVBUreg x)
1883
1884 // SIMD zero
1885 (ZeroSIMD <t>) && t.Size() == 16 => (VMOVI16B [0] <t>)
1886
1887 // Neon peephole
1888 (VDUP(S|D)bcast [i] (VMOV(S|D)ins0 [j] _ x)) && i == j => (VDUP(S|D)bcast [0] x)
1889 (VDUP(B|H|S|D)bcast [i] (VMOV(B|H|S|D)ins [j] _ x)) && i == j => (VDUP(B|H|S|D) x)
1890 (VDUPB (MOVDconst [c])) => (VMOVI16B [uint8(c)])
1891 (VDUPH (MOVDconst [c])) && (uint16(c) <= 0xff || uint16(c)&0xff == 0) => (VMOVI8H [int64(uint16(c))])
1892 (VDUPS (MOVDconst [c])) && (uint32(c) <= 0xff || (uint32(c)&0xff == 0 && uint32(c)>>8 <= 0xff) || (uint32(c)&0xffff == 0 && uint32(c)>>16 <= 0xff) || (uint32(c)&0xffffff == 0 && uint32(c)>>24 <= 0xff) || (uint32(c)&0xff == 0xff && uint32(c)>>8 <= 0xff) || (uint32(c)&0xffff == 0xffff && uint32(c)>>16 <= 0xff)) => (VMOVI4S [int64(uint32(c))])
1893 (VDUPD (MOVDconst [c])) && c == (c&0x0101010101010101)*0xff => (VMOVI2D [c])
1894 (VEOR16B x x) => (VMOVI16B [0])
1895 (VNOT16B (VCMEQ16B (VAND16B x y) (VMOVI16B [0]))) => (VCMTST16B x y)
1896 (VNOT16B (VCMEQ8H (VAND16B x y) (VMOVI16B [0]))) => (VCMTST8H x y)
1897 (VNOT16B (VCMEQ4S (VAND16B x y) (VMOVI16B [0]))) => (VCMTST4S x y)
1898 (VNOT16B (VCMEQ2D (VAND16B x y) (VMOVI16B [0]))) => (VCMTST2D x y)
1899 (ZeroSIMD <t>) && t.Size() == 32 && t.IsSIMD() => (ZDUPBconst [0])
1900
1901 // SVE scalable-vector load/store and runtime vector length.
1902 (Load <t> ptr mem) && t.Size() == 32 && t.IsSIMD() => (ZLDRload ptr mem)
1903 (Store {t} ptr val mem) && t.Size() == 32 && t.IsSIMD() => (ZSTRstore ptr val mem)
1904 // SVE predicate (mask) load/store. A predicate is 8 bytes at the SSA level
1905 // (types.TypeMask); it cannot move to a GP/FP register, so masks that cross a
1906 // call or spill round-trip through memory via PLDR/PSTR. PSTR writes only VL/8
1907 // bytes, so a store first zeroes the whole 8 bytes: the bits above the vector
1908 // length read as zero, which is what lets user code read a mask's bits as a
1909 // uint64.
1910 (ZeroSIMD <t>) && t.Size() == 8 && t.IsSIMD() => (PPFALSEB)
1911 (Load <t> ptr mem) && t.Size() == 8 && t.IsSIMD() => (PLDRload ptr mem)
1912 (Store {t} ptr val mem) && t.Size() == 8 && t.IsSIMD() => (PSTRstore ptr val (MOVDstore ptr (MOVDconst [0]) mem))
1913 (ScalableVectorLen) => (RDVL [1])
1914
1915 // SVE byte-granular predicated scalable load/store (LoadTs/Store slice APIs).
1916 // These are written by hand until the predicated ops are generated by simdgen
1917 // in the mask CL; at that point delete them and generate instead.
1918 (Count8s r) => (Select0 <types.TypeMask> (PWHILELTB (MOVDconst [0]) r))
1919
1920 // SVE per-element select, backing IfElse and Masked.
1921 (IfElseInt8s x mask y) => (ZSELB x y mask)
1922 (IfElseUint8s x mask y) => (ZSELB x y mask)
1923 (IfElseInt16s x mask y) => (ZSELH x y mask)
1924 (IfElseUint16s x mask y) => (ZSELH x y mask)
1925 (IfElseInt32s x mask y) => (ZSELS x y mask)
1926 (IfElseUint32s x mask y) => (ZSELS x y mask)
1927 (IfElseFloat32s x mask y) => (ZSELS x y mask)
1928 (IfElseInt64s x mask y) => (ZSELD x y mask)
1929 (IfElseUint64s x mask y) => (ZSELD x y mask)
1930 (IfElseFloat64s x mask y) => (ZSELD x y mask)
1931
1932 // SVE scalar-to-vector broadcast. Integers come from a general register. A
1933 // float scalar is held in element 0 of the vector register that shares its
1934 // number, so a float broadcast is a broadcast of that element.
1935 (BroadcastInt8s ...) => (ZDUPB ...)
1936 (BroadcastUint8s ...) => (ZDUPB ...)
1937 (BroadcastInt16s ...) => (ZDUPH ...)
1938 (BroadcastUint16s ...) => (ZDUPH ...)
1939 (BroadcastInt32s ...) => (ZDUPS ...)
1940 (BroadcastUint32s ...) => (ZDUPS ...)
1941 (BroadcastInt64s ...) => (ZDUPD ...)
1942 (BroadcastUint64s ...) => (ZDUPD ...)
1943 (BroadcastFloat32s x) => (ZDUPIS [0] x)
1944 (BroadcastFloat64s x) => (ZDUPID [0] x)
1945
1946 // Element i is the last active one of the mask of the first i+1 lanes.
1947 (ElemInt8s x i) => (ZLASTBB x (Select0 <types.TypeMask> (PWHILELTB (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1948 (ElemUint8s x i) => (ZLASTBB x (Select0 <types.TypeMask> (PWHILELTB (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1949 (ElemInt16s x i) => (ZLASTBH x (Select0 <types.TypeMask> (PWHILELTH (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1950 (ElemUint16s x i) => (ZLASTBH x (Select0 <types.TypeMask> (PWHILELTH (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1951 (ElemInt32s x i) => (ZLASTBS x (Select0 <types.TypeMask> (PWHILELTS (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1952 (ElemUint32s x i) => (ZLASTBS x (Select0 <types.TypeMask> (PWHILELTS (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1953 (ElemFloat32s x i) => (ZLASTBfpS x (Select0 <types.TypeMask> (PWHILELTS (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1954 (ElemInt64s x i) => (ZLASTBD x (Select0 <types.TypeMask> (PWHILELTD (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1955 (ElemUint64s x i) => (ZLASTBD x (Select0 <types.TypeMask> (PWHILELTD (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1956 (ElemFloat64s x i) => (ZLASTBfpD x (Select0 <types.TypeMask> (PWHILELTD (MOVDconst [0]) (ADDconst <typ.UInt64> [1] (MOVBUreg <typ.UInt64> i)))))
1957
1958 // A broadcast of a small constant needs no general register: DUP (immediate)
1959 // takes a signed 8-bit immediate.
1960 (ZDUPB (MOVDconst [c])) && c == int64(int8(c)) => (ZDUPBconst [int8(c)])
1961 (ZDUPH (MOVDconst [c])) && c == int64(int8(c)) => (ZDUPHconst [int8(c)])
1962 (ZDUPS (MOVDconst [c])) && c == int64(int8(c)) => (ZDUPSconst [int8(c)])
1963 (ZDUPD (MOVDconst [c])) && c == int64(int8(c)) => (ZDUPDconst [int8(c)])
1964
1965 // A select over a broadcast folds into predicated CPY. Merging CPY (/M) handles
1966 // an arbitrary else operand; when the broadcast is a small constant and the
1967 // else operand is zero (as in Masked), zeroing CPY (/Z) constructs the result
1968 // directly without materializing the zero vector.
1969 //
1970 // Fold a select over a GP-register broadcast into a merging GP-register CPY.
1971 (ZSEL(B|H|S|D) (ZDUP(B|H|S|D) x) z mask) => (ZCPYMerging(B|H|S|D) z x mask)
1972 // Fold a select over a lane-0 vector/FP broadcast into a merging FP-register CPY.
1973 (ZSEL(B|H|S|D) (ZDUPI(B|H|S|D) [0] x) z mask) => (ZCPYIMerging(B|H|S|D) z x mask)
1974 // Fold a select over an immediate broadcast into a merging immediate CPY.
1975 (ZSEL(B|H|S|D) (ZDUP(B|H|S|D)const [c]) z mask) => (ZCPYMerging(B|H|S|D)const [c] z mask)
1976 // Fold a small constant scalar into a merging GP-register CPY if ZSEL folded before ZDUP.
1977 (ZCPYMerging(B|H|S|D) z (MOVDconst [c]) mask) && c == int64(int8(c)) => (ZCPYMerging(B|H|S|D)const [int8(c)] z mask)
1978 // Replace a merging immediate CPY into a zero vector with a zeroing immediate CPY.
1979 (ZCPYMerging(B|H|S|D)const [c] (ZDUPBconst [0]) mask) => (ZCPY(B|H|S|D)const [c] mask)
1980
1981 // All-true predicate constructors: the same PWHILELT pattern the lowering
1982 // synthesizes for implicitly predicated operations, so the select-fold
1983 // peepholes recognize an explicit all-true mask and CSE dedups it with theirs.
1984 (Mask8sAllTrue) => (Select0 <types.TypeMask> (PWHILELTB (MOVDconst [0]) (MOVDconst [32])))
1985 (Mask16sAllTrue) => (Select0 <types.TypeMask> (PWHILELTH (MOVDconst [0]) (MOVDconst [16])))
1986 (Mask32sAllTrue) => (Select0 <types.TypeMask> (PWHILELTS (MOVDconst [0]) (MOVDconst [8])))
1987 (Mask64sAllTrue) => (Select0 <types.TypeMask> (PWHILELTD (MOVDconst [0]) (MOVDconst [4])))
1988
1989 // Lane i is active when i < count, compared signed, so a count of 0 or less
1990 // gives no active lanes.
1991 (Mask8sFromCount n) => (Select0 <types.TypeMask> (PWHILELTB (MOVDconst [0]) n))
1992 (Mask16sFromCount n) => (Select0 <types.TypeMask> (PWHILELTH (MOVDconst [0]) n))
1993 (Mask32sFromCount n) => (Select0 <types.TypeMask> (PWHILELTS (MOVDconst [0]) n))
1994 (Mask64sFromCount n) => (Select0 <types.TypeMask> (PWHILELTD (MOVDconst [0]) n))
1995
1996 // The first active lane is the one that follows the last active lane of an
1997 // all-false mask.
1998 (Mask8sFirst m) => (PPNEXTB (PPFALSEB) m)
1999 (Mask16sFirst m) => (PPNEXTH (PPFALSEB) m)
2000 (Mask32sFirst m) => (PPNEXTS (PPFALSEB) m)
2001 (Mask64sFirst m) => (PPNEXTD (PPFALSEB) m)
2002
2003 (Mask8sNext m cursor) => (PPNEXTB cursor m)
2004 (Mask16sNext m cursor) => (PPNEXTH cursor m)
2005 (Mask32sNext m cursor) => (PPNEXTS cursor m)
2006 (Mask64sNext m cursor) => (PPNEXTD cursor m)
2007
2008 // Every lane is active when no lane survives all-true AND NOT m.
2009 (Mask8sAll m) => (Equal (Select1 <types.TypeFlags> (PBICSB t:(Mask8sAllTrue <types.TypeMask>) t m)))
2010 (Mask16sAll m) => (Equal (Select1 <types.TypeFlags> (PBICSB t:(Mask16sAllTrue <types.TypeMask>) t m)))
2011 (Mask32sAll m) => (Equal (Select1 <types.TypeFlags> (PBICSB t:(Mask32sAllTrue <types.TypeMask>) t m)))
2012 (Mask64sAll m) => (Equal (Select1 <types.TypeFlags> (PBICSB t:(Mask64sAllTrue <types.TypeMask>) t m)))
2013
2014 (Mask8sNone m) => (Equal (PPTEST (Mask8sAllTrue <types.TypeMask>) m))
2015 (Mask16sNone m) => (Equal (PPTEST (Mask16sAllTrue <types.TypeMask>) m))
2016 (Mask32sNone m) => (Equal (PPTEST (Mask32sAllTrue <types.TypeMask>) m))
2017 (Mask64sNone m) => (Equal (PPTEST (Mask64sAllTrue <types.TypeMask>) m))
2018
2019 (Mask8sAny m) => (NotEqual (PPTEST (Mask8sAllTrue <types.TypeMask>) m))
2020 (Mask16sAny m) => (NotEqual (PPTEST (Mask16sAllTrue <types.TypeMask>) m))
2021 (Mask32sAny m) => (NotEqual (PPTEST (Mask32sAllTrue <types.TypeMask>) m))
2022 (Mask64sAny m) => (NotEqual (PPTEST (Mask64sAllTrue <types.TypeMask>) m))
2023
2024 // The predicate logic instructions have only a byte form. Governing them by
2025 // the all-true mask of the lane size zeroes the bits between lanes. A Mask8s
2026 // has a lane for every bit, so x itself can govern it.
2027 (Mask8sAnd x y) => (PANDB x x y)
2028 (Mask16sAnd x y) => (PANDB (Mask16sAllTrue <types.TypeMask>) x y)
2029 (Mask32sAnd x y) => (PANDB (Mask32sAllTrue <types.TypeMask>) x y)
2030 (Mask64sAnd x y) => (PANDB (Mask64sAllTrue <types.TypeMask>) x y)
2031 (Mask8sAndNot x y) => (PBICB x x y)
2032 (Mask16sAndNot x y) => (PBICB (Mask16sAllTrue <types.TypeMask>) x y)
2033 (Mask32sAndNot x y) => (PBICB (Mask32sAllTrue <types.TypeMask>) x y)
2034 (Mask64sAndNot x y) => (PBICB (Mask64sAllTrue <types.TypeMask>) x y)
2035 (Mask8sOr x y) => (PORRB (Mask8sAllTrue <types.TypeMask>) x y)
2036 (Mask16sOr x y) => (PORRB (Mask16sAllTrue <types.TypeMask>) x y)
2037 (Mask32sOr x y) => (PORRB (Mask32sAllTrue <types.TypeMask>) x y)
2038 (Mask64sOr x y) => (PORRB (Mask64sAllTrue <types.TypeMask>) x y)
2039 (Mask8sXor x y) => (PEORB (Mask8sAllTrue <types.TypeMask>) x y)
2040 (Mask16sXor x y) => (PEORB (Mask16sAllTrue <types.TypeMask>) x y)
2041 (Mask32sXor x y) => (PEORB (Mask32sAllTrue <types.TypeMask>) x y)
2042 (Mask64sXor x y) => (PEORB (Mask64sAllTrue <types.TypeMask>) x y)
2043
2044 // NOT is EOR with the governing predicate as the second source.
2045 (Mask8sNot x) => (PEORB t:(Mask8sAllTrue <types.TypeMask>) x t)
2046 (Mask16sNot x) => (PEORB t:(Mask16sAllTrue <types.TypeMask>) x t)
2047 (Mask32sNot x) => (PEORB t:(Mask32sAllTrue <types.TypeMask>) x t)
2048 (Mask64sNot x) => (PEORB t:(Mask64sAllTrue <types.TypeMask>) x t)
2049
2050 // TrailingZeros: PBRKB sets the lanes before the first active one and PCNTP
2051 // counts them. PBRKB has only a byte form; governing it by the all-true mask
2052 // of the lane size makes it ignore the bits between lanes.
2053 (Mask8sTrailingZeros m) => (PCNTPB t:(Mask8sAllTrue <types.TypeMask>) (PBRKB t m))
2054 (Mask16sTrailingZeros m) => (PCNTPH t:(Mask16sAllTrue <types.TypeMask>) (PBRKB t m))
2055 (Mask32sTrailingZeros m) => (PCNTPS t:(Mask32sAllTrue <types.TypeMask>) (PBRKB t m))
2056 (Mask64sTrailingZeros m) => (PCNTPD t:(Mask64sAllTrue <types.TypeMask>) (PBRKB t m))
2057
2058 // == on SIMD vectors and masks. Integer vectors and masks are equal if their
2059 // XOR is zero. Float vectors are equal if every element compares equal, so NaN
2060 // elements are unequal and +0 equals -0.
2061 (EqualVec128 x y) => (Equal (CMPWconst [0] (VMOVSextr <typ.UInt32> [0] (VUMAXV4S (VEOR16B x y)))))
2062 (EqualVecFloat32x4 x y) => (Equal (CMPWconst [0] (VMOVSextr <typ.UInt32> [0] (VUMAXV4S (VNOT16B (VFCMEQ4S x y))))))
2063 (EqualVecFloat64x2 x y) => (Equal (CMPWconst [0] (VMOVSextr <typ.UInt32> [0] (VUMAXV4S (VNOT16B (VFCMEQ2D x y))))))
2064
2065 (LoadMasked8 <t> ptr mask mem) && t.Size() == 32 => (ZLD1BPredload ptr mask mem)
2066 (StoreMasked8 {t} ptr mask val mem) && t.Size() == 32 => (ZST1BPredstore ptr val mask mem)
2067
View as plain text