github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/cmd/compile/internal/ssa/gen/MIPS.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 (Add(Ptr|32|16|8) x y) -> (ADD x y) 6 (Add(32|64)F x y) -> (ADD(F|D) x y) 7 8 (Select0 (Add32carry <t> x y)) -> (ADD <t.FieldType(0)> x y) 9 (Select1 (Add32carry <t> x y)) -> (SGTU <typ.Bool> x (ADD <t.FieldType(0)> x y)) 10 (Add32withcarry <t> x y c) -> (ADD c (ADD <t> x y)) 11 12 (Sub(Ptr|32|16|8) x y) -> (SUB x y) 13 (Sub(32|64)F x y) -> (SUB(F|D) x y) 14 15 (Select0 (Sub32carry <t> x y)) -> (SUB <t.FieldType(0)> x y) 16 (Select1 (Sub32carry <t> x y)) -> (SGTU <typ.Bool> (SUB <t.FieldType(0)> x y) x) 17 (Sub32withcarry <t> x y c) -> (SUB (SUB <t> x y) c) 18 19 (Mul(32|16|8) x y) -> (MUL x y) 20 (Mul(32|64)F x y) -> (MUL(F|D) x y) 21 22 (Hmul(32|32u) x y) -> (Select0 (MUL(T|TU) x y)) 23 (Mul32uhilo x y) -> (MULTU x y) 24 25 (Div32 x y) -> (Select1 (DIV x y)) 26 (Div32u x y) -> (Select1 (DIVU x y)) 27 (Div16 x y) -> (Select1 (DIV (SignExt16to32 x) (SignExt16to32 y))) 28 (Div16u x y) -> (Select1 (DIVU (ZeroExt16to32 x) (ZeroExt16to32 y))) 29 (Div8 x y) -> (Select1 (DIV (SignExt8to32 x) (SignExt8to32 y))) 30 (Div8u x y) -> (Select1 (DIVU (ZeroExt8to32 x) (ZeroExt8to32 y))) 31 (Div(32|64)F x y) -> (DIV(F|D) x y) 32 33 (Mod32 x y) -> (Select0 (DIV x y)) 34 (Mod32u x y) -> (Select0 (DIVU x y)) 35 (Mod16 x y) -> (Select0 (DIV (SignExt16to32 x) (SignExt16to32 y))) 36 (Mod16u x y) -> (Select0 (DIVU (ZeroExt16to32 x) (ZeroExt16to32 y))) 37 (Mod8 x y) -> (Select0 (DIV (SignExt8to32 x) (SignExt8to32 y))) 38 (Mod8u x y) -> (Select0 (DIVU (ZeroExt8to32 x) (ZeroExt8to32 y))) 39 40 // (x + y) / 2 with x>=y -> (x - y) / 2 + y 41 (Avg32u <t> x y) -> (ADD (SRLconst <t> (SUB <t> x y) [1]) y) 42 43 (And(32|16|8) x y) -> (AND x y) 44 (Or(32|16|8) x y) -> (OR x y) 45 (Xor(32|16|8) x y) -> (XOR x y) 46 47 // constant shifts 48 // generic opt rewrites all constant shifts to shift by Const64 49 (Lsh32x64 x (Const64 [c])) && uint32(c) < 32 -> (SLLconst x [c]) 50 (Rsh32x64 x (Const64 [c])) && uint32(c) < 32 -> (SRAconst x [c]) 51 (Rsh32Ux64 x (Const64 [c])) && uint32(c) < 32 -> (SRLconst x [c]) 52 (Lsh16x64 x (Const64 [c])) && uint32(c) < 16 -> (SLLconst x [c]) 53 (Rsh16x64 x (Const64 [c])) && uint32(c) < 16 -> (SRAconst (SLLconst <typ.UInt32> x [16]) [c+16]) 54 (Rsh16Ux64 x (Const64 [c])) && uint32(c) < 16 -> (SRLconst (SLLconst <typ.UInt32> x [16]) [c+16]) 55 (Lsh8x64 x (Const64 [c])) && uint32(c) < 8 -> (SLLconst x [c]) 56 (Rsh8x64 x (Const64 [c])) && uint32(c) < 8 -> (SRAconst (SLLconst <typ.UInt32> x [24]) [c+24]) 57 (Rsh8Ux64 x (Const64 [c])) && uint32(c) < 8 -> (SRLconst (SLLconst <typ.UInt32> x [24]) [c+24]) 58 59 // large constant shifts 60 (Lsh32x64 _ (Const64 [c])) && uint32(c) >= 32 -> (MOVWconst [0]) 61 (Rsh32Ux64 _ (Const64 [c])) && uint32(c) >= 32 -> (MOVWconst [0]) 62 (Lsh16x64 _ (Const64 [c])) && uint32(c) >= 16 -> (MOVWconst [0]) 63 (Rsh16Ux64 _ (Const64 [c])) && uint32(c) >= 16 -> (MOVWconst [0]) 64 (Lsh8x64 _ (Const64 [c])) && uint32(c) >= 8 -> (MOVWconst [0]) 65 (Rsh8Ux64 _ (Const64 [c])) && uint32(c) >= 8 -> (MOVWconst [0]) 66 67 // large constant signed right shift, we leave the sign bit 68 (Rsh32x64 x (Const64 [c])) && uint32(c) >= 32 -> (SRAconst x [31]) 69 (Rsh16x64 x (Const64 [c])) && uint32(c) >= 16 -> (SRAconst (SLLconst <typ.UInt32> x [16]) [31]) 70 (Rsh8x64 x (Const64 [c])) && uint32(c) >= 8 -> (SRAconst (SLLconst <typ.UInt32> x [24]) [31]) 71 72 // shifts 73 // hardware instruction uses only the low 5 bits of the shift 74 // we compare to 32 to ensure Go semantics for large shifts 75 (Lsh32x32 <t> x y) -> (CMOVZ (SLL <t> x y) (MOVWconst [0]) (SGTUconst [32] y)) 76 (Lsh32x16 <t> x y) -> (CMOVZ (SLL <t> x (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) 77 (Lsh32x8 <t> x y) -> (CMOVZ (SLL <t> x (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) 78 79 (Lsh16x32 <t> x y) -> (CMOVZ (SLL <t> x y) (MOVWconst [0]) (SGTUconst [32] y)) 80 (Lsh16x16 <t> x y) -> (CMOVZ (SLL <t> x (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) 81 (Lsh16x8 <t> x y) -> (CMOVZ (SLL <t> x (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) 82 83 (Lsh8x32 <t> x y) -> (CMOVZ (SLL <t> x y) (MOVWconst [0]) (SGTUconst [32] y)) 84 (Lsh8x16 <t> x y) -> (CMOVZ (SLL <t> x (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) 85 (Lsh8x8 <t> x y) -> (CMOVZ (SLL <t> x (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) 86 87 (Rsh32Ux32 <t> x y) -> (CMOVZ (SRL <t> x y) (MOVWconst [0]) (SGTUconst [32] y)) 88 (Rsh32Ux16 <t> x y) -> (CMOVZ (SRL <t> x (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) 89 (Rsh32Ux8 <t> x y) -> (CMOVZ (SRL <t> x (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) 90 91 (Rsh16Ux32 <t> x y) -> (CMOVZ (SRL <t> (ZeroExt16to32 x) y) (MOVWconst [0]) (SGTUconst [32] y)) 92 (Rsh16Ux16 <t> x y) -> (CMOVZ (SRL <t> (ZeroExt16to32 x) (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) 93 (Rsh16Ux8 <t> x y) -> (CMOVZ (SRL <t> (ZeroExt16to32 x) (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) 94 95 (Rsh8Ux32 <t> x y) -> (CMOVZ (SRL <t> (ZeroExt8to32 x) y) (MOVWconst [0]) (SGTUconst [32] y)) 96 (Rsh8Ux16 <t> x y) -> (CMOVZ (SRL <t> (ZeroExt8to32 x) (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) 97 (Rsh8Ux8 <t> x y) -> (CMOVZ (SRL <t> (ZeroExt8to32 x) (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) 98 99 (Rsh32x32 x y) -> (SRA x ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y))) 100 (Rsh32x16 x y) -> (SRA x ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) 101 (Rsh32x8 x y) -> (SRA x ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) 102 103 (Rsh16x32 x y) -> (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y))) 104 (Rsh16x16 x y) -> (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) 105 (Rsh16x8 x y) -> (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) 106 107 (Rsh8x32 x y) -> (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y))) 108 (Rsh8x16 x y) -> (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) 109 (Rsh8x8 x y) -> (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) 110 111 // unary ops 112 (Neg(32|16|8) x) -> (NEG x) 113 (Neg(32|64)F x) -> (NEG(F|D) x) 114 115 (Com(32|16|8) x) -> (NORconst [0] x) 116 117 (Sqrt x) -> (SQRTD x) 118 119 // TODO: optimize this case? 120 (Ctz32NonZero x) -> (Ctz32 x) 121 122 // count trailing zero 123 // 32 - CLZ(x&-x - 1) 124 (Ctz32 <t> x) -> (SUB (MOVWconst [32]) (CLZ <t> (SUBconst <t> [1] (AND <t> x (NEG <t> x))))) 125 126 // bit length 127 (BitLen32 <t> x) -> (SUB (MOVWconst [32]) (CLZ <t> x)) 128 129 // boolean ops -- booleans are represented with 0=false, 1=true 130 (AndB x y) -> (AND x y) 131 (OrB x y) -> (OR x y) 132 (EqB x y) -> (XORconst [1] (XOR <typ.Bool> x y)) 133 (NeqB x y) -> (XOR x y) 134 (Not x) -> (XORconst [1] x) 135 136 // constants 137 (Const(32|16|8) [val]) -> (MOVWconst [val]) 138 (Const(32|64)F [val]) -> (MOV(F|D)const [val]) 139 (ConstNil) -> (MOVWconst [0]) 140 (ConstBool [b]) -> (MOVWconst [b]) 141 142 // truncations 143 // Because we ignore high parts of registers, truncates are just copies. 144 (Trunc16to8 x) -> x 145 (Trunc32to8 x) -> x 146 (Trunc32to16 x) -> x 147 148 // Zero-/Sign-extensions 149 (ZeroExt8to16 x) -> (MOVBUreg x) 150 (ZeroExt8to32 x) -> (MOVBUreg x) 151 (ZeroExt16to32 x) -> (MOVHUreg x) 152 153 (SignExt8to16 x) -> (MOVBreg x) 154 (SignExt8to32 x) -> (MOVBreg x) 155 (SignExt16to32 x) -> (MOVHreg x) 156 157 (Signmask x) -> (SRAconst x [31]) 158 (Zeromask x) -> (NEG (SGTU x (MOVWconst [0]))) 159 (Slicemask <t> x) -> (SRAconst (NEG <t> x) [31]) 160 161 // float <-> int conversion 162 (Cvt32to(32|64)F x) -> (MOVW(F|D) x) 163 (Cvt(32|64)Fto32 x) -> (TRUNC(F|D)W x) 164 (Cvt32Fto64F x) -> (MOVFD x) 165 (Cvt64Fto32F x) -> (MOVDF x) 166 167 (Round(32|64)F x) -> x 168 169 // comparisons 170 (Eq8 x y) -> (SGTUconst [1] (XOR (ZeroExt8to32 x) (ZeroExt8to32 y))) 171 (Eq16 x y) -> (SGTUconst [1] (XOR (ZeroExt16to32 x) (ZeroExt16to32 y))) 172 (Eq32 x y) -> (SGTUconst [1] (XOR x y)) 173 (EqPtr x y) -> (SGTUconst [1] (XOR x y)) 174 (Eq(32|64)F x y) -> (FPFlagTrue (CMPEQ(F|D) x y)) 175 176 (Neq8 x y) -> (SGTU (XOR (ZeroExt8to32 x) (ZeroExt8to32 y)) (MOVWconst [0])) 177 (Neq16 x y) -> (SGTU (XOR (ZeroExt16to32 x) (ZeroExt16to32 y)) (MOVWconst [0])) 178 (Neq32 x y) -> (SGTU (XOR x y) (MOVWconst [0])) 179 (NeqPtr x y) -> (SGTU (XOR x y) (MOVWconst [0])) 180 (Neq(32|64)F x y) -> (FPFlagFalse (CMPEQ(F|D) x y)) 181 182 (Less8 x y) -> (SGT (SignExt8to32 y) (SignExt8to32 x)) 183 (Less16 x y) -> (SGT (SignExt16to32 y) (SignExt16to32 x)) 184 (Less32 x y) -> (SGT y x) 185 (Less(32|64)F x y) -> (FPFlagTrue (CMPGT(F|D) y x)) // reverse operands to work around NaN 186 187 (Less8U x y) -> (SGTU (ZeroExt8to32 y) (ZeroExt8to32 x)) 188 (Less16U x y) -> (SGTU (ZeroExt16to32 y) (ZeroExt16to32 x)) 189 (Less32U x y) -> (SGTU y x) 190 191 (Leq8 x y) -> (XORconst [1] (SGT (SignExt8to32 x) (SignExt8to32 y))) 192 (Leq16 x y) -> (XORconst [1] (SGT (SignExt16to32 x) (SignExt16to32 y))) 193 (Leq32 x y) -> (XORconst [1] (SGT x y)) 194 (Leq(32|64)F x y) -> (FPFlagTrue (CMPGE(F|D) y x)) // reverse operands to work around NaN 195 196 (Leq8U x y) -> (XORconst [1] (SGTU (ZeroExt8to32 x) (ZeroExt8to32 y))) 197 (Leq16U x y) -> (XORconst [1] (SGTU (ZeroExt16to32 x) (ZeroExt16to32 y))) 198 (Leq32U x y) -> (XORconst [1] (SGTU x y)) 199 200 (Greater8 x y) -> (SGT (SignExt8to32 x) (SignExt8to32 y)) 201 (Greater16 x y) -> (SGT (SignExt16to32 x) (SignExt16to32 y)) 202 (Greater32 x y) -> (SGT x y) 203 (Greater(32|64)F x y) -> (FPFlagTrue (CMPGT(F|D) x y)) 204 205 (Greater8U x y) -> (SGTU (ZeroExt8to32 x) (ZeroExt8to32 y)) 206 (Greater16U x y) -> (SGTU (ZeroExt16to32 x) (ZeroExt16to32 y)) 207 (Greater32U x y) -> (SGTU x y) 208 209 (Geq8 x y) -> (XORconst [1] (SGT (SignExt8to32 y) (SignExt8to32 x))) 210 (Geq16 x y) -> (XORconst [1] (SGT (SignExt16to32 y) (SignExt16to32 x))) 211 (Geq32 x y) -> (XORconst [1] (SGT y x)) 212 (Geq(32|64)F x y) -> (FPFlagTrue (CMPGE(F|D) x y)) 213 214 (Geq8U x y) -> (XORconst [1] (SGTU (ZeroExt8to32 y) (ZeroExt8to32 x))) 215 (Geq16U x y) -> (XORconst [1] (SGTU (ZeroExt16to32 y) (ZeroExt16to32 x))) 216 (Geq32U x y) -> (XORconst [1] (SGTU y x)) 217 218 (OffPtr [off] ptr:(SP)) -> (MOVWaddr [off] ptr) 219 (OffPtr [off] ptr) -> (ADDconst [off] ptr) 220 221 (Addr {sym} base) -> (MOVWaddr {sym} base) 222 (LocalAddr {sym} base _) -> (MOVWaddr {sym} base) 223 224 // loads 225 (Load <t> ptr mem) && t.IsBoolean() -> (MOVBUload ptr mem) 226 (Load <t> ptr mem) && (is8BitInt(t) && isSigned(t)) -> (MOVBload ptr mem) 227 (Load <t> ptr mem) && (is8BitInt(t) && !isSigned(t)) -> (MOVBUload ptr mem) 228 (Load <t> ptr mem) && (is16BitInt(t) && isSigned(t)) -> (MOVHload ptr mem) 229 (Load <t> ptr mem) && (is16BitInt(t) && !isSigned(t)) -> (MOVHUload ptr mem) 230 (Load <t> ptr mem) && (is32BitInt(t) || isPtr(t)) -> (MOVWload ptr mem) 231 (Load <t> ptr mem) && is32BitFloat(t) -> (MOVFload ptr mem) 232 (Load <t> ptr mem) && is64BitFloat(t) -> (MOVDload ptr mem) 233 234 // stores 235 (Store {t} ptr val mem) && t.(*types.Type).Size() == 1 -> (MOVBstore ptr val mem) 236 (Store {t} ptr val mem) && t.(*types.Type).Size() == 2 -> (MOVHstore ptr val mem) 237 (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && !is32BitFloat(val.Type) -> (MOVWstore ptr val mem) 238 (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && is32BitFloat(val.Type) -> (MOVFstore ptr val mem) 239 (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 && is64BitFloat(val.Type) -> (MOVDstore ptr val mem) 240 241 // zero instructions 242 (Zero [0] _ mem) -> mem 243 (Zero [1] ptr mem) -> (MOVBstore ptr (MOVWconst [0]) mem) 244 (Zero [2] {t} ptr mem) && t.(*types.Type).Alignment()%2 == 0 -> 245 (MOVHstore ptr (MOVWconst [0]) mem) 246 (Zero [2] ptr mem) -> 247 (MOVBstore [1] ptr (MOVWconst [0]) 248 (MOVBstore [0] ptr (MOVWconst [0]) mem)) 249 (Zero [4] {t} ptr mem) && t.(*types.Type).Alignment()%4 == 0 -> 250 (MOVWstore ptr (MOVWconst [0]) mem) 251 (Zero [4] {t} ptr mem) && t.(*types.Type).Alignment()%2 == 0 -> 252 (MOVHstore [2] ptr (MOVWconst [0]) 253 (MOVHstore [0] ptr (MOVWconst [0]) mem)) 254 (Zero [4] ptr mem) -> 255 (MOVBstore [3] ptr (MOVWconst [0]) 256 (MOVBstore [2] ptr (MOVWconst [0]) 257 (MOVBstore [1] ptr (MOVWconst [0]) 258 (MOVBstore [0] ptr (MOVWconst [0]) mem)))) 259 (Zero [3] ptr mem) -> 260 (MOVBstore [2] ptr (MOVWconst [0]) 261 (MOVBstore [1] ptr (MOVWconst [0]) 262 (MOVBstore [0] ptr (MOVWconst [0]) mem))) 263 (Zero [6] {t} ptr mem) && t.(*types.Type).Alignment()%2 == 0 -> 264 (MOVHstore [4] ptr (MOVWconst [0]) 265 (MOVHstore [2] ptr (MOVWconst [0]) 266 (MOVHstore [0] ptr (MOVWconst [0]) mem))) 267 (Zero [8] {t} ptr mem) && t.(*types.Type).Alignment()%4 == 0 -> 268 (MOVWstore [4] ptr (MOVWconst [0]) 269 (MOVWstore [0] ptr (MOVWconst [0]) mem)) 270 (Zero [12] {t} ptr mem) && t.(*types.Type).Alignment()%4 == 0 -> 271 (MOVWstore [8] ptr (MOVWconst [0]) 272 (MOVWstore [4] ptr (MOVWconst [0]) 273 (MOVWstore [0] ptr (MOVWconst [0]) mem))) 274 (Zero [16] {t} ptr mem) && t.(*types.Type).Alignment()%4 == 0 -> 275 (MOVWstore [12] ptr (MOVWconst [0]) 276 (MOVWstore [8] ptr (MOVWconst [0]) 277 (MOVWstore [4] ptr (MOVWconst [0]) 278 (MOVWstore [0] ptr (MOVWconst [0]) mem)))) 279 280 // large or unaligned zeroing uses a loop 281 (Zero [s] {t} ptr mem) 282 && (s > 16 || t.(*types.Type).Alignment()%4 != 0) -> 283 (LoweredZero [t.(*types.Type).Alignment()] 284 ptr 285 (ADDconst <ptr.Type> ptr [s-moveSize(t.(*types.Type).Alignment(), config)]) 286 mem) 287 288 // moves 289 (Move [0] _ _ mem) -> mem 290 (Move [1] dst src mem) -> (MOVBstore dst (MOVBUload src mem) mem) 291 (Move [2] {t} dst src mem) && t.(*types.Type).Alignment()%2 == 0 -> 292 (MOVHstore dst (MOVHUload src mem) mem) 293 (Move [2] dst src mem) -> 294 (MOVBstore [1] dst (MOVBUload [1] src mem) 295 (MOVBstore dst (MOVBUload src mem) mem)) 296 (Move [4] {t} dst src mem) && t.(*types.Type).Alignment()%4 == 0 -> 297 (MOVWstore dst (MOVWload src mem) mem) 298 (Move [4] {t} dst src mem) && t.(*types.Type).Alignment()%2 == 0 -> 299 (MOVHstore [2] dst (MOVHUload [2] src mem) 300 (MOVHstore dst (MOVHUload src mem) mem)) 301 (Move [4] dst src mem) -> 302 (MOVBstore [3] dst (MOVBUload [3] src mem) 303 (MOVBstore [2] dst (MOVBUload [2] src mem) 304 (MOVBstore [1] dst (MOVBUload [1] src mem) 305 (MOVBstore dst (MOVBUload src mem) mem)))) 306 (Move [3] dst src mem) -> 307 (MOVBstore [2] dst (MOVBUload [2] src mem) 308 (MOVBstore [1] dst (MOVBUload [1] src mem) 309 (MOVBstore dst (MOVBUload src mem) mem))) 310 (Move [8] {t} dst src mem) && t.(*types.Type).Alignment()%4 == 0 -> 311 (MOVWstore [4] dst (MOVWload [4] src mem) 312 (MOVWstore dst (MOVWload src mem) mem)) 313 (Move [8] {t} dst src mem) && t.(*types.Type).Alignment()%2 == 0 -> 314 (MOVHstore [6] dst (MOVHload [6] src mem) 315 (MOVHstore [4] dst (MOVHload [4] src mem) 316 (MOVHstore [2] dst (MOVHload [2] src mem) 317 (MOVHstore dst (MOVHload src mem) mem)))) 318 (Move [6] {t} dst src mem) && t.(*types.Type).Alignment()%2 == 0 -> 319 (MOVHstore [4] dst (MOVHload [4] src mem) 320 (MOVHstore [2] dst (MOVHload [2] src mem) 321 (MOVHstore dst (MOVHload src mem) mem))) 322 (Move [12] {t} dst src mem) && t.(*types.Type).Alignment()%4 == 0 -> 323 (MOVWstore [8] dst (MOVWload [8] src mem) 324 (MOVWstore [4] dst (MOVWload [4] src mem) 325 (MOVWstore dst (MOVWload src mem) mem))) 326 (Move [16] {t} dst src mem) && t.(*types.Type).Alignment()%4 == 0 -> 327 (MOVWstore [12] dst (MOVWload [12] src mem) 328 (MOVWstore [8] dst (MOVWload [8] src mem) 329 (MOVWstore [4] dst (MOVWload [4] src mem) 330 (MOVWstore dst (MOVWload src mem) mem)))) 331 332 333 // large or unaligned move uses a loop 334 (Move [s] {t} dst src mem) 335 && (s > 16 || t.(*types.Type).Alignment()%4 != 0) -> 336 (LoweredMove [t.(*types.Type).Alignment()] 337 dst 338 src 339 (ADDconst <src.Type> src [s-moveSize(t.(*types.Type).Alignment(), config)]) 340 mem) 341 342 // calls 343 (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem) 344 (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem) 345 (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem) 346 347 // atomic intrinsics 348 (AtomicLoad32 ptr mem) -> (LoweredAtomicLoad ptr mem) 349 (AtomicLoadPtr ptr mem) -> (LoweredAtomicLoad ptr mem) 350 351 (AtomicStore32 ptr val mem) -> (LoweredAtomicStore ptr val mem) 352 (AtomicStorePtrNoWB ptr val mem) -> (LoweredAtomicStore ptr val mem) 353 354 (AtomicExchange32 ptr val mem) -> (LoweredAtomicExchange ptr val mem) 355 (AtomicAdd32 ptr val mem) -> (LoweredAtomicAdd ptr val mem) 356 357 (AtomicCompareAndSwap32 ptr old new_ mem) -> (LoweredAtomicCas ptr old new_ mem) 358 359 // AtomicOr8(ptr,val) -> LoweredAtomicOr(ptr&^3,uint32(val) << ((ptr & 3) * 8)) 360 (AtomicOr8 ptr val mem) && !config.BigEndian -> 361 (LoweredAtomicOr (AND <typ.UInt32Ptr> (MOVWconst [^3]) ptr) 362 (SLL <typ.UInt32> (ZeroExt8to32 val) 363 (SLLconst <typ.UInt32> [3] 364 (ANDconst <typ.UInt32> [3] ptr))) mem) 365 366 // AtomicAnd8(ptr,val) -> LoweredAtomicAnd(ptr&^3,(uint32(val) << ((ptr & 3) * 8)) | ^(uint32(0xFF) << ((ptr & 3) * 8)))) 367 (AtomicAnd8 ptr val mem) && !config.BigEndian -> 368 (LoweredAtomicAnd (AND <typ.UInt32Ptr> (MOVWconst [^3]) ptr) 369 (OR <typ.UInt32> (SLL <typ.UInt32> (ZeroExt8to32 val) 370 (SLLconst <typ.UInt32> [3] 371 (ANDconst <typ.UInt32> [3] ptr))) 372 (NORconst [0] <typ.UInt32> (SLL <typ.UInt32> 373 (MOVWconst [0xff]) (SLLconst <typ.UInt32> [3] 374 (ANDconst <typ.UInt32> [3] ptr))))) mem) 375 376 // AtomicOr8(ptr,val) -> LoweredAtomicOr(ptr&^3,uint32(val) << (((ptr^3) & 3) * 8)) 377 (AtomicOr8 ptr val mem) && config.BigEndian -> 378 (LoweredAtomicOr (AND <typ.UInt32Ptr> (MOVWconst [^3]) ptr) 379 (SLL <typ.UInt32> (ZeroExt8to32 val) 380 (SLLconst <typ.UInt32> [3] 381 (ANDconst <typ.UInt32> [3] 382 (XORconst <typ.UInt32> [3] ptr)))) mem) 383 384 // AtomicAnd8(ptr,val) -> LoweredAtomicAnd(ptr&^3,(uint32(val) << (((ptr^3) & 3) * 8)) | ^(uint32(0xFF) << (((ptr^3) & 3) * 8)))) 385 (AtomicAnd8 ptr val mem) && config.BigEndian -> 386 (LoweredAtomicAnd (AND <typ.UInt32Ptr> (MOVWconst [^3]) ptr) 387 (OR <typ.UInt32> (SLL <typ.UInt32> (ZeroExt8to32 val) 388 (SLLconst <typ.UInt32> [3] 389 (ANDconst <typ.UInt32> [3] 390 (XORconst <typ.UInt32> [3] ptr)))) 391 (NORconst [0] <typ.UInt32> (SLL <typ.UInt32> 392 (MOVWconst [0xff]) (SLLconst <typ.UInt32> [3] 393 (ANDconst <typ.UInt32> [3] 394 (XORconst <typ.UInt32> [3] ptr)))))) mem) 395 396 397 // checks 398 (NilCheck ptr mem) -> (LoweredNilCheck ptr mem) 399 (IsNonNil ptr) -> (SGTU ptr (MOVWconst [0])) 400 (IsInBounds idx len) -> (SGTU len idx) 401 (IsSliceInBounds idx len) -> (XORconst [1] (SGTU idx len)) 402 403 // pseudo-ops 404 (GetClosurePtr) -> (LoweredGetClosurePtr) 405 (GetCallerSP) -> (LoweredGetCallerSP) 406 (GetCallerPC) -> (LoweredGetCallerPC) 407 408 (If cond yes no) -> (NE cond yes no) 409 410 // Write barrier. 411 (WB {fn} destptr srcptr mem) -> (LoweredWB {fn} destptr srcptr mem) 412 413 414 // Optimizations 415 416 // Absorb boolean tests into block 417 (NE (FPFlagTrue cmp) yes no) -> (FPT cmp yes no) 418 (NE (FPFlagFalse cmp) yes no) -> (FPF cmp yes no) 419 (EQ (FPFlagTrue cmp) yes no) -> (FPF cmp yes no) 420 (EQ (FPFlagFalse cmp) yes no) -> (FPT cmp yes no) 421 (NE (XORconst [1] cmp:(SGT _ _)) yes no) -> (EQ cmp yes no) 422 (NE (XORconst [1] cmp:(SGTU _ _)) yes no) -> (EQ cmp yes no) 423 (NE (XORconst [1] cmp:(SGTconst _)) yes no) -> (EQ cmp yes no) 424 (NE (XORconst [1] cmp:(SGTUconst _)) yes no) -> (EQ cmp yes no) 425 (NE (XORconst [1] cmp:(SGTzero _)) yes no) -> (EQ cmp yes no) 426 (NE (XORconst [1] cmp:(SGTUzero _)) yes no) -> (EQ cmp yes no) 427 (EQ (XORconst [1] cmp:(SGT _ _)) yes no) -> (NE cmp yes no) 428 (EQ (XORconst [1] cmp:(SGTU _ _)) yes no) -> (NE cmp yes no) 429 (EQ (XORconst [1] cmp:(SGTconst _)) yes no) -> (NE cmp yes no) 430 (EQ (XORconst [1] cmp:(SGTUconst _)) yes no) -> (NE cmp yes no) 431 (EQ (XORconst [1] cmp:(SGTzero _)) yes no) -> (NE cmp yes no) 432 (EQ (XORconst [1] cmp:(SGTUzero _)) yes no) -> (NE cmp yes no) 433 (NE (SGTUconst [1] x) yes no) -> (EQ x yes no) 434 (EQ (SGTUconst [1] x) yes no) -> (NE x yes no) 435 (NE (SGTUzero x) yes no) -> (NE x yes no) 436 (EQ (SGTUzero x) yes no) -> (EQ x yes no) 437 (NE (SGTconst [0] x) yes no) -> (LTZ x yes no) 438 (EQ (SGTconst [0] x) yes no) -> (GEZ x yes no) 439 (NE (SGTzero x) yes no) -> (GTZ x yes no) 440 (EQ (SGTzero x) yes no) -> (LEZ x yes no) 441 442 // fold offset into address 443 (ADDconst [off1] (MOVWaddr [off2] {sym} ptr)) -> (MOVWaddr [off1+off2] {sym} ptr) 444 445 // fold address into load/store 446 (MOVBload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVBload [off1+off2] {sym} ptr mem) 447 (MOVBUload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVBUload [off1+off2] {sym} ptr mem) 448 (MOVHload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVHload [off1+off2] {sym} ptr mem) 449 (MOVHUload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVHUload [off1+off2] {sym} ptr mem) 450 (MOVWload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVWload [off1+off2] {sym} ptr mem) 451 (MOVFload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVFload [off1+off2] {sym} ptr mem) 452 (MOVDload [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVDload [off1+off2] {sym} ptr mem) 453 454 (MOVBstore [off1] {sym} x:(ADDconst [off2] ptr) val mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVBstore [off1+off2] {sym} ptr val mem) 455 (MOVHstore [off1] {sym} x:(ADDconst [off2] ptr) val mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVHstore [off1+off2] {sym} ptr val mem) 456 (MOVWstore [off1] {sym} x:(ADDconst [off2] ptr) val mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVWstore [off1+off2] {sym} ptr val mem) 457 (MOVFstore [off1] {sym} x:(ADDconst [off2] ptr) val mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVFstore [off1+off2] {sym} ptr val mem) 458 (MOVDstore [off1] {sym} x:(ADDconst [off2] ptr) val mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVDstore [off1+off2] {sym} ptr val mem) 459 460 (MOVBstorezero [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVBstorezero [off1+off2] {sym} ptr mem) 461 (MOVHstorezero [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVHstorezero [off1+off2] {sym} ptr mem) 462 (MOVWstorezero [off1] {sym} x:(ADDconst [off2] ptr) mem) && (is16Bit(off1+off2) || x.Uses == 1) -> (MOVWstorezero [off1+off2] {sym} ptr mem) 463 464 (MOVBload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 465 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 466 (MOVBUload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 467 (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 468 (MOVHload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 469 (MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 470 (MOVHUload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 471 (MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 472 (MOVWload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 473 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 474 (MOVFload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 475 (MOVFload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 476 (MOVDload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 477 (MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 478 479 (MOVBstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) -> 480 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 481 (MOVHstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) -> 482 (MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 483 (MOVWstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) -> 484 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 485 (MOVFstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) -> 486 (MOVFstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 487 (MOVDstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) -> 488 (MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) 489 (MOVBstorezero [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 490 (MOVBstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 491 (MOVHstorezero [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 492 (MOVHstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 493 (MOVWstorezero [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) -> 494 (MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 495 496 // replace load from same location as preceding store with zero/sign extension (or copy in case of full width) 497 (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBreg x) 498 (MOVBUload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBUreg x) 499 (MOVHload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHreg x) 500 (MOVHUload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHUreg x) 501 (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 502 (MOVFload [off] {sym} ptr (MOVFstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 503 (MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 504 505 // store zero 506 (MOVBstore [off] {sym} ptr (MOVWconst [0]) mem) -> (MOVBstorezero [off] {sym} ptr mem) 507 (MOVHstore [off] {sym} ptr (MOVWconst [0]) mem) -> (MOVHstorezero [off] {sym} ptr mem) 508 (MOVWstore [off] {sym} ptr (MOVWconst [0]) mem) -> (MOVWstorezero [off] {sym} ptr mem) 509 510 // don't extend after proper load 511 (MOVBreg x:(MOVBload _ _)) -> (MOVWreg x) 512 (MOVBUreg x:(MOVBUload _ _)) -> (MOVWreg x) 513 (MOVHreg x:(MOVBload _ _)) -> (MOVWreg x) 514 (MOVHreg x:(MOVBUload _ _)) -> (MOVWreg x) 515 (MOVHreg x:(MOVHload _ _)) -> (MOVWreg x) 516 (MOVHUreg x:(MOVBUload _ _)) -> (MOVWreg x) 517 (MOVHUreg x:(MOVHUload _ _)) -> (MOVWreg x) 518 519 // fold double extensions 520 (MOVBreg x:(MOVBreg _)) -> (MOVWreg x) 521 (MOVBUreg x:(MOVBUreg _)) -> (MOVWreg x) 522 (MOVHreg x:(MOVBreg _)) -> (MOVWreg x) 523 (MOVHreg x:(MOVBUreg _)) -> (MOVWreg x) 524 (MOVHreg x:(MOVHreg _)) -> (MOVWreg x) 525 (MOVHUreg x:(MOVBUreg _)) -> (MOVWreg x) 526 (MOVHUreg x:(MOVHUreg _)) -> (MOVWreg x) 527 528 // sign extended loads 529 // Note: The combined instruction must end up in the same block 530 // as the original load. If not, we end up making a value with 531 // memory type live in two different blocks, which can lead to 532 // multiple memory values alive simultaneously. 533 // Make sure we don't combine these ops if the load has another use. 534 // This prevents a single load from being split into multiple loads 535 // which then might return different values. See test/atomicload.go. 536 (MOVBreg <t> x:(MOVBUload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <t> [off] {sym} ptr mem) 537 (MOVBUreg <t> x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBUload <t> [off] {sym} ptr mem) 538 (MOVHreg <t> x:(MOVHUload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVHload <t> [off] {sym} ptr mem) 539 (MOVHUreg <t> x:(MOVHload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVHUload <t> [off] {sym} ptr mem) 540 541 // fold extensions and ANDs together 542 (MOVBUreg (ANDconst [c] x)) -> (ANDconst [c&0xff] x) 543 (MOVHUreg (ANDconst [c] x)) -> (ANDconst [c&0xffff] x) 544 (MOVBreg (ANDconst [c] x)) && c & 0x80 == 0 -> (ANDconst [c&0x7f] x) 545 (MOVHreg (ANDconst [c] x)) && c & 0x8000 == 0 -> (ANDconst [c&0x7fff] x) 546 547 // don't extend before store 548 (MOVBstore [off] {sym} ptr (MOVBreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 549 (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 550 (MOVBstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 551 (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 552 (MOVBstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVBstore [off] {sym} ptr x mem) 553 (MOVHstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 554 (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 555 (MOVHstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVHstore [off] {sym} ptr x mem) 556 (MOVWstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVWstore [off] {sym} ptr x mem) 557 558 // if a register move has only 1 use, just use the same register without emitting instruction 559 // MOVWnop doesn't emit instruction, only for ensuring the type. 560 (MOVWreg x) && x.Uses == 1 -> (MOVWnop x) 561 562 // fold constant into arithmatic ops 563 (ADD x (MOVWconst [c])) -> (ADDconst [c] x) 564 (SUB x (MOVWconst [c])) -> (SUBconst [c] x) 565 (AND x (MOVWconst [c])) -> (ANDconst [c] x) 566 (OR x (MOVWconst [c])) -> (ORconst [c] x) 567 (XOR x (MOVWconst [c])) -> (XORconst [c] x) 568 (NOR x (MOVWconst [c])) -> (NORconst [c] x) 569 570 (SLL _ (MOVWconst [c])) && uint32(c)>=32 -> (MOVWconst [0]) 571 (SRL _ (MOVWconst [c])) && uint32(c)>=32 -> (MOVWconst [0]) 572 (SRA x (MOVWconst [c])) && uint32(c)>=32 -> (SRAconst x [31]) 573 (SLL x (MOVWconst [c])) -> (SLLconst x [c]) 574 (SRL x (MOVWconst [c])) -> (SRLconst x [c]) 575 (SRA x (MOVWconst [c])) -> (SRAconst x [c]) 576 577 (SGT (MOVWconst [c]) x) -> (SGTconst [c] x) 578 (SGTU (MOVWconst [c]) x) -> (SGTUconst [c] x) 579 (SGT x (MOVWconst [0])) -> (SGTzero x) 580 (SGTU x (MOVWconst [0])) -> (SGTUzero x) 581 582 // mul with constant 583 (Select1 (MULTU (MOVWconst [0]) _ )) -> (MOVWconst [0]) 584 (Select0 (MULTU (MOVWconst [0]) _ )) -> (MOVWconst [0]) 585 (Select1 (MULTU (MOVWconst [1]) x )) -> x 586 (Select0 (MULTU (MOVWconst [1]) _ )) -> (MOVWconst [0]) 587 (Select1 (MULTU (MOVWconst [-1]) x )) -> (NEG <x.Type> x) 588 (Select0 (MULTU (MOVWconst [-1]) x )) -> (CMOVZ (ADDconst <x.Type> [-1] x) (MOVWconst [0]) x) 589 (Select1 (MULTU (MOVWconst [c]) x )) && isPowerOfTwo(int64(uint32(c))) -> (SLLconst [log2(int64(uint32(c)))] x) 590 (Select0 (MULTU (MOVWconst [c]) x )) && isPowerOfTwo(int64(uint32(c))) -> (SRLconst [32-log2(int64(uint32(c)))] x) 591 592 (MUL (MOVWconst [0]) _ ) -> (MOVWconst [0]) 593 (MUL (MOVWconst [1]) x ) -> x 594 (MUL (MOVWconst [-1]) x ) -> (NEG x) 595 (MUL (MOVWconst [c]) x ) && isPowerOfTwo(int64(uint32(c))) -> (SLLconst [log2(int64(uint32(c)))] x) 596 597 // generic simplifications 598 (ADD x (NEG y)) -> (SUB x y) 599 (SUB x x) -> (MOVWconst [0]) 600 (SUB (MOVWconst [0]) x) -> (NEG x) 601 (AND x x) -> x 602 (OR x x) -> x 603 (XOR x x) -> (MOVWconst [0]) 604 605 // miscellaneous patterns generated by dec64 606 (AND (SGTUconst [1] x) (SGTUconst [1] y)) -> (SGTUconst [1] (OR <x.Type> x y)) 607 (OR (SGTUzero x) (SGTUzero y)) -> (SGTUzero (OR <x.Type> x y)) 608 609 // remove redundant *const ops 610 (ADDconst [0] x) -> x 611 (SUBconst [0] x) -> x 612 (ANDconst [0] _) -> (MOVWconst [0]) 613 (ANDconst [-1] x) -> x 614 (ORconst [0] x) -> x 615 (ORconst [-1] _) -> (MOVWconst [-1]) 616 (XORconst [0] x) -> x 617 (XORconst [-1] x) -> (NORconst [0] x) 618 619 // generic constant folding 620 (ADDconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(c+d))]) 621 (ADDconst [c] (ADDconst [d] x)) -> (ADDconst [int64(int32(c+d))] x) 622 (ADDconst [c] (SUBconst [d] x)) -> (ADDconst [int64(int32(c-d))] x) 623 (SUBconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d-c))]) 624 (SUBconst [c] (SUBconst [d] x)) -> (ADDconst [int64(int32(-c-d))] x) 625 (SUBconst [c] (ADDconst [d] x)) -> (ADDconst [int64(int32(-c+d))] x) 626 (SLLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)<<uint32(c)))]) 627 (SRLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(uint32(d)>>uint32(c))]) 628 (SRAconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d)>>uint32(c))]) 629 (MUL (MOVWconst [c]) (MOVWconst [d])) -> (MOVWconst [int64(int32(c)*int32(d))]) 630 (Select1 (MULTU (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)*uint32(d)))]) 631 (Select0 (MULTU (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [(c*d)>>32]) 632 (Select1 (DIV (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(c)/int32(d))]) 633 (Select1 (DIVU (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)/uint32(d)))]) 634 (Select0 (DIV (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(c)%int32(d))]) 635 (Select0 (DIVU (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)%uint32(d)))]) 636 (ANDconst [c] (MOVWconst [d])) -> (MOVWconst [c&d]) 637 (ANDconst [c] (ANDconst [d] x)) -> (ANDconst [c&d] x) 638 (ORconst [c] (MOVWconst [d])) -> (MOVWconst [c|d]) 639 (ORconst [c] (ORconst [d] x)) -> (ORconst [c|d] x) 640 (XORconst [c] (MOVWconst [d])) -> (MOVWconst [c^d]) 641 (XORconst [c] (XORconst [d] x)) -> (XORconst [c^d] x) 642 (NORconst [c] (MOVWconst [d])) -> (MOVWconst [^(c|d)]) 643 (NEG (MOVWconst [c])) -> (MOVWconst [int64(int32(-c))]) 644 (MOVBreg (MOVWconst [c])) -> (MOVWconst [int64(int8(c))]) 645 (MOVBUreg (MOVWconst [c])) -> (MOVWconst [int64(uint8(c))]) 646 (MOVHreg (MOVWconst [c])) -> (MOVWconst [int64(int16(c))]) 647 (MOVHUreg (MOVWconst [c])) -> (MOVWconst [int64(uint16(c))]) 648 (MOVWreg (MOVWconst [c])) -> (MOVWconst [c]) 649 650 // constant comparisons 651 (SGTconst [c] (MOVWconst [d])) && int32(c) > int32(d) -> (MOVWconst [1]) 652 (SGTconst [c] (MOVWconst [d])) && int32(c) <= int32(d) -> (MOVWconst [0]) 653 (SGTUconst [c] (MOVWconst [d])) && uint32(c)>uint32(d) -> (MOVWconst [1]) 654 (SGTUconst [c] (MOVWconst [d])) && uint32(c)<=uint32(d) -> (MOVWconst [0]) 655 (SGTzero (MOVWconst [d])) && int32(d) > 0 -> (MOVWconst [1]) 656 (SGTzero (MOVWconst [d])) && int32(d) <= 0 -> (MOVWconst [0]) 657 (SGTUzero (MOVWconst [d])) && uint32(d) != 0 -> (MOVWconst [1]) 658 (SGTUzero (MOVWconst [d])) && uint32(d) == 0 -> (MOVWconst [0]) 659 660 // other known comparisons 661 (SGTconst [c] (MOVBreg _)) && 0x7f < int32(c) -> (MOVWconst [1]) 662 (SGTconst [c] (MOVBreg _)) && int32(c) <= -0x80 -> (MOVWconst [0]) 663 (SGTconst [c] (MOVBUreg _)) && 0xff < int32(c) -> (MOVWconst [1]) 664 (SGTconst [c] (MOVBUreg _)) && int32(c) < 0 -> (MOVWconst [0]) 665 (SGTUconst [c] (MOVBUreg _)) && 0xff < uint32(c) -> (MOVWconst [1]) 666 (SGTconst [c] (MOVHreg _)) && 0x7fff < int32(c) -> (MOVWconst [1]) 667 (SGTconst [c] (MOVHreg _)) && int32(c) <= -0x8000 -> (MOVWconst [0]) 668 (SGTconst [c] (MOVHUreg _)) && 0xffff < int32(c) -> (MOVWconst [1]) 669 (SGTconst [c] (MOVHUreg _)) && int32(c) < 0 -> (MOVWconst [0]) 670 (SGTUconst [c] (MOVHUreg _)) && 0xffff < uint32(c) -> (MOVWconst [1]) 671 (SGTconst [c] (ANDconst [m] _)) && 0 <= int32(m) && int32(m) < int32(c) -> (MOVWconst [1]) 672 (SGTUconst [c] (ANDconst [m] _)) && uint32(m) < uint32(c) -> (MOVWconst [1]) 673 (SGTconst [c] (SRLconst _ [d])) && 0 <= int32(c) && uint32(d) <= 31 && 0xffffffff>>uint32(d) < uint32(c) -> (MOVWconst [1]) 674 (SGTUconst [c] (SRLconst _ [d])) && uint32(d) <= 31 && 0xffffffff>>uint32(d) < uint32(c) -> (MOVWconst [1]) 675 676 // absorb constants into branches 677 (EQ (MOVWconst [0]) yes no) -> (First nil yes no) 678 (EQ (MOVWconst [c]) yes no) && c != 0 -> (First nil no yes) 679 (NE (MOVWconst [0]) yes no) -> (First nil no yes) 680 (NE (MOVWconst [c]) yes no) && c != 0 -> (First nil yes no) 681 (LTZ (MOVWconst [c]) yes no) && int32(c) < 0 -> (First nil yes no) 682 (LTZ (MOVWconst [c]) yes no) && int32(c) >= 0 -> (First nil no yes) 683 (LEZ (MOVWconst [c]) yes no) && int32(c) <= 0 -> (First nil yes no) 684 (LEZ (MOVWconst [c]) yes no) && int32(c) > 0 -> (First nil no yes) 685 (GTZ (MOVWconst [c]) yes no) && int32(c) > 0 -> (First nil yes no) 686 (GTZ (MOVWconst [c]) yes no) && int32(c) <= 0 -> (First nil no yes) 687 (GEZ (MOVWconst [c]) yes no) && int32(c) >= 0 -> (First nil yes no) 688 (GEZ (MOVWconst [c]) yes no) && int32(c) < 0 -> (First nil no yes) 689 690 // conditional move 691 (CMOVZ _ b (MOVWconst [0])) -> b 692 (CMOVZ a _ (MOVWconst [c])) && c!=0 -> a 693 (CMOVZzero _ (MOVWconst [0])) -> (MOVWconst [0]) 694 (CMOVZzero a (MOVWconst [c])) && c!=0 -> a 695 (CMOVZ a (MOVWconst [0]) c) -> (CMOVZzero a c) 696 697 // atomic 698 (LoweredAtomicStore ptr (MOVWconst [0]) mem) -> (LoweredAtomicStorezero ptr mem) 699 (LoweredAtomicAdd ptr (MOVWconst [c]) mem) && is16Bit(c) -> (LoweredAtomicAddconst [c] ptr mem) 700