github.com/fenixara/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/compile/internal/ssa/gen/ARM64.rules (about) 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 (AddPtr x y) -> (ADD x y) 6 (Add64 x y) -> (ADD x y) 7 (Add32 x y) -> (ADD x y) 8 (Add16 x y) -> (ADD x y) 9 (Add8 x y) -> (ADD x y) 10 (Add32F x y) -> (FADDS x y) 11 (Add64F x y) -> (FADDD x y) 12 13 (SubPtr x y) -> (SUB x y) 14 (Sub64 x y) -> (SUB x y) 15 (Sub32 x y) -> (SUB x y) 16 (Sub16 x y) -> (SUB x y) 17 (Sub8 x y) -> (SUB x y) 18 (Sub32F x y) -> (FSUBS x y) 19 (Sub64F x y) -> (FSUBD x y) 20 21 (Mul64 x y) -> (MUL x y) 22 (Mul32 x y) -> (MULW x y) 23 (Mul16 x y) -> (MULW x y) 24 (Mul8 x y) -> (MULW x y) 25 (Mul32F x y) -> (FMULS x y) 26 (Mul64F x y) -> (FMULD x y) 27 28 (Hmul64 x y) -> (MULH x y) 29 (Hmul64u x y) -> (UMULH x y) 30 (Hmul32 x y) -> (SRAconst (MULL <config.fe.TypeInt64()> x y) [32]) 31 (Hmul32u x y) -> (SRAconst (UMULL <config.fe.TypeUInt64()> x y) [32]) 32 (Hmul16 x y) -> (SRAconst (MULW <config.fe.TypeInt32()> (SignExt16to32 x) (SignExt16to32 y)) [16]) 33 (Hmul16u x y) -> (SRLconst (MUL <config.fe.TypeUInt32()> (ZeroExt16to32 x) (ZeroExt16to32 y)) [16]) 34 (Hmul8 x y) -> (SRAconst (MULW <config.fe.TypeInt16()> (SignExt8to32 x) (SignExt8to32 y)) [8]) 35 (Hmul8u x y) -> (SRLconst (MUL <config.fe.TypeUInt16()> (ZeroExt8to32 x) (ZeroExt8to32 y)) [8]) 36 37 (Div64 x y) -> (DIV x y) 38 (Div64u x y) -> (UDIV x y) 39 (Div32 x y) -> (DIVW x y) 40 (Div32u x y) -> (UDIVW x y) 41 (Div16 x y) -> (DIVW (SignExt16to32 x) (SignExt16to32 y)) 42 (Div16u x y) -> (UDIVW (ZeroExt16to32 x) (ZeroExt16to32 y)) 43 (Div8 x y) -> (DIVW (SignExt8to32 x) (SignExt8to32 y)) 44 (Div8u x y) -> (UDIVW (ZeroExt8to32 x) (ZeroExt8to32 y)) 45 (Div32F x y) -> (FDIVS x y) 46 (Div64F x y) -> (FDIVD x y) 47 48 (Mod64 x y) -> (MOD x y) 49 (Mod64u x y) -> (UMOD x y) 50 (Mod32 x y) -> (MODW x y) 51 (Mod32u x y) -> (UMODW x y) 52 (Mod16 x y) -> (MODW (SignExt16to32 x) (SignExt16to32 y)) 53 (Mod16u x y) -> (UMODW (ZeroExt16to32 x) (ZeroExt16to32 y)) 54 (Mod8 x y) -> (MODW (SignExt8to32 x) (SignExt8to32 y)) 55 (Mod8u x y) -> (UMODW (ZeroExt8to32 x) (ZeroExt8to32 y)) 56 57 (Avg64u <t> x y) -> (ADD (ADD <t> (SRLconst <t> x [1]) (SRLconst <t> y [1])) (AND <t> (AND <t> x y) (MOVDconst [1]))) 58 59 (And64 x y) -> (AND x y) 60 (And32 x y) -> (AND x y) 61 (And16 x y) -> (AND x y) 62 (And8 x y) -> (AND x y) 63 64 (Or64 x y) -> (OR x y) 65 (Or32 x y) -> (OR x y) 66 (Or16 x y) -> (OR x y) 67 (Or8 x y) -> (OR x y) 68 69 (Xor64 x y) -> (XOR x y) 70 (Xor32 x y) -> (XOR x y) 71 (Xor16 x y) -> (XOR x y) 72 (Xor8 x y) -> (XOR x y) 73 74 // unary ops 75 (Neg64 x) -> (NEG x) 76 (Neg32 x) -> (NEG x) 77 (Neg16 x) -> (NEG x) 78 (Neg8 x) -> (NEG x) 79 (Neg32F x) -> (FNEGS x) 80 (Neg64F x) -> (FNEGD x) 81 82 (Com64 x) -> (MVN x) 83 (Com32 x) -> (MVN x) 84 (Com16 x) -> (MVN x) 85 (Com8 x) -> (MVN x) 86 87 (Sqrt x) -> (FSQRTD x) 88 89 (Ctz64 <t> x) -> (CLZ (RBIT <t> x)) 90 (Ctz32 <t> x) -> (CLZW (RBITW <t> x)) 91 92 (Bswap64 x) -> (REV x) 93 (Bswap32 x) -> (REVW x) 94 95 // boolean ops -- booleans are represented with 0=false, 1=true 96 (AndB x y) -> (AND x y) 97 (OrB x y) -> (OR x y) 98 (EqB x y) -> (XOR (MOVDconst [1]) (XOR <config.fe.TypeBool()> x y)) 99 (NeqB x y) -> (XOR x y) 100 (Not x) -> (XOR (MOVDconst [1]) x) 101 102 // constant shifts 103 (Lsh64x64 x (MOVDconst [c])) && uint64(c) < 64 -> (SLLconst x [c]) 104 (Rsh64x64 x (MOVDconst [c])) && uint64(c) < 64 -> (SRAconst x [c]) 105 (Rsh64Ux64 x (MOVDconst [c])) && uint64(c) < 64 -> (SRLconst x [c]) 106 (Lsh32x64 x (MOVDconst [c])) && uint64(c) < 32 -> (SLLconst x [c]) 107 (Rsh32x64 x (MOVDconst [c])) && uint64(c) < 32 -> (SRAconst (SignExt32to64 x) [c]) 108 (Rsh32Ux64 x (MOVDconst [c])) && uint64(c) < 32 -> (SRLconst (ZeroExt32to64 x) [c]) 109 (Lsh16x64 x (MOVDconst [c])) && uint64(c) < 16 -> (SLLconst x [c]) 110 (Rsh16x64 x (MOVDconst [c])) && uint64(c) < 16 -> (SRAconst (SignExt16to64 x) [c]) 111 (Rsh16Ux64 x (MOVDconst [c])) && uint64(c) < 16 -> (SRLconst (ZeroExt16to64 x) [c]) 112 (Lsh8x64 x (MOVDconst [c])) && uint64(c) < 8 -> (SLLconst x [c]) 113 (Rsh8x64 x (MOVDconst [c])) && uint64(c) < 8 -> (SRAconst (SignExt8to64 x) [c]) 114 (Rsh8Ux64 x (MOVDconst [c])) && uint64(c) < 8 -> (SRLconst (ZeroExt8to64 x) [c]) 115 116 // large constant shifts 117 (Lsh64x64 _ (MOVDconst [c])) && uint64(c) >= 64 -> (MOVDconst [0]) 118 (Rsh64Ux64 _ (MOVDconst [c])) && uint64(c) >= 64 -> (MOVDconst [0]) 119 (Lsh32x64 _ (MOVDconst [c])) && uint64(c) >= 32 -> (MOVDconst [0]) 120 (Rsh32Ux64 _ (MOVDconst [c])) && uint64(c) >= 32 -> (MOVDconst [0]) 121 (Lsh16x64 _ (MOVDconst [c])) && uint64(c) >= 16 -> (MOVDconst [0]) 122 (Rsh16Ux64 _ (MOVDconst [c])) && uint64(c) >= 16 -> (MOVDconst [0]) 123 (Lsh8x64 _ (MOVDconst [c])) && uint64(c) >= 8 -> (MOVDconst [0]) 124 (Rsh8Ux64 _ (MOVDconst [c])) && uint64(c) >= 8 -> (MOVDconst [0]) 125 126 // large constant signed right shift, we leave the sign bit 127 (Rsh64x64 x (MOVDconst [c])) && uint64(c) >= 64 -> (SRAconst x [63]) 128 (Rsh32x64 x (MOVDconst [c])) && uint64(c) >= 32 -> (SRAconst (SignExt32to64 x) [63]) 129 (Rsh16x64 x (MOVDconst [c])) && uint64(c) >= 16 -> (SRAconst (SignExt16to64 x) [63]) 130 (Rsh8x64 x (MOVDconst [c])) && uint64(c) >= 8 -> (SRAconst (SignExt8to64 x) [63]) 131 132 // shifts 133 // hardware instruction uses only the low 6 bits of the shift 134 // we compare to 64 to ensure Go semantics for large shifts 135 (Lsh64x64 <t> x y) -> (CSELULT (SLL <t> x y) (Const64 <t> [0]) (CMPconst [64] y)) 136 (Lsh64x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 137 (Lsh64x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 138 (Lsh64x8 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 139 140 (Lsh32x64 <t> x y) -> (CSELULT (SLL <t> x y) (Const64 <t> [0]) (CMPconst [64] y)) 141 (Lsh32x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 142 (Lsh32x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 143 (Lsh32x8 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 144 145 (Lsh16x64 <t> x y) -> (CSELULT (SLL <t> x y) (Const64 <t> [0]) (CMPconst [64] y)) 146 (Lsh16x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 147 (Lsh16x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 148 (Lsh16x8 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 149 150 (Lsh8x64 <t> x y) -> (CSELULT (SLL <t> x y) (Const64 <t> [0]) (CMPconst [64] y)) 151 (Lsh8x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 152 (Lsh8x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 153 (Lsh8x8 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 154 155 (Rsh64Ux64 <t> x y) -> (CSELULT (SRL <t> x y) (Const64 <t> [0]) (CMPconst [64] y)) 156 (Rsh64Ux32 <t> x y) -> (CSELULT (SRL <t> x (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 157 (Rsh64Ux16 <t> x y) -> (CSELULT (SRL <t> x (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 158 (Rsh64Ux8 <t> x y) -> (CSELULT (SRL <t> x (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 159 160 (Rsh32Ux64 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) y) (Const64 <t> [0]) (CMPconst [64] y)) 161 (Rsh32Ux32 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 162 (Rsh32Ux16 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 163 (Rsh32Ux8 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 164 165 (Rsh16Ux64 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) y) (Const64 <t> [0]) (CMPconst [64] y)) 166 (Rsh16Ux32 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 167 (Rsh16Ux16 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 168 (Rsh16Ux8 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 169 170 (Rsh8Ux64 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) y) (Const64 <t> [0]) (CMPconst [64] y)) 171 (Rsh8Ux32 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) (ZeroExt32to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt32to64 y))) 172 (Rsh8Ux16 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) (ZeroExt16to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt16to64 y))) 173 (Rsh8Ux8 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) (ZeroExt8to64 y)) (Const64 <t> [0]) (CMPconst [64] (ZeroExt8to64 y))) 174 175 (Rsh64x64 x y) -> (SRA x (CSELULT <y.Type> y (Const64 <y.Type> [63]) (CMPconst [64] y))) 176 (Rsh64x32 x y) -> (SRA x (CSELULT <y.Type> (ZeroExt32to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y)))) 177 (Rsh64x16 x y) -> (SRA x (CSELULT <y.Type> (ZeroExt16to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y)))) 178 (Rsh64x8 x y) -> (SRA x (CSELULT <y.Type> (ZeroExt8to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt8to64 y)))) 179 180 (Rsh32x64 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> y (Const64 <y.Type> [63]) (CMPconst [64] y))) 181 (Rsh32x32 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> (ZeroExt32to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y)))) 182 (Rsh32x16 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> (ZeroExt16to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y)))) 183 (Rsh32x8 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> (ZeroExt8to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt8to64 y)))) 184 185 (Rsh16x64 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> y (Const64 <y.Type> [63]) (CMPconst [64] y))) 186 (Rsh16x32 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> (ZeroExt32to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y)))) 187 (Rsh16x16 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> (ZeroExt16to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y)))) 188 (Rsh16x8 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> (ZeroExt8to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt8to64 y)))) 189 190 (Rsh8x64 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> y (Const64 <y.Type> [63]) (CMPconst [64] y))) 191 (Rsh8x32 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> (ZeroExt32to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y)))) 192 (Rsh8x16 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> (ZeroExt16to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y)))) 193 (Rsh8x8 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> (ZeroExt8to64 y) (Const64 <y.Type> [63]) (CMPconst [64] (ZeroExt8to64 y)))) 194 195 (Lrot64 x [c]) -> (RORconst x [64-c&63]) 196 (Lrot32 x [c]) -> (RORWconst x [32-c&31]) 197 (Lrot16 <t> x [c]) -> (OR (SLLconst <t> x [c&15]) (SRLconst <t> (ZeroExt16to64 x) [16-c&15])) 198 (Lrot8 <t> x [c]) -> (OR (SLLconst <t> x [c&7]) (SRLconst <t> (ZeroExt8to64 x) [8-c&7])) 199 200 // constants 201 (Const64 [val]) -> (MOVDconst [val]) 202 (Const32 [val]) -> (MOVDconst [val]) 203 (Const16 [val]) -> (MOVDconst [val]) 204 (Const8 [val]) -> (MOVDconst [val]) 205 (Const32F [val]) -> (FMOVSconst [val]) 206 (Const64F [val]) -> (FMOVDconst [val]) 207 (ConstNil) -> (MOVDconst [0]) 208 (ConstBool [b]) -> (MOVDconst [b]) 209 210 (Slicemask <t> x) -> (MVN (SRAconst <t> (SUBconst <t> x [1]) [63])) 211 212 // truncations 213 // Because we ignore high parts of registers, truncates are just copies. 214 (Trunc16to8 x) -> x 215 (Trunc32to8 x) -> x 216 (Trunc32to16 x) -> x 217 (Trunc64to8 x) -> x 218 (Trunc64to16 x) -> x 219 (Trunc64to32 x) -> x 220 221 // Zero-/Sign-extensions 222 (ZeroExt8to16 x) -> (MOVBUreg x) 223 (ZeroExt8to32 x) -> (MOVBUreg x) 224 (ZeroExt16to32 x) -> (MOVHUreg x) 225 (ZeroExt8to64 x) -> (MOVBUreg x) 226 (ZeroExt16to64 x) -> (MOVHUreg x) 227 (ZeroExt32to64 x) -> (MOVWUreg x) 228 229 (SignExt8to16 x) -> (MOVBreg x) 230 (SignExt8to32 x) -> (MOVBreg x) 231 (SignExt16to32 x) -> (MOVHreg x) 232 (SignExt8to64 x) -> (MOVBreg x) 233 (SignExt16to64 x) -> (MOVHreg x) 234 (SignExt32to64 x) -> (MOVWreg x) 235 236 // float <-> int conversion 237 (Cvt32to32F x) -> (SCVTFWS x) 238 (Cvt32to64F x) -> (SCVTFWD x) 239 (Cvt64to32F x) -> (SCVTFS x) 240 (Cvt64to64F x) -> (SCVTFD x) 241 (Cvt32Uto32F x) -> (UCVTFWS x) 242 (Cvt32Uto64F x) -> (UCVTFWD x) 243 (Cvt64Uto32F x) -> (UCVTFS x) 244 (Cvt64Uto64F x) -> (UCVTFD x) 245 (Cvt32Fto32 x) -> (FCVTZSSW x) 246 (Cvt64Fto32 x) -> (FCVTZSDW x) 247 (Cvt32Fto64 x) -> (FCVTZSS x) 248 (Cvt64Fto64 x) -> (FCVTZSD x) 249 (Cvt32Fto32U x) -> (FCVTZUSW x) 250 (Cvt64Fto32U x) -> (FCVTZUDW x) 251 (Cvt32Fto64U x) -> (FCVTZUS x) 252 (Cvt64Fto64U x) -> (FCVTZUD x) 253 (Cvt32Fto64F x) -> (FCVTSD x) 254 (Cvt64Fto32F x) -> (FCVTDS x) 255 256 // comparisons 257 (Eq8 x y) -> (Equal (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y))) 258 (Eq16 x y) -> (Equal (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y))) 259 (Eq32 x y) -> (Equal (CMPW x y)) 260 (Eq64 x y) -> (Equal (CMP x y)) 261 (EqPtr x y) -> (Equal (CMP x y)) 262 (Eq32F x y) -> (Equal (FCMPS x y)) 263 (Eq64F x y) -> (Equal (FCMPD x y)) 264 265 (Neq8 x y) -> (NotEqual (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y))) 266 (Neq16 x y) -> (NotEqual (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y))) 267 (Neq32 x y) -> (NotEqual (CMPW x y)) 268 (Neq64 x y) -> (NotEqual (CMP x y)) 269 (NeqPtr x y) -> (NotEqual (CMP x y)) 270 (Neq32F x y) -> (NotEqual (FCMPS x y)) 271 (Neq64F x y) -> (NotEqual (FCMPD x y)) 272 273 (Less8 x y) -> (LessThan (CMPW (SignExt8to32 x) (SignExt8to32 y))) 274 (Less16 x y) -> (LessThan (CMPW (SignExt16to32 x) (SignExt16to32 y))) 275 (Less32 x y) -> (LessThan (CMPW x y)) 276 (Less64 x y) -> (LessThan (CMP x y)) 277 (Less32F x y) -> (GreaterThan (FCMPS y x)) // reverse operands to work around NaN 278 (Less64F x y) -> (GreaterThan (FCMPD y x)) // reverse operands to work around NaN 279 280 (Less8U x y) -> (LessThanU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y))) 281 (Less16U x y) -> (LessThanU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y))) 282 (Less32U x y) -> (LessThanU (CMPW x y)) 283 (Less64U x y) -> (LessThanU (CMP x y)) 284 285 (Leq8 x y) -> (LessEqual (CMPW (SignExt8to32 x) (SignExt8to32 y))) 286 (Leq16 x y) -> (LessEqual (CMPW (SignExt16to32 x) (SignExt16to32 y))) 287 (Leq32 x y) -> (LessEqual (CMPW x y)) 288 (Leq64 x y) -> (LessEqual (CMP x y)) 289 (Leq32F x y) -> (GreaterEqual (FCMPS y x)) // reverse operands to work around NaN 290 (Leq64F x y) -> (GreaterEqual (FCMPD y x)) // reverse operands to work around NaN 291 292 (Leq8U x y) -> (LessEqualU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y))) 293 (Leq16U x y) -> (LessEqualU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y))) 294 (Leq32U x y) -> (LessEqualU (CMPW x y)) 295 (Leq64U x y) -> (LessEqualU (CMP x y)) 296 297 (Greater8 x y) -> (GreaterThan (CMPW (SignExt8to32 x) (SignExt8to32 y))) 298 (Greater16 x y) -> (GreaterThan (CMPW (SignExt16to32 x) (SignExt16to32 y))) 299 (Greater32 x y) -> (GreaterThan (CMPW x y)) 300 (Greater64 x y) -> (GreaterThan (CMP x y)) 301 (Greater32F x y) -> (GreaterThan (FCMPS x y)) 302 (Greater64F x y) -> (GreaterThan (FCMPD x y)) 303 304 (Greater8U x y) -> (GreaterThanU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y))) 305 (Greater16U x y) -> (GreaterThanU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y))) 306 (Greater32U x y) -> (GreaterThanU (CMPW x y)) 307 (Greater64U x y) -> (GreaterThanU (CMP x y)) 308 309 (Geq8 x y) -> (GreaterEqual (CMPW (SignExt8to32 x) (SignExt8to32 y))) 310 (Geq16 x y) -> (GreaterEqual (CMPW (SignExt16to32 x) (SignExt16to32 y))) 311 (Geq32 x y) -> (GreaterEqual (CMPW x y)) 312 (Geq64 x y) -> (GreaterEqual (CMP x y)) 313 (Geq32F x y) -> (GreaterEqual (FCMPS x y)) 314 (Geq64F x y) -> (GreaterEqual (FCMPD x y)) 315 316 (Geq8U x y) -> (GreaterEqualU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y))) 317 (Geq16U x y) -> (GreaterEqualU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y))) 318 (Geq32U x y) -> (GreaterEqualU (CMPW x y)) 319 (Geq64U x y) -> (GreaterEqualU (CMP x y)) 320 321 (OffPtr [off] ptr:(SP)) -> (MOVDaddr [off] ptr) 322 (OffPtr [off] ptr) -> (ADDconst [off] ptr) 323 324 (Addr {sym} base) -> (MOVDaddr {sym} base) 325 326 // loads 327 (Load <t> ptr mem) && t.IsBoolean() -> (MOVBUload ptr mem) 328 (Load <t> ptr mem) && (is8BitInt(t) && isSigned(t)) -> (MOVBload ptr mem) 329 (Load <t> ptr mem) && (is8BitInt(t) && !isSigned(t)) -> (MOVBUload ptr mem) 330 (Load <t> ptr mem) && (is16BitInt(t) && isSigned(t)) -> (MOVHload ptr mem) 331 (Load <t> ptr mem) && (is16BitInt(t) && !isSigned(t)) -> (MOVHUload ptr mem) 332 (Load <t> ptr mem) && (is32BitInt(t) && isSigned(t)) -> (MOVWload ptr mem) 333 (Load <t> ptr mem) && (is32BitInt(t) && !isSigned(t)) -> (MOVWUload ptr mem) 334 (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) -> (MOVDload ptr mem) 335 (Load <t> ptr mem) && is32BitFloat(t) -> (FMOVSload ptr mem) 336 (Load <t> ptr mem) && is64BitFloat(t) -> (FMOVDload ptr mem) 337 338 // stores 339 (Store [1] ptr val mem) -> (MOVBstore ptr val mem) 340 (Store [2] ptr val mem) -> (MOVHstore ptr val mem) 341 (Store [4] ptr val mem) && !is32BitFloat(val.Type) -> (MOVWstore ptr val mem) 342 (Store [8] ptr val mem) && !is64BitFloat(val.Type) -> (MOVDstore ptr val mem) 343 (Store [4] ptr val mem) && is32BitFloat(val.Type) -> (FMOVSstore ptr val mem) 344 (Store [8] ptr val mem) && is64BitFloat(val.Type) -> (FMOVDstore ptr val mem) 345 346 // zeroing 347 (Zero [s] _ mem) && SizeAndAlign(s).Size() == 0 -> mem 348 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 1 -> (MOVBstore ptr (MOVDconst [0]) mem) 349 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 2 -> (MOVHstore ptr (MOVDconst [0]) mem) 350 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 4 -> (MOVWstore ptr (MOVDconst [0]) mem) 351 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 8 -> (MOVDstore ptr (MOVDconst [0]) mem) 352 353 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 3 -> 354 (MOVBstore [2] ptr (MOVDconst [0]) 355 (MOVHstore ptr (MOVDconst [0]) mem)) 356 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 5 -> 357 (MOVBstore [4] ptr (MOVDconst [0]) 358 (MOVWstore ptr (MOVDconst [0]) mem)) 359 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 6 -> 360 (MOVHstore [4] ptr (MOVDconst [0]) 361 (MOVWstore ptr (MOVDconst [0]) mem)) 362 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 7 -> 363 (MOVBstore [6] ptr (MOVDconst [0]) 364 (MOVHstore [4] ptr (MOVDconst [0]) 365 (MOVWstore ptr (MOVDconst [0]) mem))) 366 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 12 -> 367 (MOVWstore [8] ptr (MOVDconst [0]) 368 (MOVDstore ptr (MOVDconst [0]) mem)) 369 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 16 -> 370 (MOVDstore [8] ptr (MOVDconst [0]) 371 (MOVDstore ptr (MOVDconst [0]) mem)) 372 (Zero [s] ptr mem) && SizeAndAlign(s).Size() == 24 -> 373 (MOVDstore [16] ptr (MOVDconst [0]) 374 (MOVDstore [8] ptr (MOVDconst [0]) 375 (MOVDstore ptr (MOVDconst [0]) mem))) 376 377 // strip off fractional word zeroing 378 (Zero [s] ptr mem) && SizeAndAlign(s).Size()%8 != 0 && SizeAndAlign(s).Size() > 8 -> 379 (Zero [MakeSizeAndAlign(SizeAndAlign(s).Size()%8, 1).Int64()] 380 (OffPtr <ptr.Type> ptr [SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%8]) 381 (Zero [MakeSizeAndAlign(SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%8, 1).Int64()] ptr mem)) 382 383 // medium zeroing uses a duff device 384 // 4, 8, and 128 are magic constants, see runtime/mkduff.go 385 (Zero [s] ptr mem) 386 && SizeAndAlign(s).Size()%8 == 0 && SizeAndAlign(s).Size() > 24 && SizeAndAlign(s).Size() <= 8*128 387 && !config.noDuffDevice -> 388 (DUFFZERO [4 * (128 - int64(SizeAndAlign(s).Size()/8))] ptr mem) 389 390 // large zeroing uses a loop 391 (Zero [s] ptr mem) 392 && SizeAndAlign(s).Size()%8 == 0 && (SizeAndAlign(s).Size() > 8*128 || config.noDuffDevice) -> 393 (LoweredZero 394 ptr 395 (ADDconst <ptr.Type> [SizeAndAlign(s).Size()-moveSize(SizeAndAlign(s).Align(), config)] ptr) 396 mem) 397 398 // moves 399 (Move [s] _ _ mem) && SizeAndAlign(s).Size() == 0 -> mem 400 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 1 -> (MOVBstore dst (MOVBUload src mem) mem) 401 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 2 -> (MOVHstore dst (MOVHUload src mem) mem) 402 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 4 -> (MOVWstore dst (MOVWUload src mem) mem) 403 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 8 -> (MOVDstore dst (MOVDload src mem) mem) 404 405 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 3 -> 406 (MOVBstore [2] dst (MOVBUload [2] src mem) 407 (MOVHstore dst (MOVHUload src mem) mem)) 408 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 5 -> 409 (MOVBstore [4] dst (MOVBUload [4] src mem) 410 (MOVWstore dst (MOVWUload src mem) mem)) 411 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 6 -> 412 (MOVHstore [4] dst (MOVHUload [4] src mem) 413 (MOVWstore dst (MOVWUload src mem) mem)) 414 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 7 -> 415 (MOVBstore [6] dst (MOVBUload [6] src mem) 416 (MOVHstore [4] dst (MOVHUload [4] src mem) 417 (MOVWstore dst (MOVWUload src mem) mem))) 418 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 12 -> 419 (MOVWstore [8] dst (MOVWUload [8] src mem) 420 (MOVDstore dst (MOVDload src mem) mem)) 421 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 16 -> 422 (MOVDstore [8] dst (MOVDload [8] src mem) 423 (MOVDstore dst (MOVDload src mem) mem)) 424 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 24 -> 425 (MOVDstore [16] dst (MOVDload [16] src mem) 426 (MOVDstore [8] dst (MOVDload [8] src mem) 427 (MOVDstore dst (MOVDload src mem) mem))) 428 429 // strip off fractional word move 430 (Move [s] dst src mem) && SizeAndAlign(s).Size()%8 != 0 && SizeAndAlign(s).Size() > 8 -> 431 (Move [MakeSizeAndAlign(SizeAndAlign(s).Size()%8, 1).Int64()] 432 (OffPtr <dst.Type> dst [SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%8]) 433 (OffPtr <src.Type> src [SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%8]) 434 (Move [MakeSizeAndAlign(SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%8, 1).Int64()] dst src mem)) 435 436 // medium move uses a duff device 437 // 8 and 128 are magic constants, see runtime/mkduff.go 438 (Move [s] dst src mem) 439 && SizeAndAlign(s).Size()%8 == 0 && SizeAndAlign(s).Size() > 24 && SizeAndAlign(s).Size() <= 8*128 440 && !config.noDuffDevice -> 441 (DUFFCOPY [8 * (128 - int64(SizeAndAlign(s).Size()/8))] dst src mem) 442 443 // large move uses a loop 444 (Move [s] dst src mem) 445 && SizeAndAlign(s).Size() > 24 && SizeAndAlign(s).Size()%8 == 0 -> 446 (LoweredMove 447 dst 448 src 449 (ADDconst <src.Type> src [SizeAndAlign(s).Size()-moveSize(SizeAndAlign(s).Align(), config)]) 450 mem) 451 452 // calls 453 (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem) 454 (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem) 455 (DeferCall [argwid] mem) -> (CALLdefer [argwid] mem) 456 (GoCall [argwid] mem) -> (CALLgo [argwid] mem) 457 (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem) 458 459 // checks 460 (NilCheck ptr mem) -> (LoweredNilCheck ptr mem) 461 (IsNonNil ptr) -> (NotEqual (CMPconst [0] ptr)) 462 (IsInBounds idx len) -> (LessThanU (CMP idx len)) 463 (IsSliceInBounds idx len) -> (LessEqualU (CMP idx len)) 464 465 // pseudo-ops 466 (GetClosurePtr) -> (LoweredGetClosurePtr) 467 (Convert x mem) -> (MOVDconvert x mem) 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 481 (If cond yes no) -> (NZ cond yes no) 482 483 // atomic intrinsics 484 // Note: these ops do not accept offset. 485 (AtomicLoad32 ptr mem) -> (LDARW ptr mem) 486 (AtomicLoad64 ptr mem) -> (LDAR ptr mem) 487 (AtomicLoadPtr ptr mem) -> (LDAR ptr mem) 488 489 (AtomicStore32 ptr val mem) -> (STLRW ptr val mem) 490 (AtomicStore64 ptr val mem) -> (STLR ptr val mem) 491 (AtomicStorePtrNoWB ptr val mem) -> (STLR ptr val mem) 492 493 (AtomicExchange32 ptr val mem) -> (LoweredAtomicExchange32 ptr val mem) 494 (AtomicExchange64 ptr val mem) -> (LoweredAtomicExchange64 ptr val mem) 495 496 (AtomicAdd32 ptr val mem) -> (LoweredAtomicAdd32 ptr val mem) 497 (AtomicAdd64 ptr val mem) -> (LoweredAtomicAdd64 ptr val mem) 498 499 (AtomicCompareAndSwap32 ptr old new_ mem) -> (LoweredAtomicCas32 ptr old new_ mem) 500 (AtomicCompareAndSwap64 ptr old new_ mem) -> (LoweredAtomicCas64 ptr old new_ mem) 501 502 (AtomicAnd8 ptr val mem) -> (LoweredAtomicAnd8 ptr val mem) 503 (AtomicOr8 ptr val mem) -> (LoweredAtomicOr8 ptr val mem) 504 505 // Optimizations 506 507 // Absorb boolean tests into block 508 (NZ (Equal cc) yes no) -> (EQ cc yes no) 509 (NZ (NotEqual cc) yes no) -> (NE cc yes no) 510 (NZ (LessThan cc) yes no) -> (LT cc yes no) 511 (NZ (LessThanU cc) yes no) -> (ULT cc yes no) 512 (NZ (LessEqual cc) yes no) -> (LE cc yes no) 513 (NZ (LessEqualU cc) yes no) -> (ULE cc yes no) 514 (NZ (GreaterThan cc) yes no) -> (GT cc yes no) 515 (NZ (GreaterThanU cc) yes no) -> (UGT cc yes no) 516 (NZ (GreaterEqual cc) yes no) -> (GE cc yes no) 517 (NZ (GreaterEqualU cc) yes no) -> (UGE cc yes no) 518 519 (EQ (CMPconst [0] x) yes no) -> (Z x yes no) 520 (NE (CMPconst [0] x) yes no) -> (NZ x yes no) 521 (EQ (CMPWconst [0] x) yes no) -> (ZW x yes no) 522 (NE (CMPWconst [0] x) yes no) -> (NZW x yes no) 523 524 // fold offset into address 525 (ADDconst [off1] (MOVDaddr [off2] {sym} ptr)) -> (MOVDaddr [off1+off2] {sym} ptr) 526 527 // fold address into load/store 528 // only small offset (between -256 and 256) or offset that is a multiple of data size 529 // can be encoded in the instructions 530 // since this rewriting takes place before stack allocation, the offset to SP is unknown, 531 // so don't do it for args and locals with unaligned offset 532 (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVBload [off1+off2] {sym} ptr mem) 533 (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVBUload [off1+off2] {sym} ptr mem) 534 (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) 535 && (off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 536 (MOVHload [off1+off2] {sym} ptr mem) 537 (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) 538 && (off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 539 (MOVHUload [off1+off2] {sym} ptr mem) 540 (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) 541 && (off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 542 (MOVWload [off1+off2] {sym} ptr mem) 543 (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) 544 && (off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 545 (MOVWUload [off1+off2] {sym} ptr mem) 546 (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) 547 && (off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 548 (MOVDload [off1+off2] {sym} ptr mem) 549 (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) 550 && (off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 551 (FMOVSload [off1+off2] {sym} ptr mem) 552 (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) 553 && (off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 554 (FMOVDload [off1+off2] {sym} ptr mem) 555 556 (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) -> (MOVBstore [off1+off2] {sym} ptr val mem) 557 (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) 558 && (off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 559 (MOVHstore [off1+off2] {sym} ptr val mem) 560 (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) 561 && (off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 562 (MOVWstore [off1+off2] {sym} ptr val mem) 563 (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) 564 && (off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 565 (MOVDstore [off1+off2] {sym} ptr val mem) 566 (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) 567 && (off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 568 (FMOVSstore [off1+off2] {sym} ptr val mem) 569 (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) 570 && (off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 571 (FMOVDstore [off1+off2] {sym} ptr val mem) 572 (MOVBstorezero [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVBstorezero [off1+off2] {sym} ptr mem) 573 (MOVHstorezero [off1] {sym} (ADDconst [off2] ptr) mem) 574 && (off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 575 (MOVHstorezero [off1+off2] {sym} ptr mem) 576 (MOVWstorezero [off1] {sym} (ADDconst [off2] ptr) mem) 577 && (off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 578 (MOVWstorezero [off1+off2] {sym} ptr mem) 579 (MOVDstorezero [off1] {sym} (ADDconst [off2] ptr) mem) 580 && (off1+off2)%2==8 || off1+off2<256 && off1+off2>-256 && !isArg(sym) && !isAuto(sym) -> 581 (MOVDstorezero [off1+off2] {sym} ptr mem) 582 583 (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 584 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 585 (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 586 (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 587 (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 588 && ((off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 589 (MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 590 (MOVHUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 591 && ((off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 592 (MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 593 (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 594 && ((off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 595 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 596 (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 597 && ((off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 598 (MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 599 (MOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 600 && ((off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 601 (MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 602 (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 603 && ((off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 604 (FMOVSload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 605 (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 606 && ((off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 607 (FMOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 608 609 (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) -> 610 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 611 (MOVHstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) 612 && ((off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 613 (MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 614 (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) 615 && ((off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 616 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 617 (MOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) 618 && ((off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 619 (MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 620 (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) 621 && ((off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 622 (FMOVSstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 623 (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) 624 && ((off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 625 (FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 626 (MOVBstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 627 (MOVBstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 628 (MOVHstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 629 && ((off1+off2)%2==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 630 (MOVHstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 631 (MOVWstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 632 && ((off1+off2)%4==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 633 (MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 634 (MOVDstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) 635 && ((off1+off2)%8==0 || off1+off2<256 && off1+off2>-256 && !isArg(sym1) && !isAuto(sym1)) -> 636 (MOVDstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 637 638 // store zero 639 (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVBstorezero [off] {sym} ptr mem) 640 (MOVHstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVHstorezero [off] {sym} ptr mem) 641 (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVWstorezero [off] {sym} ptr mem) 642 (MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVDstorezero [off] {sym} ptr mem) 643 644 // replace load from same location as preceding store with copy 645 // these seem to have bad interaction with other rules, resulting in slower code 646 //(MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 647 //(MOVBUload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 648 //(MOVHload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 649 //(MOVHUload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 650 //(MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 651 //(MOVWUload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 652 //(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 653 //(FMOVSload [off] {sym} ptr (FMOVSstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 654 //(FMOVDload [off] {sym} ptr (FMOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 655 656 (MOVBload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 657 (MOVBUload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 658 (MOVHload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 659 (MOVHUload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 660 (MOVWload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 661 (MOVWUload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 662 (MOVDload [off] {sym} ptr (MOVDstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0]) 663 664 // don't extend after proper load 665 (MOVBreg x:(MOVBload _ _)) -> (MOVDreg x) 666 (MOVBUreg x:(MOVBUload _ _)) -> (MOVDreg x) 667 (MOVHreg x:(MOVBload _ _)) -> (MOVDreg x) 668 (MOVHreg x:(MOVBUload _ _)) -> (MOVDreg x) 669 (MOVHreg x:(MOVHload _ _)) -> (MOVDreg x) 670 (MOVHUreg x:(MOVBUload _ _)) -> (MOVDreg x) 671 (MOVHUreg x:(MOVHUload _ _)) -> (MOVDreg x) 672 (MOVWreg x:(MOVBload _ _)) -> (MOVDreg x) 673 (MOVWreg x:(MOVBUload _ _)) -> (MOVDreg x) 674 (MOVWreg x:(MOVHload _ _)) -> (MOVDreg x) 675 (MOVWreg x:(MOVHUload _ _)) -> (MOVDreg x) 676 (MOVWreg x:(MOVWload _ _)) -> (MOVDreg x) 677 (MOVWUreg x:(MOVBUload _ _)) -> (MOVDreg x) 678 (MOVWUreg x:(MOVHUload _ _)) -> (MOVDreg x) 679 (MOVWUreg x:(MOVWUload _ _)) -> (MOVDreg x) 680 681 // fold double extensions 682 (MOVBreg x:(MOVBreg _)) -> (MOVDreg x) 683 (MOVBUreg x:(MOVBUreg _)) -> (MOVDreg x) 684 (MOVHreg x:(MOVBreg _)) -> (MOVDreg x) 685 (MOVHreg x:(MOVBUreg _)) -> (MOVDreg x) 686 (MOVHreg x:(MOVHreg _)) -> (MOVDreg x) 687 (MOVHUreg x:(MOVBUreg _)) -> (MOVDreg x) 688 (MOVHUreg x:(MOVHUreg _)) -> (MOVDreg x) 689 (MOVWreg x:(MOVBreg _)) -> (MOVDreg x) 690 (MOVWreg x:(MOVBUreg _)) -> (MOVDreg x) 691 (MOVWreg x:(MOVHreg _)) -> (MOVDreg x) 692 (MOVWreg x:(MOVHreg _)) -> (MOVDreg x) 693 (MOVWreg x:(MOVWreg _)) -> (MOVDreg x) 694 (MOVWUreg x:(MOVBUreg _)) -> (MOVDreg x) 695 (MOVWUreg x:(MOVHUreg _)) -> (MOVDreg x) 696 (MOVWUreg x:(MOVWUreg _)) -> (MOVDreg x) 697 698 // don't extend before store 699 (MOVBstore [off] {sym} ptr (MOVBreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 700 (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 701 (MOVBstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 702 (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 703 (MOVBstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 704 (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 705 (MOVHstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 706 (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 707 (MOVHstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 708 (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 709 (MOVWstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVWstore [off] {sym} ptr x mem) 710 (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) -> (MOVWstore [off] {sym} ptr x mem) 711 712 // if a register move has only 1 use, just use the same register without emitting instruction 713 // MOVDnop doesn't emit instruction, only for ensuring the type. 714 (MOVDreg x) && x.Uses == 1 -> (MOVDnop x) 715 716 // fold constant into arithmatic ops 717 (ADD (MOVDconst [c]) x) -> (ADDconst [c] x) 718 (ADD x (MOVDconst [c])) -> (ADDconst [c] x) 719 (SUB x (MOVDconst [c])) -> (SUBconst [c] x) 720 (AND (MOVDconst [c]) x) -> (ANDconst [c] x) 721 (AND x (MOVDconst [c])) -> (ANDconst [c] x) 722 (OR (MOVDconst [c]) x) -> (ORconst [c] x) 723 (OR x (MOVDconst [c])) -> (ORconst [c] x) 724 (XOR (MOVDconst [c]) x) -> (XORconst [c] x) 725 (XOR x (MOVDconst [c])) -> (XORconst [c] x) 726 (BIC x (MOVDconst [c])) -> (BICconst [c] x) 727 728 (SLL x (MOVDconst [c])) -> (SLLconst x [c&63]) // Note: I don't think we ever generate bad constant shifts (i.e. c>=64) 729 (SRL x (MOVDconst [c])) -> (SRLconst x [c&63]) 730 (SRA x (MOVDconst [c])) -> (SRAconst x [c&63]) 731 732 (CMP x (MOVDconst [c])) -> (CMPconst [c] x) 733 (CMP (MOVDconst [c]) x) -> (InvertFlags (CMPconst [c] x)) 734 (CMPW x (MOVDconst [c])) -> (CMPWconst [int64(int32(c))] x) 735 (CMPW (MOVDconst [c]) x) -> (InvertFlags (CMPWconst [int64(int32(c))] x)) 736 737 // mul by constant 738 (MUL x (MOVDconst [-1])) -> (NEG x) 739 (MUL _ (MOVDconst [0])) -> (MOVDconst [0]) 740 (MUL x (MOVDconst [1])) -> x 741 (MUL x (MOVDconst [c])) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x) 742 (MUL x (MOVDconst [c])) && isPowerOfTwo(c-1) && c >= 3 -> (ADDshiftLL x x [log2(c-1)]) 743 (MUL x (MOVDconst [c])) && isPowerOfTwo(c+1) && c >= 7 -> (ADDshiftLL (NEG <x.Type> x) x [log2(c+1)]) 744 (MUL x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) 745 (MUL x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) 746 (MUL x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) -> (SLLconst [log2(c/7)] (ADDshiftLL <x.Type> (NEG <x.Type> x) x [3])) 747 (MUL x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) 748 749 (MUL (MOVDconst [-1]) x) -> (NEG x) 750 (MUL (MOVDconst [0]) _) -> (MOVDconst [0]) 751 (MUL (MOVDconst [1]) x) -> x 752 (MUL (MOVDconst [c]) x) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x) 753 (MUL (MOVDconst [c]) x) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x) 754 (MUL (MOVDconst [c]) x) && isPowerOfTwo(c-1) && c >= 3 -> (ADDshiftLL x x [log2(c-1)]) 755 (MUL (MOVDconst [c]) x) && isPowerOfTwo(c+1) && c >= 7 -> (ADDshiftLL (NEG <x.Type> x) x [log2(c+1)]) 756 (MUL (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) 757 (MUL (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) 758 (MUL (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) -> (SLLconst [log2(c/7)] (ADDshiftLL <x.Type> (NEG <x.Type> x) x [3])) 759 (MUL (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) 760 761 (MULW x (MOVDconst [c])) && int32(c)==-1 -> (NEG x) 762 (MULW _ (MOVDconst [c])) && int32(c)==0 -> (MOVDconst [0]) 763 (MULW x (MOVDconst [c])) && int32(c)==1 -> x 764 (MULW x (MOVDconst [c])) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x) 765 (MULW x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (ADDshiftLL x x [log2(c-1)]) 766 (MULW x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (ADDshiftLL (NEG <x.Type> x) x [log2(c+1)]) 767 (MULW x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) 768 (MULW x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) 769 (MULW x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SLLconst [log2(c/7)] (ADDshiftLL <x.Type> (NEG <x.Type> x) x [3])) 770 (MULW x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) 771 772 (MULW (MOVDconst [c]) x) && int32(c)==-1 -> (NEG x) 773 (MULW (MOVDconst [c]) _) && int32(c)==0 -> (MOVDconst [0]) 774 (MULW (MOVDconst [c]) x) && int32(c)==1 -> x 775 (MULW (MOVDconst [c]) x) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x) 776 (MULW (MOVDconst [c]) x) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (ADDshiftLL x x [log2(c-1)]) 777 (MULW (MOVDconst [c]) x) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (ADDshiftLL (NEG <x.Type> x) x [log2(c+1)]) 778 (MULW (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) 779 (MULW (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) 780 (MULW (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SLLconst [log2(c/7)] (ADDshiftLL <x.Type> (NEG <x.Type> x) x [3])) 781 (MULW (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) 782 783 // div by constant 784 (UDIV x (MOVDconst [1])) -> x 785 (UDIV x (MOVDconst [c])) && isPowerOfTwo(c) -> (SRLconst [log2(c)] x) 786 (UDIVW x (MOVDconst [c])) && uint32(c)==1 -> x 787 (UDIVW x (MOVDconst [c])) && isPowerOfTwo(c) && is32Bit(c) -> (SRLconst [log2(c)] x) 788 (UMOD _ (MOVDconst [1])) -> (MOVDconst [0]) 789 (UMOD x (MOVDconst [c])) && isPowerOfTwo(c) -> (ANDconst [c-1] x) 790 (UMODW _ (MOVDconst [c])) && uint32(c)==1 -> (MOVDconst [0]) 791 (UMODW x (MOVDconst [c])) && isPowerOfTwo(c) && is32Bit(c) -> (ANDconst [c-1] x) 792 793 // generic simplifications 794 (ADD x (NEG y)) -> (SUB x y) 795 (ADD (NEG y) x) -> (SUB x y) 796 (SUB x x) -> (MOVDconst [0]) 797 (AND x x) -> x 798 (OR x x) -> x 799 (XOR x x) -> (MOVDconst [0]) 800 (BIC x x) -> (MOVDconst [0]) 801 (AND x (MVN y)) -> (BIC x y) 802 (CSELULT x (MOVDconst [0]) flag) -> (CSELULT0 x flag) 803 804 // remove redundant *const ops 805 (ADDconst [0] x) -> x 806 (SUBconst [0] x) -> x 807 (ANDconst [0] _) -> (MOVDconst [0]) 808 (ANDconst [-1] x) -> x 809 (ORconst [0] x) -> x 810 (ORconst [-1] _) -> (MOVDconst [-1]) 811 (XORconst [0] x) -> x 812 (XORconst [-1] x) -> (MVN x) 813 (BICconst [0] x) -> x 814 (BICconst [-1] _) -> (MOVDconst [0]) 815 816 // generic constant folding 817 (ADDconst [c] (MOVDconst [d])) -> (MOVDconst [c+d]) 818 (ADDconst [c] (ADDconst [d] x)) -> (ADDconst [c+d] x) 819 (ADDconst [c] (SUBconst [d] x)) -> (ADDconst [c-d] x) 820 (SUBconst [c] (MOVDconst [d])) -> (MOVDconst [d-c]) 821 (SUBconst [c] (SUBconst [d] x)) -> (ADDconst [-c-d] x) 822 (SUBconst [c] (ADDconst [d] x)) -> (ADDconst [-c+d] x) 823 (SLLconst [c] (MOVDconst [d])) -> (MOVDconst [int64(d)<<uint64(c)]) 824 (SRLconst [c] (MOVDconst [d])) -> (MOVDconst [int64(uint64(d)>>uint64(c))]) 825 (SRAconst [c] (MOVDconst [d])) -> (MOVDconst [int64(d)>>uint64(c)]) 826 (MUL (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [c*d]) 827 (MULW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)*int32(d))]) 828 (DIV (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(c)/int64(d)]) 829 (UDIV (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint64(c)/uint64(d))]) 830 (DIVW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)/int32(d))]) 831 (UDIVW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint32(c)/uint32(d))]) 832 (MOD (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(c)%int64(d)]) 833 (UMOD (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint64(c)%uint64(d))]) 834 (MODW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)%int32(d))]) 835 (UMODW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint32(c)%uint32(d))]) 836 (ANDconst [c] (MOVDconst [d])) -> (MOVDconst [c&d]) 837 (ANDconst [c] (ANDconst [d] x)) -> (ANDconst [c&d] x) 838 (ORconst [c] (MOVDconst [d])) -> (MOVDconst [c|d]) 839 (ORconst [c] (ORconst [d] x)) -> (ORconst [c|d] x) 840 (XORconst [c] (MOVDconst [d])) -> (MOVDconst [c^d]) 841 (XORconst [c] (XORconst [d] x)) -> (XORconst [c^d] x) 842 (BICconst [c] (MOVDconst [d])) -> (MOVDconst [d&^c]) 843 (MVN (MOVDconst [c])) -> (MOVDconst [^c]) 844 (NEG (MOVDconst [c])) -> (MOVDconst [-c]) 845 (MOVBreg (MOVDconst [c])) -> (MOVDconst [int64(int8(c))]) 846 (MOVBUreg (MOVDconst [c])) -> (MOVDconst [int64(uint8(c))]) 847 (MOVHreg (MOVDconst [c])) -> (MOVDconst [int64(int16(c))]) 848 (MOVHUreg (MOVDconst [c])) -> (MOVDconst [int64(uint16(c))]) 849 (MOVWreg (MOVDconst [c])) -> (MOVDconst [int64(int32(c))]) 850 (MOVWUreg (MOVDconst [c])) -> (MOVDconst [int64(uint32(c))]) 851 (MOVDreg (MOVDconst [c])) -> (MOVDconst [c]) 852 853 // constant comparisons 854 (CMPconst (MOVDconst [x]) [y]) && x==y -> (FlagEQ) 855 (CMPconst (MOVDconst [x]) [y]) && int64(x)<int64(y) && uint64(x)<uint64(y) -> (FlagLT_ULT) 856 (CMPconst (MOVDconst [x]) [y]) && int64(x)<int64(y) && uint64(x)>uint64(y) -> (FlagLT_UGT) 857 (CMPconst (MOVDconst [x]) [y]) && int64(x)>int64(y) && uint64(x)<uint64(y) -> (FlagGT_ULT) 858 (CMPconst (MOVDconst [x]) [y]) && int64(x)>int64(y) && uint64(x)>uint64(y) -> (FlagGT_UGT) 859 (CMPWconst (MOVDconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ) 860 (CMPWconst (MOVDconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT) 861 (CMPWconst (MOVDconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT) 862 (CMPWconst (MOVDconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT) 863 (CMPWconst (MOVDconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT) 864 865 // other known comparisons 866 (CMPconst (MOVBUreg _) [c]) && 0xff < c -> (FlagLT_ULT) 867 (CMPconst (MOVHUreg _) [c]) && 0xffff < c -> (FlagLT_ULT) 868 (CMPconst (MOVWUreg _) [c]) && 0xffffffff < c -> (FlagLT_ULT) 869 (CMPconst (ANDconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 870 (CMPconst (SRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 63 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT) 871 (CMPWconst (MOVBUreg _) [c]) && 0xff < int32(c) -> (FlagLT_ULT) 872 (CMPWconst (MOVHUreg _) [c]) && 0xffff < int32(c) -> (FlagLT_ULT) 873 874 // absorb flag constants into branches 875 (EQ (FlagEQ) yes no) -> (First nil yes no) 876 (EQ (FlagLT_ULT) yes no) -> (First nil no yes) 877 (EQ (FlagLT_UGT) yes no) -> (First nil no yes) 878 (EQ (FlagGT_ULT) yes no) -> (First nil no yes) 879 (EQ (FlagGT_UGT) yes no) -> (First nil no yes) 880 881 (NE (FlagEQ) yes no) -> (First nil no yes) 882 (NE (FlagLT_ULT) yes no) -> (First nil yes no) 883 (NE (FlagLT_UGT) yes no) -> (First nil yes no) 884 (NE (FlagGT_ULT) yes no) -> (First nil yes no) 885 (NE (FlagGT_UGT) yes no) -> (First nil yes no) 886 887 (LT (FlagEQ) yes no) -> (First nil no yes) 888 (LT (FlagLT_ULT) yes no) -> (First nil yes no) 889 (LT (FlagLT_UGT) yes no) -> (First nil yes no) 890 (LT (FlagGT_ULT) yes no) -> (First nil no yes) 891 (LT (FlagGT_UGT) yes no) -> (First nil no yes) 892 893 (LE (FlagEQ) yes no) -> (First nil yes no) 894 (LE (FlagLT_ULT) yes no) -> (First nil yes no) 895 (LE (FlagLT_UGT) yes no) -> (First nil yes no) 896 (LE (FlagGT_ULT) yes no) -> (First nil no yes) 897 (LE (FlagGT_UGT) yes no) -> (First nil no yes) 898 899 (GT (FlagEQ) yes no) -> (First nil no yes) 900 (GT (FlagLT_ULT) yes no) -> (First nil no yes) 901 (GT (FlagLT_UGT) yes no) -> (First nil no yes) 902 (GT (FlagGT_ULT) yes no) -> (First nil yes no) 903 (GT (FlagGT_UGT) yes no) -> (First nil yes no) 904 905 (GE (FlagEQ) yes no) -> (First nil yes no) 906 (GE (FlagLT_ULT) yes no) -> (First nil no yes) 907 (GE (FlagLT_UGT) yes no) -> (First nil no yes) 908 (GE (FlagGT_ULT) yes no) -> (First nil yes no) 909 (GE (FlagGT_UGT) yes no) -> (First nil yes no) 910 911 (ULT (FlagEQ) yes no) -> (First nil no yes) 912 (ULT (FlagLT_ULT) yes no) -> (First nil yes no) 913 (ULT (FlagLT_UGT) yes no) -> (First nil no yes) 914 (ULT (FlagGT_ULT) yes no) -> (First nil yes no) 915 (ULT (FlagGT_UGT) yes no) -> (First nil no yes) 916 917 (ULE (FlagEQ) yes no) -> (First nil yes no) 918 (ULE (FlagLT_ULT) yes no) -> (First nil yes no) 919 (ULE (FlagLT_UGT) yes no) -> (First nil no yes) 920 (ULE (FlagGT_ULT) yes no) -> (First nil yes no) 921 (ULE (FlagGT_UGT) yes no) -> (First nil no yes) 922 923 (UGT (FlagEQ) yes no) -> (First nil no yes) 924 (UGT (FlagLT_ULT) yes no) -> (First nil no yes) 925 (UGT (FlagLT_UGT) yes no) -> (First nil yes no) 926 (UGT (FlagGT_ULT) yes no) -> (First nil no yes) 927 (UGT (FlagGT_UGT) yes no) -> (First nil yes no) 928 929 (UGE (FlagEQ) yes no) -> (First nil yes no) 930 (UGE (FlagLT_ULT) yes no) -> (First nil no yes) 931 (UGE (FlagLT_UGT) yes no) -> (First nil yes no) 932 (UGE (FlagGT_ULT) yes no) -> (First nil no yes) 933 (UGE (FlagGT_UGT) yes no) -> (First nil yes no) 934 935 (Z (MOVDconst [0]) yes no) -> (First nil yes no) 936 (Z (MOVDconst [c]) yes no) && c != 0 -> (First nil no yes) 937 (NZ (MOVDconst [0]) yes no) -> (First nil no yes) 938 (NZ (MOVDconst [c]) yes no) && c != 0 -> (First nil yes no) 939 (ZW (MOVDconst [c]) yes no) && int32(c) == 0 -> (First nil yes no) 940 (ZW (MOVDconst [c]) yes no) && int32(c) != 0 -> (First nil no yes) 941 (NZW (MOVDconst [c]) yes no) && int32(c) == 0 -> (First nil no yes) 942 (NZW (MOVDconst [c]) yes no) && int32(c) != 0 -> (First nil yes no) 943 944 // absorb InvertFlags into branches 945 (LT (InvertFlags cmp) yes no) -> (GT cmp yes no) 946 (GT (InvertFlags cmp) yes no) -> (LT cmp yes no) 947 (LE (InvertFlags cmp) yes no) -> (GE cmp yes no) 948 (GE (InvertFlags cmp) yes no) -> (LE cmp yes no) 949 (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no) 950 (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no) 951 (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no) 952 (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no) 953 (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no) 954 (NE (InvertFlags cmp) yes no) -> (NE cmp yes no) 955 956 // absorb flag constants into boolean values 957 (Equal (FlagEQ)) -> (MOVDconst [1]) 958 (Equal (FlagLT_ULT)) -> (MOVDconst [0]) 959 (Equal (FlagLT_UGT)) -> (MOVDconst [0]) 960 (Equal (FlagGT_ULT)) -> (MOVDconst [0]) 961 (Equal (FlagGT_UGT)) -> (MOVDconst [0]) 962 963 (NotEqual (FlagEQ)) -> (MOVDconst [0]) 964 (NotEqual (FlagLT_ULT)) -> (MOVDconst [1]) 965 (NotEqual (FlagLT_UGT)) -> (MOVDconst [1]) 966 (NotEqual (FlagGT_ULT)) -> (MOVDconst [1]) 967 (NotEqual (FlagGT_UGT)) -> (MOVDconst [1]) 968 969 (LessThan (FlagEQ)) -> (MOVDconst [0]) 970 (LessThan (FlagLT_ULT)) -> (MOVDconst [1]) 971 (LessThan (FlagLT_UGT)) -> (MOVDconst [1]) 972 (LessThan (FlagGT_ULT)) -> (MOVDconst [0]) 973 (LessThan (FlagGT_UGT)) -> (MOVDconst [0]) 974 975 (LessThanU (FlagEQ)) -> (MOVDconst [0]) 976 (LessThanU (FlagLT_ULT)) -> (MOVDconst [1]) 977 (LessThanU (FlagLT_UGT)) -> (MOVDconst [0]) 978 (LessThanU (FlagGT_ULT)) -> (MOVDconst [1]) 979 (LessThanU (FlagGT_UGT)) -> (MOVDconst [0]) 980 981 (LessEqual (FlagEQ)) -> (MOVDconst [1]) 982 (LessEqual (FlagLT_ULT)) -> (MOVDconst [1]) 983 (LessEqual (FlagLT_UGT)) -> (MOVDconst [1]) 984 (LessEqual (FlagGT_ULT)) -> (MOVDconst [0]) 985 (LessEqual (FlagGT_UGT)) -> (MOVDconst [0]) 986 987 (LessEqualU (FlagEQ)) -> (MOVDconst [1]) 988 (LessEqualU (FlagLT_ULT)) -> (MOVDconst [1]) 989 (LessEqualU (FlagLT_UGT)) -> (MOVDconst [0]) 990 (LessEqualU (FlagGT_ULT)) -> (MOVDconst [1]) 991 (LessEqualU (FlagGT_UGT)) -> (MOVDconst [0]) 992 993 (GreaterThan (FlagEQ)) -> (MOVDconst [0]) 994 (GreaterThan (FlagLT_ULT)) -> (MOVDconst [0]) 995 (GreaterThan (FlagLT_UGT)) -> (MOVDconst [0]) 996 (GreaterThan (FlagGT_ULT)) -> (MOVDconst [1]) 997 (GreaterThan (FlagGT_UGT)) -> (MOVDconst [1]) 998 999 (GreaterThanU (FlagEQ)) -> (MOVDconst [0]) 1000 (GreaterThanU (FlagLT_ULT)) -> (MOVDconst [0]) 1001 (GreaterThanU (FlagLT_UGT)) -> (MOVDconst [1]) 1002 (GreaterThanU (FlagGT_ULT)) -> (MOVDconst [0]) 1003 (GreaterThanU (FlagGT_UGT)) -> (MOVDconst [1]) 1004 1005 (GreaterEqual (FlagEQ)) -> (MOVDconst [1]) 1006 (GreaterEqual (FlagLT_ULT)) -> (MOVDconst [0]) 1007 (GreaterEqual (FlagLT_UGT)) -> (MOVDconst [0]) 1008 (GreaterEqual (FlagGT_ULT)) -> (MOVDconst [1]) 1009 (GreaterEqual (FlagGT_UGT)) -> (MOVDconst [1]) 1010 1011 (GreaterEqualU (FlagEQ)) -> (MOVDconst [1]) 1012 (GreaterEqualU (FlagLT_ULT)) -> (MOVDconst [0]) 1013 (GreaterEqualU (FlagLT_UGT)) -> (MOVDconst [1]) 1014 (GreaterEqualU (FlagGT_ULT)) -> (MOVDconst [0]) 1015 (GreaterEqualU (FlagGT_UGT)) -> (MOVDconst [1]) 1016 1017 // absorb InvertFlags into boolean values 1018 (Equal (InvertFlags x)) -> (Equal x) 1019 (NotEqual (InvertFlags x)) -> (NotEqual x) 1020 (LessThan (InvertFlags x)) -> (GreaterThan x) 1021 (LessThanU (InvertFlags x)) -> (GreaterThanU x) 1022 (GreaterThan (InvertFlags x)) -> (LessThan x) 1023 (GreaterThanU (InvertFlags x)) -> (LessThanU x) 1024 (LessEqual (InvertFlags x)) -> (GreaterEqual x) 1025 (LessEqualU (InvertFlags x)) -> (GreaterEqualU x) 1026 (GreaterEqual (InvertFlags x)) -> (LessEqual x) 1027 (GreaterEqualU (InvertFlags x)) -> (LessEqualU x) 1028 1029 // absorb flag constants into conditional instructions 1030 (CSELULT _ y (FlagEQ)) -> y 1031 (CSELULT x _ (FlagLT_ULT)) -> x 1032 (CSELULT _ y (FlagLT_UGT)) -> y 1033 (CSELULT x _ (FlagGT_ULT)) -> x 1034 (CSELULT _ y (FlagGT_UGT)) -> y 1035 (CSELULT0 _ (FlagEQ)) -> (MOVDconst [0]) 1036 (CSELULT0 x (FlagLT_ULT)) -> x 1037 (CSELULT0 _ (FlagLT_UGT)) -> (MOVDconst [0]) 1038 (CSELULT0 x (FlagGT_ULT)) -> x 1039 (CSELULT0 _ (FlagGT_UGT)) -> (MOVDconst [0]) 1040 1041 // absorb shifts into ops 1042 (ADD x (SLLconst [c] y)) -> (ADDshiftLL x y [c]) 1043 (ADD (SLLconst [c] y) x) -> (ADDshiftLL x y [c]) 1044 (ADD x (SRLconst [c] y)) -> (ADDshiftRL x y [c]) 1045 (ADD (SRLconst [c] y) x) -> (ADDshiftRL x y [c]) 1046 (ADD x (SRAconst [c] y)) -> (ADDshiftRA x y [c]) 1047 (ADD (SRAconst [c] y) x) -> (ADDshiftRA x y [c]) 1048 (SUB x (SLLconst [c] y)) -> (SUBshiftLL x y [c]) 1049 (SUB x (SRLconst [c] y)) -> (SUBshiftRL x y [c]) 1050 (SUB x (SRAconst [c] y)) -> (SUBshiftRA x y [c]) 1051 (AND x (SLLconst [c] y)) -> (ANDshiftLL x y [c]) 1052 (AND (SLLconst [c] y) x) -> (ANDshiftLL x y [c]) 1053 (AND x (SRLconst [c] y)) -> (ANDshiftRL x y [c]) 1054 (AND (SRLconst [c] y) x) -> (ANDshiftRL x y [c]) 1055 (AND x (SRAconst [c] y)) -> (ANDshiftRA x y [c]) 1056 (AND (SRAconst [c] y) x) -> (ANDshiftRA x y [c]) 1057 (OR x s:(SLLconst [c] y)) && s.Uses == 1 && clobber(s) -> (ORshiftLL x y [c]) // useful for combined load 1058 (OR s:(SLLconst [c] y) x) && s.Uses == 1 && clobber(s) -> (ORshiftLL x y [c]) 1059 (OR x (SLLconst [c] y)) -> (ORshiftLL x y [c]) 1060 (OR (SLLconst [c] y) x) -> (ORshiftLL x y [c]) 1061 (OR x (SRLconst [c] y)) -> (ORshiftRL x y [c]) 1062 (OR (SRLconst [c] y) x) -> (ORshiftRL x y [c]) 1063 (OR x (SRAconst [c] y)) -> (ORshiftRA x y [c]) 1064 (OR (SRAconst [c] y) x) -> (ORshiftRA x y [c]) 1065 (XOR x (SLLconst [c] y)) -> (XORshiftLL x y [c]) 1066 (XOR (SLLconst [c] y) x) -> (XORshiftLL x y [c]) 1067 (XOR x (SRLconst [c] y)) -> (XORshiftRL x y [c]) 1068 (XOR (SRLconst [c] y) x) -> (XORshiftRL x y [c]) 1069 (XOR x (SRAconst [c] y)) -> (XORshiftRA x y [c]) 1070 (XOR (SRAconst [c] y) x) -> (XORshiftRA x y [c]) 1071 (BIC x (SLLconst [c] y)) -> (BICshiftLL x y [c]) 1072 (BIC x (SRLconst [c] y)) -> (BICshiftRL x y [c]) 1073 (BIC x (SRAconst [c] y)) -> (BICshiftRA x y [c]) 1074 (CMP x (SLLconst [c] y)) -> (CMPshiftLL x y [c]) 1075 (CMP (SLLconst [c] y) x) -> (InvertFlags (CMPshiftLL x y [c])) 1076 (CMP x (SRLconst [c] y)) -> (CMPshiftRL x y [c]) 1077 (CMP (SRLconst [c] y) x) -> (InvertFlags (CMPshiftRL x y [c])) 1078 (CMP x (SRAconst [c] y)) -> (CMPshiftRA x y [c]) 1079 (CMP (SRAconst [c] y) x) -> (InvertFlags (CMPshiftRA x y [c])) 1080 1081 // prefer *const ops to *shift ops 1082 (ADDshiftLL (MOVDconst [c]) x [d]) -> (ADDconst [c] (SLLconst <x.Type> x [d])) 1083 (ADDshiftRL (MOVDconst [c]) x [d]) -> (ADDconst [c] (SRLconst <x.Type> x [d])) 1084 (ADDshiftRA (MOVDconst [c]) x [d]) -> (ADDconst [c] (SRAconst <x.Type> x [d])) 1085 (ANDshiftLL (MOVDconst [c]) x [d]) -> (ANDconst [c] (SLLconst <x.Type> x [d])) 1086 (ANDshiftRL (MOVDconst [c]) x [d]) -> (ANDconst [c] (SRLconst <x.Type> x [d])) 1087 (ANDshiftRA (MOVDconst [c]) x [d]) -> (ANDconst [c] (SRAconst <x.Type> x [d])) 1088 (ORshiftLL (MOVDconst [c]) x [d]) -> (ORconst [c] (SLLconst <x.Type> x [d])) 1089 (ORshiftRL (MOVDconst [c]) x [d]) -> (ORconst [c] (SRLconst <x.Type> x [d])) 1090 (ORshiftRA (MOVDconst [c]) x [d]) -> (ORconst [c] (SRAconst <x.Type> x [d])) 1091 (XORshiftLL (MOVDconst [c]) x [d]) -> (XORconst [c] (SLLconst <x.Type> x [d])) 1092 (XORshiftRL (MOVDconst [c]) x [d]) -> (XORconst [c] (SRLconst <x.Type> x [d])) 1093 (XORshiftRA (MOVDconst [c]) x [d]) -> (XORconst [c] (SRAconst <x.Type> x [d])) 1094 (CMPshiftLL (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SLLconst <x.Type> x [d]))) 1095 (CMPshiftRL (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRLconst <x.Type> x [d]))) 1096 (CMPshiftRA (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRAconst <x.Type> x [d]))) 1097 1098 // constant folding in *shift ops 1099 (ADDshiftLL x (MOVDconst [c]) [d]) -> (ADDconst x [int64(uint64(c)<<uint64(d))]) 1100 (ADDshiftRL x (MOVDconst [c]) [d]) -> (ADDconst x [int64(uint64(c)>>uint64(d))]) 1101 (ADDshiftRA x (MOVDconst [c]) [d]) -> (ADDconst x [int64(int64(c)>>uint64(d))]) 1102 (SUBshiftLL x (MOVDconst [c]) [d]) -> (SUBconst x [int64(uint64(c)<<uint64(d))]) 1103 (SUBshiftRL x (MOVDconst [c]) [d]) -> (SUBconst x [int64(uint64(c)>>uint64(d))]) 1104 (SUBshiftRA x (MOVDconst [c]) [d]) -> (SUBconst x [int64(int64(c)>>uint64(d))]) 1105 (ANDshiftLL x (MOVDconst [c]) [d]) -> (ANDconst x [int64(uint64(c)<<uint64(d))]) 1106 (ANDshiftRL x (MOVDconst [c]) [d]) -> (ANDconst x [int64(uint64(c)>>uint64(d))]) 1107 (ANDshiftRA x (MOVDconst [c]) [d]) -> (ANDconst x [int64(int64(c)>>uint64(d))]) 1108 (ORshiftLL x (MOVDconst [c]) [d]) -> (ORconst x [int64(uint64(c)<<uint64(d))]) 1109 (ORshiftRL x (MOVDconst [c]) [d]) -> (ORconst x [int64(uint64(c)>>uint64(d))]) 1110 (ORshiftRA x (MOVDconst [c]) [d]) -> (ORconst x [int64(int64(c)>>uint64(d))]) 1111 (XORshiftLL x (MOVDconst [c]) [d]) -> (XORconst x [int64(uint64(c)<<uint64(d))]) 1112 (XORshiftRL x (MOVDconst [c]) [d]) -> (XORconst x [int64(uint64(c)>>uint64(d))]) 1113 (XORshiftRA x (MOVDconst [c]) [d]) -> (XORconst x [int64(int64(c)>>uint64(d))]) 1114 (BICshiftLL x (MOVDconst [c]) [d]) -> (BICconst x [int64(uint64(c)<<uint64(d))]) 1115 (BICshiftRL x (MOVDconst [c]) [d]) -> (BICconst x [int64(uint64(c)>>uint64(d))]) 1116 (BICshiftRA x (MOVDconst [c]) [d]) -> (BICconst x [int64(int64(c)>>uint64(d))]) 1117 (CMPshiftLL x (MOVDconst [c]) [d]) -> (CMPconst x [int64(uint64(c)<<uint64(d))]) 1118 (CMPshiftRL x (MOVDconst [c]) [d]) -> (CMPconst x [int64(uint64(c)>>uint64(d))]) 1119 (CMPshiftRA x (MOVDconst [c]) [d]) -> (CMPconst x [int64(int64(c)>>uint64(d))]) 1120 1121 // simplification with *shift ops 1122 (SUBshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1123 (SUBshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1124 (SUBshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1125 (ANDshiftLL x y:(SLLconst x [c]) [d]) && c==d -> y 1126 (ANDshiftRL x y:(SRLconst x [c]) [d]) && c==d -> y 1127 (ANDshiftRA x y:(SRAconst x [c]) [d]) && c==d -> y 1128 (ORshiftLL x y:(SLLconst x [c]) [d]) && c==d -> y 1129 (ORshiftRL x y:(SRLconst x [c]) [d]) && c==d -> y 1130 (ORshiftRA x y:(SRAconst x [c]) [d]) && c==d -> y 1131 (XORshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1132 (XORshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1133 (XORshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1134 (BICshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1135 (BICshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1136 (BICshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [0]) 1137 1138 // do combined loads 1139 // little endian loads 1140 // b[0] | b[1]<<8 -> load 16-bit 1141 (ORshiftLL <t> [8] 1142 y0:(MOVDnop x0:(MOVBUload [i] {s} p mem)) 1143 y1:(MOVDnop x1:(MOVBUload [i+1] {s} p mem))) 1144 && x0.Uses == 1 && x1.Uses == 1 1145 && y0.Uses == 1 && y1.Uses == 1 1146 && mergePoint(b,x0,x1) != nil 1147 && clobber(x0) && clobber(x1) 1148 && clobber(y0) && clobber(y1) 1149 -> @mergePoint(b,x0,x1) (MOVHUload <t> {s} (OffPtr <p.Type> [i] p) mem) 1150 1151 // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 -> load 32-bit 1152 (ORshiftLL <t> [24] o0:(ORshiftLL [16] 1153 x0:(MOVHUload [i] {s} p mem) 1154 y1:(MOVDnop x1:(MOVBUload [i+2] {s} p mem))) 1155 y2:(MOVDnop x2:(MOVBUload [i+3] {s} p mem))) 1156 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 1157 && y1.Uses == 1 && y2.Uses == 1 1158 && o0.Uses == 1 1159 && mergePoint(b,x0,x1,x2) != nil 1160 && clobber(x0) && clobber(x1) && clobber(x2) 1161 && clobber(y1) && clobber(y2) 1162 && clobber(o0) 1163 -> @mergePoint(b,x0,x1,x2) (MOVWUload <t> {s} (OffPtr <p.Type> [i] p) mem) 1164 1165 // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 | b[4]<<32 | b[5]<<40 | b[6]<<48 | b[7]<<56 -> load 64-bit 1166 (ORshiftLL <t> [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] 1167 x0:(MOVWUload [i] {s} p mem) 1168 y1:(MOVDnop x1:(MOVBUload [i+4] {s} p mem))) 1169 y2:(MOVDnop x2:(MOVBUload [i+5] {s} p mem))) 1170 y3:(MOVDnop x3:(MOVBUload [i+6] {s} p mem))) 1171 y4:(MOVDnop x4:(MOVBUload [i+7] {s} p mem))) 1172 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 1173 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 1174 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 1175 && mergePoint(b,x0,x1,x2,x3,x4) != nil 1176 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) 1177 && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) 1178 && clobber(o0) && clobber(o1) && clobber(o2) 1179 -> @mergePoint(b,x0,x1,x2,x3,x4) (MOVDload <t> {s} (OffPtr <p.Type> [i] p) mem) 1180 1181 // b[3]<<24 | b[2]<<16 | b[1]<<8 | b[0] -> load 32-bit 1182 (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] 1183 y0:(MOVDnop x0:(MOVBUload [i] {s} p mem))) 1184 y1:(MOVDnop x1:(MOVBUload [i-1] {s} p mem))) 1185 y2:(MOVDnop x2:(MOVBUload [i-2] {s} p mem))) 1186 y3:(MOVDnop x3:(MOVBUload [i-3] {s} p mem))) 1187 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 1188 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 1189 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 1190 && mergePoint(b,x0,x1,x2,x3) != nil 1191 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) 1192 && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) 1193 && clobber(o0) && clobber(o1) && clobber(s0) 1194 -> @mergePoint(b,x0,x1,x2,x3) (MOVWUload <t> {s} (OffPtr <p.Type> [i-3] p) mem) 1195 1196 // b[7]<<56 | b[6]<<48 | b[5]<<40 | b[4]<<32 | b[3]<<24 | b[2]<<16 | b[1]<<8 | b[0] -> load 64-bit, reverse 1197 (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] 1198 y0:(MOVDnop x0:(MOVBUload [i] {s} p mem))) 1199 y1:(MOVDnop x1:(MOVBUload [i-1] {s} p mem))) 1200 y2:(MOVDnop x2:(MOVBUload [i-2] {s} p mem))) 1201 y3:(MOVDnop x3:(MOVBUload [i-3] {s} p mem))) 1202 y4:(MOVDnop x4:(MOVBUload [i-4] {s} p mem))) 1203 y5:(MOVDnop x5:(MOVBUload [i-5] {s} p mem))) 1204 y6:(MOVDnop x6:(MOVBUload [i-6] {s} p mem))) 1205 y7:(MOVDnop x7:(MOVBUload [i-7] {s} p mem))) 1206 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 1207 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 1208 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 1209 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 1210 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 1211 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 1212 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil 1213 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) 1214 && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) 1215 && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) 1216 && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) 1217 && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) 1218 && clobber(o4) && clobber(o5) && clobber(s0) 1219 -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV <t> (MOVDload <t> {s} (OffPtr <p.Type> [i-7] p) mem)) 1220 1221 // big endian loads 1222 // b[1] | b[0]<<8 -> load 16-bit, reverse 1223 (ORshiftLL <t> [8] 1224 y0:(MOVDnop x0:(MOVBUload [i] {s} p mem)) 1225 y1:(MOVDnop x1:(MOVBUload [i-1] {s} p mem))) 1226 && ((i-1)%2 == 0 || i-1<256 && i-1>-256 && !isArg(s) && !isAuto(s)) 1227 && x0.Uses == 1 && x1.Uses == 1 1228 && y0.Uses == 1 && y1.Uses == 1 1229 && mergePoint(b,x0,x1) != nil 1230 && clobber(x0) && clobber(x1) 1231 && clobber(y0) && clobber(y1) 1232 -> @mergePoint(b,x0,x1) (REV16W <t> (MOVHUload <t> [i-1] {s} p mem)) 1233 1234 // b[3] | b[2]<<8 | b[1]<<16 | b[0]<<24 -> load 32-bit, reverse 1235 (ORshiftLL <t> [24] o0:(ORshiftLL [16] 1236 y0:(REV16W x0:(MOVHUload [i] {s} p mem)) 1237 y1:(MOVDnop x1:(MOVBUload [i-1] {s} p mem))) 1238 y2:(MOVDnop x2:(MOVBUload [i-2] {s} p mem))) 1239 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 1240 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 1241 && o0.Uses == 1 1242 && mergePoint(b,x0,x1,x2) != nil 1243 && clobber(x0) && clobber(x1) && clobber(x2) 1244 && clobber(y0) && clobber(y1) && clobber(y2) 1245 && clobber(o0) 1246 -> @mergePoint(b,x0,x1,x2) (REVW <t> (MOVWUload <t> {s} (OffPtr <p.Type> [i-2] p) mem)) 1247 1248 // b[7] | b[6]<<8 | b[5]<<16 | b[4]<<24 | b[3]<<32 | b[2]<<40 | b[1]<<48 | b[0]<<56 -> load 64-bit, reverse 1249 (ORshiftLL <t> [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] 1250 y0:(REVW x0:(MOVWUload [i] {s} p mem)) 1251 y1:(MOVDnop x1:(MOVBUload [i-1] {s} p mem))) 1252 y2:(MOVDnop x2:(MOVBUload [i-2] {s} p mem))) 1253 y3:(MOVDnop x3:(MOVBUload [i-3] {s} p mem))) 1254 y4:(MOVDnop x4:(MOVBUload [i-4] {s} p mem))) 1255 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 1256 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 1257 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 1258 && mergePoint(b,x0,x1,x2,x3,x4) != nil 1259 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) 1260 && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) 1261 && clobber(o0) && clobber(o1) && clobber(o2) 1262 -> @mergePoint(b,x0,x1,x2,x3,x4) (REV <t> (MOVDload <t> {s} (OffPtr <p.Type> [i-4] p) mem)) 1263 1264 // b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3] -> load 32-bit, reverse 1265 (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] 1266 y0:(MOVDnop x0:(MOVBUload [i] {s} p mem))) 1267 y1:(MOVDnop x1:(MOVBUload [i+1] {s} p mem))) 1268 y2:(MOVDnop x2:(MOVBUload [i+2] {s} p mem))) 1269 y3:(MOVDnop x3:(MOVBUload [i+3] {s} p mem))) 1270 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 1271 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 1272 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 1273 && mergePoint(b,x0,x1,x2,x3) != nil 1274 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) 1275 && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) 1276 && clobber(o0) && clobber(o1) && clobber(s0) 1277 -> @mergePoint(b,x0,x1,x2,x3) (REVW <t> (MOVWUload <t> {s} (OffPtr <p.Type> [i] p) mem)) 1278 1279 // b[0]<<56 | b[1]<<48 | b[2]<<40 | b[3]<<32 | b[4]<<24 | b[5]<<16 | b[6]<<8 | b[7] -> load 64-bit, reverse 1280 (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] 1281 y0:(MOVDnop x0:(MOVBUload [i] {s} p mem))) 1282 y1:(MOVDnop x1:(MOVBUload [i+1] {s} p mem))) 1283 y2:(MOVDnop x2:(MOVBUload [i+2] {s} p mem))) 1284 y3:(MOVDnop x3:(MOVBUload [i+3] {s} p mem))) 1285 y4:(MOVDnop x4:(MOVBUload [i+4] {s} p mem))) 1286 y5:(MOVDnop x5:(MOVBUload [i+5] {s} p mem))) 1287 y6:(MOVDnop x6:(MOVBUload [i+6] {s} p mem))) 1288 y7:(MOVDnop x7:(MOVBUload [i+7] {s} p mem))) 1289 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 1290 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 1291 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 1292 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 1293 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 1294 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 1295 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil 1296 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) 1297 && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) 1298 && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) 1299 && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) 1300 && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) 1301 && clobber(o4) && clobber(o5) && clobber(s0) 1302 -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV <t> (MOVDload <t> {s} (OffPtr <p.Type> [i] p) mem))