github.com/goproxy0/go@v0.0.0-20171111080102-49cc0c489d2c/src/cmd/compile/internal/ssa/gen/AMD64.rules (about) 1 // Copyright 2015 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 // Lowering arithmetic 6 (Add64 x y) -> (ADDQ x y) 7 (AddPtr x y) && config.PtrSize == 8 -> (ADDQ x y) 8 (AddPtr x y) && config.PtrSize == 4 -> (ADDL x y) 9 (Add32 x y) -> (ADDL x y) 10 (Add16 x y) -> (ADDL x y) 11 (Add8 x y) -> (ADDL x y) 12 (Add32F x y) -> (ADDSS x y) 13 (Add64F x y) -> (ADDSD x y) 14 15 (Sub64 x y) -> (SUBQ x y) 16 (SubPtr x y) && config.PtrSize == 8 -> (SUBQ x y) 17 (SubPtr x y) && config.PtrSize == 4 -> (SUBL x y) 18 (Sub32 x y) -> (SUBL x y) 19 (Sub16 x y) -> (SUBL x y) 20 (Sub8 x y) -> (SUBL x y) 21 (Sub32F x y) -> (SUBSS x y) 22 (Sub64F x y) -> (SUBSD x y) 23 24 (Mul64 x y) -> (MULQ x y) 25 (Mul32 x y) -> (MULL x y) 26 (Mul16 x y) -> (MULL x y) 27 (Mul8 x y) -> (MULL x y) 28 (Mul32F x y) -> (MULSS x y) 29 (Mul64F x y) -> (MULSD x y) 30 31 (Div32F x y) -> (DIVSS x y) 32 (Div64F x y) -> (DIVSD x y) 33 34 (Div64 x y) -> (Select0 (DIVQ x y)) 35 (Div64u x y) -> (Select0 (DIVQU x y)) 36 (Div32 x y) -> (Select0 (DIVL x y)) 37 (Div32u x y) -> (Select0 (DIVLU x y)) 38 (Div16 x y) -> (Select0 (DIVW x y)) 39 (Div16u x y) -> (Select0 (DIVWU x y)) 40 (Div8 x y) -> (Select0 (DIVW (SignExt8to16 x) (SignExt8to16 y))) 41 (Div8u x y) -> (Select0 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y))) 42 43 (Hmul64 x y) -> (HMULQ x y) 44 (Hmul64u x y) -> (HMULQU x y) 45 (Hmul32 x y) -> (HMULL x y) 46 (Hmul32u x y) -> (HMULLU x y) 47 48 (Mul64uhilo x y) -> (MULQU2 x y) 49 (Div128u xhi xlo y) -> (DIVQU2 xhi xlo y) 50 51 (Avg64u x y) -> (AVGQU x y) 52 53 (Mod64 x y) -> (Select1 (DIVQ x y)) 54 (Mod64u x y) -> (Select1 (DIVQU x y)) 55 (Mod32 x y) -> (Select1 (DIVL x y)) 56 (Mod32u x y) -> (Select1 (DIVLU x y)) 57 (Mod16 x y) -> (Select1 (DIVW x y)) 58 (Mod16u x y) -> (Select1 (DIVWU x y)) 59 (Mod8 x y) -> (Select1 (DIVW (SignExt8to16 x) (SignExt8to16 y))) 60 (Mod8u x y) -> (Select1 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y))) 61 62 (And64 x y) -> (ANDQ x y) 63 (And32 x y) -> (ANDL x y) 64 (And16 x y) -> (ANDL x y) 65 (And8 x y) -> (ANDL x y) 66 67 (Or64 x y) -> (ORQ x y) 68 (Or32 x y) -> (ORL x y) 69 (Or16 x y) -> (ORL x y) 70 (Or8 x y) -> (ORL x y) 71 72 (Xor64 x y) -> (XORQ x y) 73 (Xor32 x y) -> (XORL x y) 74 (Xor16 x y) -> (XORL x y) 75 (Xor8 x y) -> (XORL x y) 76 77 (Neg64 x) -> (NEGQ x) 78 (Neg32 x) -> (NEGL x) 79 (Neg16 x) -> (NEGL x) 80 (Neg8 x) -> (NEGL x) 81 (Neg32F x) -> (PXOR x (MOVSSconst <typ.Float32> [f2i(math.Copysign(0, -1))])) 82 (Neg64F x) -> (PXOR x (MOVSDconst <typ.Float64> [f2i(math.Copysign(0, -1))])) 83 84 (Com64 x) -> (NOTQ x) 85 (Com32 x) -> (NOTL x) 86 (Com16 x) -> (NOTL x) 87 (Com8 x) -> (NOTL x) 88 89 // Lowering boolean ops 90 (AndB x y) -> (ANDL x y) 91 (OrB x y) -> (ORL x y) 92 (Not x) -> (XORLconst [1] x) 93 94 // Lowering pointer arithmetic 95 (OffPtr [off] ptr) && config.PtrSize == 8 && is32Bit(off) -> (ADDQconst [off] ptr) 96 (OffPtr [off] ptr) && config.PtrSize == 8 -> (ADDQ (MOVQconst [off]) ptr) 97 (OffPtr [off] ptr) && config.PtrSize == 4 -> (ADDLconst [off] ptr) 98 99 // Lowering other arithmetic 100 (Ctz64 <t> x) -> (CMOVQEQ (Select0 <t> (BSFQ x)) (MOVQconst <t> [64]) (Select1 <types.TypeFlags> (BSFQ x))) 101 (Ctz32 x) -> (Select0 (BSFQ (ORQ <typ.UInt64> (MOVQconst [1<<32]) x))) 102 103 (BitLen64 <t> x) -> (ADDQconst [1] (CMOVQEQ <t> (Select0 <t> (BSRQ x)) (MOVQconst <t> [-1]) (Select1 <types.TypeFlags> (BSRQ x)))) 104 (BitLen32 x) -> (BitLen64 (MOVLQZX <typ.UInt64> x)) 105 106 (Bswap64 x) -> (BSWAPQ x) 107 (Bswap32 x) -> (BSWAPL x) 108 109 (PopCount64 x) -> (POPCNTQ x) 110 (PopCount32 x) -> (POPCNTL x) 111 (PopCount16 x) -> (POPCNTL (MOVWQZX <typ.UInt32> x)) 112 (PopCount8 x) -> (POPCNTL (MOVBQZX <typ.UInt32> x)) 113 114 (Sqrt x) -> (SQRTSD x) 115 116 (RoundToEven x) -> (ROUNDSD [0] x) 117 (Floor x) -> (ROUNDSD [1] x) 118 (Ceil x) -> (ROUNDSD [2] x) 119 (Trunc x) -> (ROUNDSD [3] x) 120 121 // Lowering extension 122 // Note: we always extend to 64 bits even though some ops don't need that many result bits. 123 (SignExt8to16 x) -> (MOVBQSX x) 124 (SignExt8to32 x) -> (MOVBQSX x) 125 (SignExt8to64 x) -> (MOVBQSX x) 126 (SignExt16to32 x) -> (MOVWQSX x) 127 (SignExt16to64 x) -> (MOVWQSX x) 128 (SignExt32to64 x) -> (MOVLQSX x) 129 130 (ZeroExt8to16 x) -> (MOVBQZX x) 131 (ZeroExt8to32 x) -> (MOVBQZX x) 132 (ZeroExt8to64 x) -> (MOVBQZX x) 133 (ZeroExt16to32 x) -> (MOVWQZX x) 134 (ZeroExt16to64 x) -> (MOVWQZX x) 135 (ZeroExt32to64 x) -> (MOVLQZX x) 136 137 (Slicemask <t> x) -> (SARQconst (NEGQ <t> x) [63]) 138 139 // Lowering truncation 140 // Because we ignore high parts of registers, truncates are just copies. 141 (Trunc16to8 x) -> x 142 (Trunc32to8 x) -> x 143 (Trunc32to16 x) -> x 144 (Trunc64to8 x) -> x 145 (Trunc64to16 x) -> x 146 (Trunc64to32 x) -> x 147 148 // Lowering float <-> int 149 (Cvt32to32F x) -> (CVTSL2SS x) 150 (Cvt32to64F x) -> (CVTSL2SD x) 151 (Cvt64to32F x) -> (CVTSQ2SS x) 152 (Cvt64to64F x) -> (CVTSQ2SD x) 153 154 (Cvt32Fto32 x) -> (CVTTSS2SL x) 155 (Cvt32Fto64 x) -> (CVTTSS2SQ x) 156 (Cvt64Fto32 x) -> (CVTTSD2SL x) 157 (Cvt64Fto64 x) -> (CVTTSD2SQ x) 158 159 (Cvt32Fto64F x) -> (CVTSS2SD x) 160 (Cvt64Fto32F x) -> (CVTSD2SS x) 161 162 (Round32F x) -> x 163 (Round64F x) -> x 164 165 // Lowering shifts 166 // Unsigned shifts need to return 0 if shift amount is >= width of shifted value. 167 // result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff) 168 (Lsh64x64 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPQconst y [64]))) 169 (Lsh64x32 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPLconst y [64]))) 170 (Lsh64x16 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPWconst y [64]))) 171 (Lsh64x8 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPBconst y [64]))) 172 173 (Lsh32x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 174 (Lsh32x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 175 (Lsh32x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 176 (Lsh32x8 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 177 178 (Lsh16x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 179 (Lsh16x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 180 (Lsh16x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 181 (Lsh16x8 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 182 183 (Lsh8x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 184 (Lsh8x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 185 (Lsh8x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 186 (Lsh8x8 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 187 188 (Rsh64Ux64 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPQconst y [64]))) 189 (Rsh64Ux32 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPLconst y [64]))) 190 (Rsh64Ux16 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPWconst y [64]))) 191 (Rsh64Ux8 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPBconst y [64]))) 192 193 (Rsh32Ux64 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 194 (Rsh32Ux32 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 195 (Rsh32Ux16 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 196 (Rsh32Ux8 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 197 198 (Rsh16Ux64 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPQconst y [16]))) 199 (Rsh16Ux32 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPLconst y [16]))) 200 (Rsh16Ux16 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPWconst y [16]))) 201 (Rsh16Ux8 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPBconst y [16]))) 202 203 (Rsh8Ux64 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPQconst y [8]))) 204 (Rsh8Ux32 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPLconst y [8]))) 205 (Rsh8Ux16 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPWconst y [8]))) 206 (Rsh8Ux8 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPBconst y [8]))) 207 208 // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value. 209 // We implement this by setting the shift value to -1 (all ones) if the shift value is >= width. 210 (Rsh64x64 <t> x y) -> (SARQ <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [64]))))) 211 (Rsh64x32 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [64]))))) 212 (Rsh64x16 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [64]))))) 213 (Rsh64x8 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [64]))))) 214 215 (Rsh32x64 <t> x y) -> (SARL <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [32]))))) 216 (Rsh32x32 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [32]))))) 217 (Rsh32x16 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [32]))))) 218 (Rsh32x8 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [32]))))) 219 220 (Rsh16x64 <t> x y) -> (SARW <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [16]))))) 221 (Rsh16x32 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [16]))))) 222 (Rsh16x16 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [16]))))) 223 (Rsh16x8 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [16]))))) 224 225 (Rsh8x64 <t> x y) -> (SARB <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [8]))))) 226 (Rsh8x32 <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [8]))))) 227 (Rsh8x16 <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [8]))))) 228 (Rsh8x8 <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [8]))))) 229 230 // Lowering comparisons 231 (Less64 x y) -> (SETL (CMPQ x y)) 232 (Less32 x y) -> (SETL (CMPL x y)) 233 (Less16 x y) -> (SETL (CMPW x y)) 234 (Less8 x y) -> (SETL (CMPB x y)) 235 (Less64U x y) -> (SETB (CMPQ x y)) 236 (Less32U x y) -> (SETB (CMPL x y)) 237 (Less16U x y) -> (SETB (CMPW x y)) 238 (Less8U x y) -> (SETB (CMPB x y)) 239 // Use SETGF with reversed operands to dodge NaN case 240 (Less64F x y) -> (SETGF (UCOMISD y x)) 241 (Less32F x y) -> (SETGF (UCOMISS y x)) 242 243 (Leq64 x y) -> (SETLE (CMPQ x y)) 244 (Leq32 x y) -> (SETLE (CMPL x y)) 245 (Leq16 x y) -> (SETLE (CMPW x y)) 246 (Leq8 x y) -> (SETLE (CMPB x y)) 247 (Leq64U x y) -> (SETBE (CMPQ x y)) 248 (Leq32U x y) -> (SETBE (CMPL x y)) 249 (Leq16U x y) -> (SETBE (CMPW x y)) 250 (Leq8U x y) -> (SETBE (CMPB x y)) 251 // Use SETGEF with reversed operands to dodge NaN case 252 (Leq64F x y) -> (SETGEF (UCOMISD y x)) 253 (Leq32F x y) -> (SETGEF (UCOMISS y x)) 254 255 (Greater64 x y) -> (SETG (CMPQ x y)) 256 (Greater32 x y) -> (SETG (CMPL x y)) 257 (Greater16 x y) -> (SETG (CMPW x y)) 258 (Greater8 x y) -> (SETG (CMPB x y)) 259 (Greater64U x y) -> (SETA (CMPQ x y)) 260 (Greater32U x y) -> (SETA (CMPL x y)) 261 (Greater16U x y) -> (SETA (CMPW x y)) 262 (Greater8U x y) -> (SETA (CMPB x y)) 263 // Note Go assembler gets UCOMISx operand order wrong, but it is right here 264 // Bug is accommodated at generation of assembly language. 265 (Greater64F x y) -> (SETGF (UCOMISD x y)) 266 (Greater32F x y) -> (SETGF (UCOMISS x y)) 267 268 (Geq64 x y) -> (SETGE (CMPQ x y)) 269 (Geq32 x y) -> (SETGE (CMPL x y)) 270 (Geq16 x y) -> (SETGE (CMPW x y)) 271 (Geq8 x y) -> (SETGE (CMPB x y)) 272 (Geq64U x y) -> (SETAE (CMPQ x y)) 273 (Geq32U x y) -> (SETAE (CMPL x y)) 274 (Geq16U x y) -> (SETAE (CMPW x y)) 275 (Geq8U x y) -> (SETAE (CMPB x y)) 276 // Note Go assembler gets UCOMISx operand order wrong, but it is right here 277 // Bug is accommodated at generation of assembly language. 278 (Geq64F x y) -> (SETGEF (UCOMISD x y)) 279 (Geq32F x y) -> (SETGEF (UCOMISS x y)) 280 281 (Eq64 x y) -> (SETEQ (CMPQ x y)) 282 (Eq32 x y) -> (SETEQ (CMPL x y)) 283 (Eq16 x y) -> (SETEQ (CMPW x y)) 284 (Eq8 x y) -> (SETEQ (CMPB x y)) 285 (EqB x y) -> (SETEQ (CMPB x y)) 286 (EqPtr x y) && config.PtrSize == 8 -> (SETEQ (CMPQ x y)) 287 (EqPtr x y) && config.PtrSize == 4 -> (SETEQ (CMPL x y)) 288 (Eq64F x y) -> (SETEQF (UCOMISD x y)) 289 (Eq32F x y) -> (SETEQF (UCOMISS x y)) 290 291 (Neq64 x y) -> (SETNE (CMPQ x y)) 292 (Neq32 x y) -> (SETNE (CMPL x y)) 293 (Neq16 x y) -> (SETNE (CMPW x y)) 294 (Neq8 x y) -> (SETNE (CMPB x y)) 295 (NeqB x y) -> (SETNE (CMPB x y)) 296 (NeqPtr x y) && config.PtrSize == 8 -> (SETNE (CMPQ x y)) 297 (NeqPtr x y) && config.PtrSize == 4 -> (SETNE (CMPL x y)) 298 (Neq64F x y) -> (SETNEF (UCOMISD x y)) 299 (Neq32F x y) -> (SETNEF (UCOMISS x y)) 300 301 (Int64Hi x) -> (SHRQconst [32] x) // needed for amd64p32 302 303 // Lowering loads 304 (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t) && config.PtrSize == 8) -> (MOVQload ptr mem) 305 (Load <t> ptr mem) && (is32BitInt(t) || isPtr(t) && config.PtrSize == 4) -> (MOVLload ptr mem) 306 (Load <t> ptr mem) && is16BitInt(t) -> (MOVWload ptr mem) 307 (Load <t> ptr mem) && (t.IsBoolean() || is8BitInt(t)) -> (MOVBload ptr mem) 308 (Load <t> ptr mem) && is32BitFloat(t) -> (MOVSSload ptr mem) 309 (Load <t> ptr mem) && is64BitFloat(t) -> (MOVSDload ptr mem) 310 311 // Lowering stores 312 // These more-specific FP versions of Store pattern should come first. 313 (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 && is64BitFloat(val.Type) -> (MOVSDstore ptr val mem) 314 (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && is32BitFloat(val.Type) -> (MOVSSstore ptr val mem) 315 316 (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 -> (MOVQstore ptr val mem) 317 (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 -> (MOVLstore ptr val mem) 318 (Store {t} ptr val mem) && t.(*types.Type).Size() == 2 -> (MOVWstore ptr val mem) 319 (Store {t} ptr val mem) && t.(*types.Type).Size() == 1 -> (MOVBstore ptr val mem) 320 321 // Lowering moves 322 (Move [0] _ _ mem) -> mem 323 (Move [1] dst src mem) -> (MOVBstore dst (MOVBload src mem) mem) 324 (Move [2] dst src mem) -> (MOVWstore dst (MOVWload src mem) mem) 325 (Move [4] dst src mem) -> (MOVLstore dst (MOVLload src mem) mem) 326 (Move [8] dst src mem) -> (MOVQstore dst (MOVQload src mem) mem) 327 (Move [16] dst src mem) && config.useSSE -> (MOVOstore dst (MOVOload src mem) mem) 328 (Move [16] dst src mem) && !config.useSSE -> 329 (MOVQstore [8] dst (MOVQload [8] src mem) 330 (MOVQstore dst (MOVQload src mem) mem)) 331 (Move [3] dst src mem) -> 332 (MOVBstore [2] dst (MOVBload [2] src mem) 333 (MOVWstore dst (MOVWload src mem) mem)) 334 (Move [5] dst src mem) -> 335 (MOVBstore [4] dst (MOVBload [4] src mem) 336 (MOVLstore dst (MOVLload src mem) mem)) 337 (Move [6] dst src mem) -> 338 (MOVWstore [4] dst (MOVWload [4] src mem) 339 (MOVLstore dst (MOVLload src mem) mem)) 340 (Move [7] dst src mem) -> 341 (MOVLstore [3] dst (MOVLload [3] src mem) 342 (MOVLstore dst (MOVLload src mem) mem)) 343 (Move [s] dst src mem) && s > 8 && s < 16 -> 344 (MOVQstore [s-8] dst (MOVQload [s-8] src mem) 345 (MOVQstore dst (MOVQload src mem) mem)) 346 347 // Adjust moves to be a multiple of 16 bytes. 348 (Move [s] dst src mem) 349 && s > 16 && s%16 != 0 && s%16 <= 8 -> 350 (Move [s-s%16] 351 (OffPtr <dst.Type> dst [s%16]) 352 (OffPtr <src.Type> src [s%16]) 353 (MOVQstore dst (MOVQload src mem) mem)) 354 (Move [s] dst src mem) 355 && s > 16 && s%16 != 0 && s%16 > 8 && config.useSSE -> 356 (Move [s-s%16] 357 (OffPtr <dst.Type> dst [s%16]) 358 (OffPtr <src.Type> src [s%16]) 359 (MOVOstore dst (MOVOload src mem) mem)) 360 (Move [s] dst src mem) 361 && s > 16 && s%16 != 0 && s%16 > 8 && !config.useSSE -> 362 (Move [s-s%16] 363 (OffPtr <dst.Type> dst [s%16]) 364 (OffPtr <src.Type> src [s%16]) 365 (MOVQstore [8] dst (MOVQload [8] src mem) 366 (MOVQstore dst (MOVQload src mem) mem))) 367 368 // Medium copying uses a duff device. 369 (Move [s] dst src mem) 370 && s >= 32 && s <= 16*64 && s%16 == 0 371 && !config.noDuffDevice -> 372 (DUFFCOPY [14*(64-s/16)] dst src mem) 373 // 14 and 64 are magic constants. 14 is the number of bytes to encode: 374 // MOVUPS (SI), X0 375 // ADDQ $16, SI 376 // MOVUPS X0, (DI) 377 // ADDQ $16, DI 378 // and 64 is the number of such blocks. See src/runtime/duff_amd64.s:duffcopy. 379 380 // Large copying uses REP MOVSQ. 381 (Move [s] dst src mem) && (s > 16*64 || config.noDuffDevice) && s%8 == 0 -> 382 (REPMOVSQ dst src (MOVQconst [s/8]) mem) 383 384 // Lowering Zero instructions 385 (Zero [0] _ mem) -> mem 386 (Zero [1] destptr mem) -> (MOVBstoreconst [0] destptr mem) 387 (Zero [2] destptr mem) -> (MOVWstoreconst [0] destptr mem) 388 (Zero [4] destptr mem) -> (MOVLstoreconst [0] destptr mem) 389 (Zero [8] destptr mem) -> (MOVQstoreconst [0] destptr mem) 390 391 (Zero [3] destptr mem) -> 392 (MOVBstoreconst [makeValAndOff(0,2)] destptr 393 (MOVWstoreconst [0] destptr mem)) 394 (Zero [5] destptr mem) -> 395 (MOVBstoreconst [makeValAndOff(0,4)] destptr 396 (MOVLstoreconst [0] destptr mem)) 397 (Zero [6] destptr mem) -> 398 (MOVWstoreconst [makeValAndOff(0,4)] destptr 399 (MOVLstoreconst [0] destptr mem)) 400 (Zero [7] destptr mem) -> 401 (MOVLstoreconst [makeValAndOff(0,3)] destptr 402 (MOVLstoreconst [0] destptr mem)) 403 404 // Strip off any fractional word zeroing. 405 (Zero [s] destptr mem) && s%8 != 0 && s > 8 && !config.useSSE -> 406 (Zero [s-s%8] (OffPtr <destptr.Type> destptr [s%8]) 407 (MOVQstoreconst [0] destptr mem)) 408 409 // Zero small numbers of words directly. 410 (Zero [16] destptr mem) && !config.useSSE -> 411 (MOVQstoreconst [makeValAndOff(0,8)] destptr 412 (MOVQstoreconst [0] destptr mem)) 413 (Zero [24] destptr mem) && !config.useSSE -> 414 (MOVQstoreconst [makeValAndOff(0,16)] destptr 415 (MOVQstoreconst [makeValAndOff(0,8)] destptr 416 (MOVQstoreconst [0] destptr mem))) 417 (Zero [32] destptr mem) && !config.useSSE -> 418 (MOVQstoreconst [makeValAndOff(0,24)] destptr 419 (MOVQstoreconst [makeValAndOff(0,16)] destptr 420 (MOVQstoreconst [makeValAndOff(0,8)] destptr 421 (MOVQstoreconst [0] destptr mem)))) 422 423 (Zero [s] destptr mem) && s > 8 && s < 16 && config.useSSE -> 424 (MOVQstoreconst [makeValAndOff(0,s-8)] destptr 425 (MOVQstoreconst [0] destptr mem)) 426 427 // Adjust zeros to be a multiple of 16 bytes. 428 (Zero [s] destptr mem) && s%16 != 0 && s > 16 && s%16 > 8 && config.useSSE -> 429 (Zero [s-s%16] (OffPtr <destptr.Type> destptr [s%16]) 430 (MOVOstore destptr (MOVOconst [0]) mem)) 431 432 (Zero [s] destptr mem) && s%16 != 0 && s > 16 && s%16 <= 8 && config.useSSE -> 433 (Zero [s-s%16] (OffPtr <destptr.Type> destptr [s%16]) 434 (MOVQstoreconst [0] destptr mem)) 435 436 (Zero [16] destptr mem) && config.useSSE -> 437 (MOVOstore destptr (MOVOconst [0]) mem) 438 (Zero [32] destptr mem) && config.useSSE -> 439 (MOVOstore (OffPtr <destptr.Type> destptr [16]) (MOVOconst [0]) 440 (MOVOstore destptr (MOVOconst [0]) mem)) 441 (Zero [48] destptr mem) && config.useSSE -> 442 (MOVOstore (OffPtr <destptr.Type> destptr [32]) (MOVOconst [0]) 443 (MOVOstore (OffPtr <destptr.Type> destptr [16]) (MOVOconst [0]) 444 (MOVOstore destptr (MOVOconst [0]) mem))) 445 (Zero [64] destptr mem) && config.useSSE -> 446 (MOVOstore (OffPtr <destptr.Type> destptr [48]) (MOVOconst [0]) 447 (MOVOstore (OffPtr <destptr.Type> destptr [32]) (MOVOconst [0]) 448 (MOVOstore (OffPtr <destptr.Type> destptr [16]) (MOVOconst [0]) 449 (MOVOstore destptr (MOVOconst [0]) mem)))) 450 451 // Medium zeroing uses a duff device. 452 (Zero [s] destptr mem) 453 && s > 64 && s <= 1024 && s%16 == 0 && !config.noDuffDevice -> 454 (DUFFZERO [s] destptr (MOVOconst [0]) mem) 455 456 // Large zeroing uses REP STOSQ. 457 (Zero [s] destptr mem) 458 && (s > 1024 || (config.noDuffDevice && s > 64 || !config.useSSE && s > 32)) 459 && s%8 == 0 -> 460 (REPSTOSQ destptr (MOVQconst [s/8]) (MOVQconst [0]) mem) 461 462 // Lowering constants 463 (Const8 [val]) -> (MOVLconst [val]) 464 (Const16 [val]) -> (MOVLconst [val]) 465 (Const32 [val]) -> (MOVLconst [val]) 466 (Const64 [val]) -> (MOVQconst [val]) 467 (Const32F [val]) -> (MOVSSconst [val]) 468 (Const64F [val]) -> (MOVSDconst [val]) 469 (ConstNil) && config.PtrSize == 8 -> (MOVQconst [0]) 470 (ConstNil) && config.PtrSize == 4 -> (MOVLconst [0]) 471 (ConstBool [b]) -> (MOVLconst [b]) 472 473 // Lowering calls 474 (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem) 475 (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem) 476 (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem) 477 478 // Miscellaneous 479 (Convert <t> x mem) && config.PtrSize == 8 -> (MOVQconvert <t> x mem) 480 (Convert <t> x mem) && config.PtrSize == 4 -> (MOVLconvert <t> x mem) 481 (IsNonNil p) && config.PtrSize == 8 -> (SETNE (TESTQ p p)) 482 (IsNonNil p) && config.PtrSize == 4 -> (SETNE (TESTL p p)) 483 (IsInBounds idx len) && config.PtrSize == 8 -> (SETB (CMPQ idx len)) 484 (IsInBounds idx len) && config.PtrSize == 4 -> (SETB (CMPL idx len)) 485 (IsSliceInBounds idx len) && config.PtrSize == 8 -> (SETBE (CMPQ idx len)) 486 (IsSliceInBounds idx len) && config.PtrSize == 4 -> (SETBE (CMPL idx len)) 487 (NilCheck ptr mem) -> (LoweredNilCheck ptr mem) 488 (GetG mem) -> (LoweredGetG mem) 489 (GetClosurePtr) -> (LoweredGetClosurePtr) 490 (GetCallerPC) -> (LoweredGetCallerPC) 491 (GetCallerSP) -> (LoweredGetCallerSP) 492 (Addr {sym} base) && config.PtrSize == 8 -> (LEAQ {sym} base) 493 (Addr {sym} base) && config.PtrSize == 4 -> (LEAL {sym} base) 494 495 (MOVBstore [off] {sym} ptr y:(SETL x) mem) && y.Uses == 1 -> (SETLmem [off] {sym} ptr x mem) 496 (MOVBstore [off] {sym} ptr y:(SETLE x) mem) && y.Uses == 1 -> (SETLEmem [off] {sym} ptr x mem) 497 (MOVBstore [off] {sym} ptr y:(SETG x) mem) && y.Uses == 1 -> (SETGmem [off] {sym} ptr x mem) 498 (MOVBstore [off] {sym} ptr y:(SETGE x) mem) && y.Uses == 1 -> (SETGEmem [off] {sym} ptr x mem) 499 (MOVBstore [off] {sym} ptr y:(SETEQ x) mem) && y.Uses == 1 -> (SETEQmem [off] {sym} ptr x mem) 500 (MOVBstore [off] {sym} ptr y:(SETNE x) mem) && y.Uses == 1 -> (SETNEmem [off] {sym} ptr x mem) 501 (MOVBstore [off] {sym} ptr y:(SETB x) mem) && y.Uses == 1 -> (SETBmem [off] {sym} ptr x mem) 502 (MOVBstore [off] {sym} ptr y:(SETBE x) mem) && y.Uses == 1 -> (SETBEmem [off] {sym} ptr x mem) 503 (MOVBstore [off] {sym} ptr y:(SETA x) mem) && y.Uses == 1 -> (SETAmem [off] {sym} ptr x mem) 504 (MOVBstore [off] {sym} ptr y:(SETAE x) mem) && y.Uses == 1 -> (SETAEmem [off] {sym} ptr x mem) 505 506 // block rewrites 507 (If (SETL cmp) yes no) -> (LT cmp yes no) 508 (If (SETLE cmp) yes no) -> (LE cmp yes no) 509 (If (SETG cmp) yes no) -> (GT cmp yes no) 510 (If (SETGE cmp) yes no) -> (GE cmp yes no) 511 (If (SETEQ cmp) yes no) -> (EQ cmp yes no) 512 (If (SETNE cmp) yes no) -> (NE cmp yes no) 513 (If (SETB cmp) yes no) -> (ULT cmp yes no) 514 (If (SETBE cmp) yes no) -> (ULE cmp yes no) 515 (If (SETA cmp) yes no) -> (UGT cmp yes no) 516 (If (SETAE cmp) yes no) -> (UGE cmp yes no) 517 518 // Special case for floating point - LF/LEF not generated 519 (If (SETGF cmp) yes no) -> (UGT cmp yes no) 520 (If (SETGEF cmp) yes no) -> (UGE cmp yes no) 521 (If (SETEQF cmp) yes no) -> (EQF cmp yes no) 522 (If (SETNEF cmp) yes no) -> (NEF cmp yes no) 523 524 (If cond yes no) -> (NE (TESTB cond cond) yes no) 525 526 // Atomic loads. Other than preserving their ordering with respect to other loads, nothing special here. 527 (AtomicLoad32 ptr mem) -> (MOVLatomicload ptr mem) 528 (AtomicLoad64 ptr mem) -> (MOVQatomicload ptr mem) 529 (AtomicLoadPtr ptr mem) && config.PtrSize == 8 -> (MOVQatomicload ptr mem) 530 (AtomicLoadPtr ptr mem) && config.PtrSize == 4 -> (MOVLatomicload ptr mem) 531 532 // Atomic stores. We use XCHG to prevent the hardware reordering a subsequent load. 533 // TODO: most runtime uses of atomic stores don't need that property. Use normal stores for those? 534 (AtomicStore32 ptr val mem) -> (Select1 (XCHGL <types.NewTuple(typ.UInt32,types.TypeMem)> val ptr mem)) 535 (AtomicStore64 ptr val mem) -> (Select1 (XCHGQ <types.NewTuple(typ.UInt64,types.TypeMem)> val ptr mem)) 536 (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 8 -> (Select1 (XCHGQ <types.NewTuple(typ.BytePtr,types.TypeMem)> val ptr mem)) 537 (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 4 -> (Select1 (XCHGL <types.NewTuple(typ.BytePtr,types.TypeMem)> val ptr mem)) 538 539 // Atomic exchanges. 540 (AtomicExchange32 ptr val mem) -> (XCHGL val ptr mem) 541 (AtomicExchange64 ptr val mem) -> (XCHGQ val ptr mem) 542 543 // Atomic adds. 544 (AtomicAdd32 ptr val mem) -> (AddTupleFirst32 val (XADDLlock val ptr mem)) 545 (AtomicAdd64 ptr val mem) -> (AddTupleFirst64 val (XADDQlock val ptr mem)) 546 (Select0 <t> (AddTupleFirst32 val tuple)) -> (ADDL val (Select0 <t> tuple)) 547 (Select1 (AddTupleFirst32 _ tuple)) -> (Select1 tuple) 548 (Select0 <t> (AddTupleFirst64 val tuple)) -> (ADDQ val (Select0 <t> tuple)) 549 (Select1 (AddTupleFirst64 _ tuple)) -> (Select1 tuple) 550 551 // Atomic compare and swap. 552 (AtomicCompareAndSwap32 ptr old new_ mem) -> (CMPXCHGLlock ptr old new_ mem) 553 (AtomicCompareAndSwap64 ptr old new_ mem) -> (CMPXCHGQlock ptr old new_ mem) 554 555 // Atomic memory updates. 556 (AtomicAnd8 ptr val mem) -> (ANDBlock ptr val mem) 557 (AtomicOr8 ptr val mem) -> (ORBlock ptr val mem) 558 559 // Write barrier. 560 (WB {fn} destptr srcptr mem) -> (LoweredWB {fn} destptr srcptr mem) 561 562 // *************************** 563 // Above: lowering rules 564 // Below: optimizations 565 // *************************** 566 // TODO: Should the optimizations be a separate pass? 567 568 // Fold boolean tests into blocks 569 (NE (TESTB (SETL cmp) (SETL cmp)) yes no) -> (LT cmp yes no) 570 (NE (TESTB (SETLE cmp) (SETLE cmp)) yes no) -> (LE cmp yes no) 571 (NE (TESTB (SETG cmp) (SETG cmp)) yes no) -> (GT cmp yes no) 572 (NE (TESTB (SETGE cmp) (SETGE cmp)) yes no) -> (GE cmp yes no) 573 (NE (TESTB (SETEQ cmp) (SETEQ cmp)) yes no) -> (EQ cmp yes no) 574 (NE (TESTB (SETNE cmp) (SETNE cmp)) yes no) -> (NE cmp yes no) 575 (NE (TESTB (SETB cmp) (SETB cmp)) yes no) -> (ULT cmp yes no) 576 (NE (TESTB (SETBE cmp) (SETBE cmp)) yes no) -> (ULE cmp yes no) 577 (NE (TESTB (SETA cmp) (SETA cmp)) yes no) -> (UGT cmp yes no) 578 (NE (TESTB (SETAE cmp) (SETAE cmp)) yes no) -> (UGE cmp yes no) 579 580 // Recognize bit tests: a&(1<<b) != 0 for b suitably bounded 581 // Note that ULT and SETB check the carry flag; they are identical to CS and SETCS. 582 // Same, mutatis mutandis, for UGE and SETAE, and CC and SETCC. 583 (NE (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (ULT (BTL x y)) 584 (EQ (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (UGE (BTL x y)) 585 (NE (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (ULT (BTQ x y)) 586 (EQ (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (UGE (BTQ x y)) 587 (NE (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (ULT (BTLconst [log2(c)] x)) 588 (EQ (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (UGE (BTLconst [log2(c)] x)) 589 (NE (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (ULT (BTQconst [log2(c)] x)) 590 (EQ (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (UGE (BTQconst [log2(c)] x)) 591 (NE (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (ULT (BTQconst [log2(c)] x)) 592 (EQ (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (UGE (BTQconst [log2(c)] x)) 593 (SETNE (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (SETB (BTL x y)) 594 (SETEQ (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (SETAE (BTL x y)) 595 (SETNE (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (SETB (BTQ x y)) 596 (SETEQ (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (SETAE (BTQ x y)) 597 (SETNE (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (SETB (BTLconst [log2(c)] x)) 598 (SETEQ (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (SETAE (BTLconst [log2(c)] x)) 599 (SETNE (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETB (BTQconst [log2(c)] x)) 600 (SETEQ (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETAE (BTQconst [log2(c)] x)) 601 (SETNE (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETB (BTQconst [log2(c)] x)) 602 (SETEQ (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETAE (BTQconst [log2(c)] x)) 603 // SET..mem variant 604 (SETNEmem [off] {sym} ptr (TESTL (SHLL (MOVLconst [1]) x) y) mem) && !config.nacl -> (SETBmem [off] {sym} ptr (BTL x y) mem) 605 (SETEQmem [off] {sym} ptr (TESTL (SHLL (MOVLconst [1]) x) y) mem) && !config.nacl -> (SETAEmem [off] {sym} ptr (BTL x y) mem) 606 (SETNEmem [off] {sym} ptr (TESTQ (SHLQ (MOVQconst [1]) x) y) mem) && !config.nacl -> (SETBmem [off] {sym} ptr (BTQ x y) mem) 607 (SETEQmem [off] {sym} ptr (TESTQ (SHLQ (MOVQconst [1]) x) y) mem) && !config.nacl -> (SETAEmem [off] {sym} ptr (BTQ x y) mem) 608 (SETNEmem [off] {sym} ptr (TESTLconst [c] x) mem) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (SETBmem [off] {sym} ptr (BTLconst [log2(c)] x) mem) 609 (SETEQmem [off] {sym} ptr (TESTLconst [c] x) mem) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (SETAEmem [off] {sym} ptr (BTLconst [log2(c)] x) mem) 610 (SETNEmem [off] {sym} ptr (TESTQconst [c] x) mem) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETBmem [off] {sym} ptr (BTQconst [log2(c)] x) mem) 611 (SETEQmem [off] {sym} ptr (TESTQconst [c] x) mem) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETAEmem [off] {sym} ptr (BTQconst [log2(c)] x) mem) 612 (SETNEmem [off] {sym} ptr (TESTQ (MOVQconst [c]) x) mem) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETBmem [off] {sym} ptr (BTQconst [log2(c)] x) mem) 613 (SETEQmem [off] {sym} ptr (TESTQ (MOVQconst [c]) x) mem) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETAEmem [off] {sym} ptr (BTQconst [log2(c)] x) mem) 614 615 // Fold boolean negation into SETcc. 616 (XORLconst [1] (SETNE x)) -> (SETEQ x) 617 (XORLconst [1] (SETEQ x)) -> (SETNE x) 618 (XORLconst [1] (SETL x)) -> (SETGE x) 619 (XORLconst [1] (SETGE x)) -> (SETL x) 620 (XORLconst [1] (SETLE x)) -> (SETG x) 621 (XORLconst [1] (SETG x)) -> (SETLE x) 622 (XORLconst [1] (SETB x)) -> (SETAE x) 623 (XORLconst [1] (SETAE x)) -> (SETB x) 624 (XORLconst [1] (SETBE x)) -> (SETA x) 625 (XORLconst [1] (SETA x)) -> (SETBE x) 626 627 // Convert BTQconst to BTLconst if possible. It has a shorter encoding. 628 (BTQconst [c] x) && c < 32 -> (BTLconst [c] x) 629 630 // Special case for floating point - LF/LEF not generated 631 (NE (TESTB (SETGF cmp) (SETGF cmp)) yes no) -> (UGT cmp yes no) 632 (NE (TESTB (SETGEF cmp) (SETGEF cmp)) yes no) -> (UGE cmp yes no) 633 (NE (TESTB (SETEQF cmp) (SETEQF cmp)) yes no) -> (EQF cmp yes no) 634 (NE (TESTB (SETNEF cmp) (SETNEF cmp)) yes no) -> (NEF cmp yes no) 635 636 // Disabled because it interferes with the pattern match above and makes worse code. 637 // (SETNEF x) -> (ORQ (SETNE <typ.Int8> x) (SETNAN <typ.Int8> x)) 638 // (SETEQF x) -> (ANDQ (SETEQ <typ.Int8> x) (SETORD <typ.Int8> x)) 639 640 // fold constants into instructions 641 (ADDQ x (MOVQconst [c])) && is32Bit(c) -> (ADDQconst [c] x) 642 (ADDL x (MOVLconst [c])) -> (ADDLconst [c] x) 643 644 (SUBQ x (MOVQconst [c])) && is32Bit(c) -> (SUBQconst x [c]) 645 (SUBQ (MOVQconst [c]) x) && is32Bit(c) -> (NEGQ (SUBQconst <v.Type> x [c])) 646 (SUBL x (MOVLconst [c])) -> (SUBLconst x [c]) 647 (SUBL (MOVLconst [c]) x) -> (NEGL (SUBLconst <v.Type> x [c])) 648 649 (MULQ x (MOVQconst [c])) && is32Bit(c) -> (MULQconst [c] x) 650 (MULL x (MOVLconst [c])) -> (MULLconst [c] x) 651 652 (ANDQ x (MOVQconst [c])) && is32Bit(c) -> (ANDQconst [c] x) 653 (ANDL x (MOVLconst [c])) -> (ANDLconst [c] x) 654 655 (ANDLconst [c] (ANDLconst [d] x)) -> (ANDLconst [c & d] x) 656 (ANDQconst [c] (ANDQconst [d] x)) -> (ANDQconst [c & d] x) 657 658 (XORLconst [c] (XORLconst [d] x)) -> (XORLconst [c ^ d] x) 659 (XORQconst [c] (XORQconst [d] x)) -> (XORQconst [c ^ d] x) 660 661 (MULLconst [c] (MULLconst [d] x)) -> (MULLconst [int64(int32(c * d))] x) 662 (MULQconst [c] (MULQconst [d] x)) && is32Bit(c*d) -> (MULQconst [c * d] x) 663 664 (ORQ x (MOVQconst [c])) && is32Bit(c) -> (ORQconst [c] x) 665 (ORL x (MOVLconst [c])) -> (ORLconst [c] x) 666 667 (XORQ x (MOVQconst [c])) && is32Bit(c) -> (XORQconst [c] x) 668 (XORL x (MOVLconst [c])) -> (XORLconst [c] x) 669 670 (SHLQ x (MOVQconst [c])) -> (SHLQconst [c&63] x) 671 (SHLQ x (MOVLconst [c])) -> (SHLQconst [c&63] x) 672 673 (SHLL x (MOVQconst [c])) -> (SHLLconst [c&31] x) 674 (SHLL x (MOVLconst [c])) -> (SHLLconst [c&31] x) 675 676 (SHRQ x (MOVQconst [c])) -> (SHRQconst [c&63] x) 677 (SHRQ x (MOVLconst [c])) -> (SHRQconst [c&63] x) 678 679 (SHRL x (MOVQconst [c])) -> (SHRLconst [c&31] x) 680 (SHRL x (MOVLconst [c])) -> (SHRLconst [c&31] x) 681 682 (SHRW x (MOVQconst [c])) && c&31 < 16 -> (SHRWconst [c&31] x) 683 (SHRW x (MOVLconst [c])) && c&31 < 16 -> (SHRWconst [c&31] x) 684 (SHRW _ (MOVQconst [c])) && c&31 >= 16 -> (MOVLconst [0]) 685 (SHRW _ (MOVLconst [c])) && c&31 >= 16 -> (MOVLconst [0]) 686 687 (SHRB x (MOVQconst [c])) && c&31 < 8 -> (SHRBconst [c&31] x) 688 (SHRB x (MOVLconst [c])) && c&31 < 8 -> (SHRBconst [c&31] x) 689 (SHRB _ (MOVQconst [c])) && c&31 >= 8 -> (MOVLconst [0]) 690 (SHRB _ (MOVLconst [c])) && c&31 >= 8 -> (MOVLconst [0]) 691 692 (SARQ x (MOVQconst [c])) -> (SARQconst [c&63] x) 693 (SARQ x (MOVLconst [c])) -> (SARQconst [c&63] x) 694 695 (SARL x (MOVQconst [c])) -> (SARLconst [c&31] x) 696 (SARL x (MOVLconst [c])) -> (SARLconst [c&31] x) 697 698 (SARW x (MOVQconst [c])) -> (SARWconst [min(c&31,15)] x) 699 (SARW x (MOVLconst [c])) -> (SARWconst [min(c&31,15)] x) 700 701 (SARB x (MOVQconst [c])) -> (SARBconst [min(c&31,7)] x) 702 (SARB x (MOVLconst [c])) -> (SARBconst [min(c&31,7)] x) 703 704 // Operations which don't affect the low 6/5 bits of the shift amount are NOPs. 705 (SHLQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SHLQ x y) 706 (SHRQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SHRQ x y) 707 (SARQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SARQ x y) 708 (SHLQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SHLQ x (NEGQ <t> y)) 709 (SHRQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SHRQ x (NEGQ <t> y)) 710 (SARQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SARQ x (NEGQ <t> y)) 711 (SHLQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SHLQ x y) 712 (SHRQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SHRQ x y) 713 (SARQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SARQ x y) 714 (SHLQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SHLQ x (NEGQ <t> y)) 715 (SHRQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SHRQ x (NEGQ <t> y)) 716 (SARQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SARQ x (NEGQ <t> y)) 717 718 (SHLL x (ADDQconst [c] y)) && c & 31 == 0 -> (SHLL x y) 719 (SHRL x (ADDQconst [c] y)) && c & 31 == 0 -> (SHRL x y) 720 (SARL x (ADDQconst [c] y)) && c & 31 == 0 -> (SARL x y) 721 (SHLL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SHLL x (NEGQ <t> y)) 722 (SHRL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SHRL x (NEGQ <t> y)) 723 (SARL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SARL x (NEGQ <t> y)) 724 (SHLL x (ANDQconst [c] y)) && c & 31 == 31 -> (SHLL x y) 725 (SHRL x (ANDQconst [c] y)) && c & 31 == 31 -> (SHRL x y) 726 (SARL x (ANDQconst [c] y)) && c & 31 == 31 -> (SARL x y) 727 (SHLL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SHLL x (NEGQ <t> y)) 728 (SHRL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SHRL x (NEGQ <t> y)) 729 (SARL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SARL x (NEGQ <t> y)) 730 731 (SHLQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SHLQ x y) 732 (SHRQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SHRQ x y) 733 (SARQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SARQ x y) 734 (SHLQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SHLQ x (NEGL <t> y)) 735 (SHRQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SHRQ x (NEGL <t> y)) 736 (SARQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SARQ x (NEGL <t> y)) 737 (SHLQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SHLQ x y) 738 (SHRQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SHRQ x y) 739 (SARQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SARQ x y) 740 (SHLQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SHLQ x (NEGL <t> y)) 741 (SHRQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SHRQ x (NEGL <t> y)) 742 (SARQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SARQ x (NEGL <t> y)) 743 744 (SHLL x (ADDLconst [c] y)) && c & 31 == 0 -> (SHLL x y) 745 (SHRL x (ADDLconst [c] y)) && c & 31 == 0 -> (SHRL x y) 746 (SARL x (ADDLconst [c] y)) && c & 31 == 0 -> (SARL x y) 747 (SHLL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SHLL x (NEGL <t> y)) 748 (SHRL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SHRL x (NEGL <t> y)) 749 (SARL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SARL x (NEGL <t> y)) 750 (SHLL x (ANDLconst [c] y)) && c & 31 == 31 -> (SHLL x y) 751 (SHRL x (ANDLconst [c] y)) && c & 31 == 31 -> (SHRL x y) 752 (SARL x (ANDLconst [c] y)) && c & 31 == 31 -> (SARL x y) 753 (SHLL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SHLL x (NEGL <t> y)) 754 (SHRL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SHRL x (NEGL <t> y)) 755 (SARL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SARL x (NEGL <t> y)) 756 757 // Constant rotate instructions 758 (ADDQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 759 ( ORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 760 (XORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 761 762 (ADDL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 763 ( ORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 764 (XORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 765 766 (ADDL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 767 ( ORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 768 (XORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 769 770 (ADDL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 771 ( ORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 772 (XORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 773 774 (ROLQconst [c] (ROLQconst [d] x)) -> (ROLQconst [(c+d)&63] x) 775 (ROLLconst [c] (ROLLconst [d] x)) -> (ROLLconst [(c+d)&31] x) 776 (ROLWconst [c] (ROLWconst [d] x)) -> (ROLWconst [(c+d)&15] x) 777 (ROLBconst [c] (ROLBconst [d] x)) -> (ROLBconst [(c+d)& 7] x) 778 779 // Non-constant rotates. 780 // We want to issue a rotate when the Go source contains code like 781 // y &= 63 782 // x << y | x >> (64-y) 783 // The shift rules above convert << to SHLx and >> to SHRx. 784 // SHRx converts its shift argument from 64-y to -y. 785 // A tricky situation occurs when y==0. Then the original code would be: 786 // x << 0 | x >> 64 787 // But x >> 64 is 0, not x. So there's an additional mask that is ANDed in 788 // to force the second term to 0. We don't need that mask, but we must match 789 // it in order to strip it out. 790 (ORQ (SHLQ x y) (ANDQ (SHRQ x (NEGQ y)) (SBBQcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [63]) [-64])) [64])))) -> (ROLQ x y) 791 (ORQ (SHLQ x y) (ANDQ (SHRQ x (NEGL y)) (SBBQcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [63]) [-64])) [64])))) -> (ROLQ x y) 792 (ORQ (SHRQ x y) (ANDQ (SHLQ x (NEGQ y)) (SBBQcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [63]) [-64])) [64])))) -> (RORQ x y) 793 (ORQ (SHRQ x y) (ANDQ (SHLQ x (NEGL y)) (SBBQcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [63]) [-64])) [64])))) -> (RORQ x y) 794 795 (ORL (SHLL x y) (ANDL (SHRL x (NEGQ y)) (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [31]) [-32])) [32])))) -> (ROLL x y) 796 (ORL (SHLL x y) (ANDL (SHRL x (NEGL y)) (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [31]) [-32])) [32])))) -> (ROLL x y) 797 (ORL (SHRL x y) (ANDL (SHLL x (NEGQ y)) (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [31]) [-32])) [32])))) -> (RORL x y) 798 (ORL (SHRL x y) (ANDL (SHLL x (NEGL y)) (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [31]) [-32])) [32])))) -> (RORL x y) 799 800 // Help with rotate detection 801 (CMPQconst (NEGQ (ADDQconst [-16] (ANDQconst [15] _))) [32]) -> (FlagLT_ULT) 802 (CMPQconst (NEGQ (ADDQconst [ -8] (ANDQconst [7] _))) [32]) -> (FlagLT_ULT) 803 804 (ORL (SHLL x (ANDQconst y [15])) 805 (ANDL (SHRW x (NEGQ (ADDQconst (ANDQconst y [15]) [-16]))) 806 (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [15]) [-16])) [16])))) 807 && v.Type.Size() == 2 808 -> (ROLW x y) 809 (ORL (SHLL x (ANDLconst y [15])) 810 (ANDL (SHRW x (NEGL (ADDLconst (ANDLconst y [15]) [-16]))) 811 (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [15]) [-16])) [16])))) 812 && v.Type.Size() == 2 813 -> (ROLW x y) 814 (ORL (SHRW x (ANDQconst y [15])) 815 (SHLL x (NEGQ (ADDQconst (ANDQconst y [15]) [-16])))) 816 && v.Type.Size() == 2 817 -> (RORW x y) 818 (ORL (SHRW x (ANDLconst y [15])) 819 (SHLL x (NEGL (ADDLconst (ANDLconst y [15]) [-16])))) 820 && v.Type.Size() == 2 821 -> (RORW x y) 822 823 (ORL (SHLL x (ANDQconst y [ 7])) 824 (ANDL (SHRB x (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8]))) 825 (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8])) [ 8])))) 826 && v.Type.Size() == 1 827 -> (ROLB x y) 828 (ORL (SHLL x (ANDLconst y [ 7])) 829 (ANDL (SHRB x (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8]))) 830 (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8])) [ 8])))) 831 && v.Type.Size() == 1 832 -> (ROLB x y) 833 (ORL (SHRB x (ANDQconst y [ 7])) 834 (SHLL x (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8])))) 835 && v.Type.Size() == 1 836 -> (RORB x y) 837 (ORL (SHRB x (ANDLconst y [ 7])) 838 (SHLL x (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8])))) 839 && v.Type.Size() == 1 840 -> (RORB x y) 841 842 // rotate left negative = rotate right 843 (ROLQ x (NEGQ y)) -> (RORQ x y) 844 (ROLQ x (NEGL y)) -> (RORQ x y) 845 (ROLL x (NEGQ y)) -> (RORL x y) 846 (ROLL x (NEGL y)) -> (RORL x y) 847 (ROLW x (NEGQ y)) -> (RORW x y) 848 (ROLW x (NEGL y)) -> (RORW x y) 849 (ROLB x (NEGQ y)) -> (RORB x y) 850 (ROLB x (NEGL y)) -> (RORB x y) 851 852 // rotate right negative = rotate left 853 (RORQ x (NEGQ y)) -> (ROLQ x y) 854 (RORQ x (NEGL y)) -> (ROLQ x y) 855 (RORL x (NEGQ y)) -> (ROLL x y) 856 (RORL x (NEGL y)) -> (ROLL x y) 857 (RORW x (NEGQ y)) -> (ROLW x y) 858 (RORW x (NEGL y)) -> (ROLW x y) 859 (RORB x (NEGQ y)) -> (ROLB x y) 860 (RORB x (NEGL y)) -> (ROLB x y) 861 862 // rotate by constants 863 (ROLQ x (MOVQconst [c])) -> (ROLQconst [c&63] x) 864 (ROLQ x (MOVLconst [c])) -> (ROLQconst [c&63] x) 865 (ROLL x (MOVQconst [c])) -> (ROLLconst [c&31] x) 866 (ROLL x (MOVLconst [c])) -> (ROLLconst [c&31] x) 867 (ROLW x (MOVQconst [c])) -> (ROLWconst [c&15] x) 868 (ROLW x (MOVLconst [c])) -> (ROLWconst [c&15] x) 869 (ROLB x (MOVQconst [c])) -> (ROLBconst [c&7 ] x) 870 (ROLB x (MOVLconst [c])) -> (ROLBconst [c&7 ] x) 871 872 (RORQ x (MOVQconst [c])) -> (ROLQconst [(-c)&63] x) 873 (RORQ x (MOVLconst [c])) -> (ROLQconst [(-c)&63] x) 874 (RORL x (MOVQconst [c])) -> (ROLLconst [(-c)&31] x) 875 (RORL x (MOVLconst [c])) -> (ROLLconst [(-c)&31] x) 876 (RORW x (MOVQconst [c])) -> (ROLWconst [(-c)&15] x) 877 (RORW x (MOVLconst [c])) -> (ROLWconst [(-c)&15] x) 878 (RORB x (MOVQconst [c])) -> (ROLBconst [(-c)&7 ] x) 879 (RORB x (MOVLconst [c])) -> (ROLBconst [(-c)&7 ] x) 880 881 // Constant shift simplifications 882 (SHLQconst x [0]) -> x 883 (SHRQconst x [0]) -> x 884 (SARQconst x [0]) -> x 885 886 (SHLLconst x [0]) -> x 887 (SHRLconst x [0]) -> x 888 (SARLconst x [0]) -> x 889 890 (SHRWconst x [0]) -> x 891 (SARWconst x [0]) -> x 892 893 (SHRBconst x [0]) -> x 894 (SARBconst x [0]) -> x 895 896 (ROLQconst x [0]) -> x 897 (ROLLconst x [0]) -> x 898 (ROLWconst x [0]) -> x 899 (ROLBconst x [0]) -> x 900 901 // Note: the word and byte shifts keep the low 5 bits (not the low 4 or 3 bits) 902 // because the x86 instructions are defined to use all 5 bits of the shift even 903 // for the small shifts. I don't think we'll ever generate a weird shift (e.g. 904 // (SHRW x (MOVLconst [24])), but just in case. 905 906 (CMPQ x (MOVQconst [c])) && is32Bit(c) -> (CMPQconst x [c]) 907 (CMPQ (MOVQconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPQconst x [c])) 908 (CMPL x (MOVLconst [c])) -> (CMPLconst x [c]) 909 (CMPL (MOVLconst [c]) x) -> (InvertFlags (CMPLconst x [c])) 910 (CMPW x (MOVLconst [c])) -> (CMPWconst x [int64(int16(c))]) 911 (CMPW (MOVLconst [c]) x) -> (InvertFlags (CMPWconst x [int64(int16(c))])) 912 (CMPB x (MOVLconst [c])) -> (CMPBconst x [int64(int8(c))]) 913 (CMPB (MOVLconst [c]) x) -> (InvertFlags (CMPBconst x [int64(int8(c))])) 914 915 // Using MOVZX instead of AND is cheaper. 916 (ANDLconst [0xFF] x) -> (MOVBQZX x) 917 (ANDLconst [0xFFFF] x) -> (MOVWQZX x) 918 (ANDQconst [0xFF] x) -> (MOVBQZX x) 919 (ANDQconst [0xFFFF] x) -> (MOVWQZX x) 920 (ANDQconst [0xFFFFFFFF] x) -> (MOVLQZX x) 921 922 // strength reduction 923 // Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf: 924 // 1 - addq, shlq, leaq, negq 925 // 3 - imulq 926 // This limits the rewrites to two instructions. 927 // TODO: 27, 81 928 (MULQconst [-1] x) -> (NEGQ x) 929 (MULQconst [0] _) -> (MOVQconst [0]) 930 (MULQconst [1] x) -> x 931 (MULQconst [3] x) -> (LEAQ2 x x) 932 (MULQconst [5] x) -> (LEAQ4 x x) 933 (MULQconst [7] x) -> (LEAQ8 (NEGQ <v.Type> x) x) 934 (MULQconst [9] x) -> (LEAQ8 x x) 935 (MULQconst [11] x) -> (LEAQ2 x (LEAQ4 <v.Type> x x)) 936 (MULQconst [13] x) -> (LEAQ4 x (LEAQ2 <v.Type> x x)) 937 (MULQconst [21] x) -> (LEAQ4 x (LEAQ4 <v.Type> x x)) 938 (MULQconst [25] x) -> (LEAQ8 x (LEAQ2 <v.Type> x x)) 939 (MULQconst [37] x) -> (LEAQ4 x (LEAQ8 <v.Type> x x)) 940 (MULQconst [41] x) -> (LEAQ8 x (LEAQ4 <v.Type> x x)) 941 (MULQconst [73] x) -> (LEAQ8 x (LEAQ8 <v.Type> x x)) 942 943 (MULQconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUBQ (SHLQconst <v.Type> [log2(c+1)] x) x) 944 (MULQconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (LEAQ1 (SHLQconst <v.Type> [log2(c-1)] x) x) 945 (MULQconst [c] x) && isPowerOfTwo(c-2) && c >= 34 -> (LEAQ2 (SHLQconst <v.Type> [log2(c-2)] x) x) 946 (MULQconst [c] x) && isPowerOfTwo(c-4) && c >= 68 -> (LEAQ4 (SHLQconst <v.Type> [log2(c-4)] x) x) 947 (MULQconst [c] x) && isPowerOfTwo(c-8) && c >= 136 -> (LEAQ8 (SHLQconst <v.Type> [log2(c-8)] x) x) 948 (MULQconst [c] x) && c%3 == 0 && isPowerOfTwo(c/3) -> (SHLQconst [log2(c/3)] (LEAQ2 <v.Type> x x)) 949 (MULQconst [c] x) && c%5 == 0 && isPowerOfTwo(c/5) -> (SHLQconst [log2(c/5)] (LEAQ4 <v.Type> x x)) 950 (MULQconst [c] x) && c%9 == 0 && isPowerOfTwo(c/9) -> (SHLQconst [log2(c/9)] (LEAQ8 <v.Type> x x)) 951 952 // combine add/shift into LEAQ 953 (ADDQ x (SHLQconst [3] y)) -> (LEAQ8 x y) 954 (ADDQ x (SHLQconst [2] y)) -> (LEAQ4 x y) 955 (ADDQ x (SHLQconst [1] y)) -> (LEAQ2 x y) 956 (ADDQ x (ADDQ y y)) -> (LEAQ2 x y) 957 (ADDQ x (ADDQ x y)) -> (LEAQ2 y x) 958 959 // combine ADDQ/ADDQconst into LEAQ1 960 (ADDQconst [c] (ADDQ x y)) -> (LEAQ1 [c] x y) 961 (ADDQ (ADDQconst [c] x) y) -> (LEAQ1 [c] x y) 962 963 // fold ADDQ into LEAQ 964 (ADDQconst [c] (LEAQ [d] {s} x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 965 (LEAQ [c] {s} (ADDQconst [d] x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 966 (LEAQ [c] {s} (ADDQ x y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 967 (ADDQ x (LEAQ [c] {s} y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 968 969 // fold ADDQconst into LEAQx 970 (ADDQconst [c] (LEAQ1 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ1 [c+d] {s} x y) 971 (ADDQconst [c] (LEAQ2 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ2 [c+d] {s} x y) 972 (ADDQconst [c] (LEAQ4 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ4 [c+d] {s} x y) 973 (ADDQconst [c] (LEAQ8 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ8 [c+d] {s} x y) 974 (LEAQ1 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ1 [c+d] {s} x y) 975 (LEAQ2 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ2 [c+d] {s} x y) 976 (LEAQ2 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+2*d) && y.Op != OpSB -> (LEAQ2 [c+2*d] {s} x y) 977 (LEAQ4 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ4 [c+d] {s} x y) 978 (LEAQ4 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+4*d) && y.Op != OpSB -> (LEAQ4 [c+4*d] {s} x y) 979 (LEAQ8 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ8 [c+d] {s} x y) 980 (LEAQ8 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+8*d) && y.Op != OpSB -> (LEAQ8 [c+8*d] {s} x y) 981 982 // fold shifts into LEAQx 983 (LEAQ1 [c] {s} x (SHLQconst [1] y)) -> (LEAQ2 [c] {s} x y) 984 (LEAQ1 [c] {s} x (SHLQconst [2] y)) -> (LEAQ4 [c] {s} x y) 985 (LEAQ1 [c] {s} x (SHLQconst [3] y)) -> (LEAQ8 [c] {s} x y) 986 (LEAQ2 [c] {s} x (SHLQconst [1] y)) -> (LEAQ4 [c] {s} x y) 987 (LEAQ2 [c] {s} x (SHLQconst [2] y)) -> (LEAQ8 [c] {s} x y) 988 (LEAQ4 [c] {s} x (SHLQconst [1] y)) -> (LEAQ8 [c] {s} x y) 989 990 // reverse ordering of compare instruction 991 (SETL (InvertFlags x)) -> (SETG x) 992 (SETG (InvertFlags x)) -> (SETL x) 993 (SETB (InvertFlags x)) -> (SETA x) 994 (SETA (InvertFlags x)) -> (SETB x) 995 (SETLE (InvertFlags x)) -> (SETGE x) 996 (SETGE (InvertFlags x)) -> (SETLE x) 997 (SETBE (InvertFlags x)) -> (SETAE x) 998 (SETAE (InvertFlags x)) -> (SETBE x) 999 (SETEQ (InvertFlags x)) -> (SETEQ x) 1000 (SETNE (InvertFlags x)) -> (SETNE x) 1001 1002 (SETLmem [off] {sym} ptr (InvertFlags x) mem) -> (SETGmem [off] {sym} ptr x mem) 1003 (SETGmem [off] {sym} ptr (InvertFlags x) mem) -> (SETLmem [off] {sym} ptr x mem) 1004 (SETBmem [off] {sym} ptr (InvertFlags x) mem) -> (SETAmem [off] {sym} ptr x mem) 1005 (SETAmem [off] {sym} ptr (InvertFlags x) mem) -> (SETBmem [off] {sym} ptr x mem) 1006 (SETLEmem [off] {sym} ptr (InvertFlags x) mem) -> (SETGEmem [off] {sym} ptr x mem) 1007 (SETGEmem [off] {sym} ptr (InvertFlags x) mem) -> (SETLEmem [off] {sym} ptr x mem) 1008 (SETBEmem [off] {sym} ptr (InvertFlags x) mem) -> (SETAEmem [off] {sym} ptr x mem) 1009 (SETAEmem [off] {sym} ptr (InvertFlags x) mem) -> (SETBEmem [off] {sym} ptr x mem) 1010 (SETEQmem [off] {sym} ptr (InvertFlags x) mem) -> (SETEQmem [off] {sym} ptr x mem) 1011 (SETNEmem [off] {sym} ptr (InvertFlags x) mem) -> (SETNEmem [off] {sym} ptr x mem) 1012 1013 // sign extended loads 1014 // Note: The combined instruction must end up in the same block 1015 // as the original load. If not, we end up making a value with 1016 // memory type live in two different blocks, which can lead to 1017 // multiple memory values alive simultaneously. 1018 // Make sure we don't combine these ops if the load has another use. 1019 // This prevents a single load from being split into multiple loads 1020 // which then might return different values. See test/atomicload.go. 1021 (MOVBQSX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 1022 (MOVBQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 1023 (MOVBQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 1024 (MOVBQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 1025 (MOVBQZX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 1026 (MOVBQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 1027 (MOVBQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 1028 (MOVBQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 1029 (MOVWQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 1030 (MOVWQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 1031 (MOVWQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 1032 (MOVWQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 1033 (MOVWQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 1034 (MOVWQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 1035 (MOVLQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 1036 (MOVLQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 1037 (MOVLQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 1038 (MOVLQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 1039 1040 (MOVLQZX x) && zeroUpper32Bits(x,3) -> x 1041 1042 (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBloadidx1 <v.Type> [off] {sym} ptr idx mem) 1043 (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx1 <v.Type> [off] {sym} ptr idx mem) 1044 (MOVWQZX x:(MOVWloadidx2 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx2 <v.Type> [off] {sym} ptr idx mem) 1045 (MOVLQZX x:(MOVLloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx1 <v.Type> [off] {sym} ptr idx mem) 1046 (MOVLQZX x:(MOVLloadidx4 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx4 <v.Type> [off] {sym} ptr idx mem) 1047 1048 // replace load from same location as preceding store with zero/sign extension (or copy in case of full width) 1049 (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBQZX x) 1050 (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWQZX x) 1051 (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVLQZX x) 1052 (MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 1053 (MOVBQSXload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBQSX x) 1054 (MOVWQSXload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWQSX x) 1055 (MOVLQSXload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVLQSX x) 1056 1057 // Fold extensions and ANDs together. 1058 (MOVBQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xff] x) 1059 (MOVWQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xffff] x) 1060 (MOVLQZX (ANDLconst [c] x)) -> (ANDLconst [c] x) 1061 (MOVBQSX (ANDLconst [c] x)) && c & 0x80 == 0 -> (ANDLconst [c & 0x7f] x) 1062 (MOVWQSX (ANDLconst [c] x)) && c & 0x8000 == 0 -> (ANDLconst [c & 0x7fff] x) 1063 (MOVLQSX (ANDLconst [c] x)) && c & 0x80000000 == 0 -> (ANDLconst [c & 0x7fffffff] x) 1064 1065 // Don't extend before storing 1066 (MOVLstore [off] {sym} ptr (MOVLQSX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 1067 (MOVWstore [off] {sym} ptr (MOVWQSX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 1068 (MOVBstore [off] {sym} ptr (MOVBQSX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 1069 (MOVLstore [off] {sym} ptr (MOVLQZX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 1070 (MOVWstore [off] {sym} ptr (MOVWQZX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 1071 (MOVBstore [off] {sym} ptr (MOVBQZX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 1072 1073 // fold constants into memory operations 1074 // Note that this is not always a good idea because if not all the uses of 1075 // the ADDQconst get eliminated, we still have to compute the ADDQconst and we now 1076 // have potentially two live values (ptr and (ADDQconst [off] ptr)) instead of one. 1077 // Nevertheless, let's do it! 1078 (MOVQload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 1079 (MOVLload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 1080 (MOVWload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 1081 (MOVBload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 1082 (MOVSSload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSSload [off1+off2] {sym} ptr mem) 1083 (MOVSDload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSDload [off1+off2] {sym} ptr mem) 1084 (MOVOload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVOload [off1+off2] {sym} ptr mem) 1085 1086 (MOVQstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 1087 (MOVLstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 1088 (MOVWstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 1089 (MOVBstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 1090 (MOVSSstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSSstore [off1+off2] {sym} ptr val mem) 1091 (MOVSDstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSDstore [off1+off2] {sym} ptr val mem) 1092 (MOVOstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVOstore [off1+off2] {sym} ptr val mem) 1093 1094 // Fold constants into stores. 1095 (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> 1096 (MOVQstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 1097 (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 1098 (MOVLstoreconst [makeValAndOff(int64(int32(c)),off)] {sym} ptr mem) 1099 (MOVWstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 1100 (MOVWstoreconst [makeValAndOff(int64(int16(c)),off)] {sym} ptr mem) 1101 (MOVBstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 1102 (MOVBstoreconst [makeValAndOff(int64(int8(c)),off)] {sym} ptr mem) 1103 1104 // Fold address offsets into constant stores. 1105 (MOVQstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1106 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1107 (MOVLstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1108 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1109 (MOVWstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1110 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1111 (MOVBstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1112 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1113 1114 // We need to fold LEAQ into the MOVx ops so that the live variable analysis knows 1115 // what variables are being read/written by the ops. 1116 (MOVQload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1117 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1118 (MOVLload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1119 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1120 (MOVWload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1121 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1122 (MOVBload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1123 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1124 (MOVSSload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1125 (MOVSSload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1126 (MOVSDload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1127 (MOVSDload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1128 (MOVOload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1129 (MOVOload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1130 1131 (MOVBQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1132 (MOVBQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1133 (MOVWQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1134 (MOVWQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1135 (MOVLQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1136 (MOVLQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1137 1138 (MOVQstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1139 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1140 (MOVLstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1141 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1142 (MOVWstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1143 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1144 (MOVBstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1145 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1146 (MOVSSstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1147 (MOVSSstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1148 (MOVSDstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1149 (MOVSDstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1150 (MOVOstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1151 (MOVOstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1152 1153 (MOVQstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1154 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1155 (MOVLstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1156 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1157 (MOVWstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1158 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1159 (MOVBstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1160 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1161 1162 // generating indexed loads and stores 1163 (MOVBload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1164 (MOVBloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1165 (MOVWload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1166 (MOVWloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1167 (MOVWload [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1168 (MOVWloadidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1169 (MOVLload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1170 (MOVLloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1171 (MOVLload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1172 (MOVLloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1173 (MOVLload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1174 (MOVLloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1175 (MOVQload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1176 (MOVQloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1177 (MOVQload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1178 (MOVQloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1179 (MOVSSload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1180 (MOVSSloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1181 (MOVSSload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1182 (MOVSSloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1183 (MOVSDload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1184 (MOVSDloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1185 (MOVSDload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1186 (MOVSDloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1187 1188 (MOVBstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1189 (MOVBstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1190 (MOVWstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1191 (MOVWstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1192 (MOVWstore [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1193 (MOVWstoreidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1194 (MOVLstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1195 (MOVLstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1196 (MOVLstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1197 (MOVLstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1198 (MOVLstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1199 (MOVLstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1200 (MOVQstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1201 (MOVQstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1202 (MOVQstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1203 (MOVQstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1204 (MOVSSstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1205 (MOVSSstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1206 (MOVSSstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1207 (MOVSSstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1208 (MOVSDstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1209 (MOVSDstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1210 (MOVSDstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1211 (MOVSDstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1212 1213 (MOVBload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVBloadidx1 [off] {sym} ptr idx mem) 1214 (MOVWload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVWloadidx1 [off] {sym} ptr idx mem) 1215 (MOVLload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVLloadidx1 [off] {sym} ptr idx mem) 1216 (MOVQload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVQloadidx1 [off] {sym} ptr idx mem) 1217 (MOVSSload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSSloadidx1 [off] {sym} ptr idx mem) 1218 (MOVSDload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSDloadidx1 [off] {sym} ptr idx mem) 1219 (MOVBstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVBstoreidx1 [off] {sym} ptr idx val mem) 1220 (MOVWstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVWstoreidx1 [off] {sym} ptr idx val mem) 1221 (MOVLstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVLstoreidx1 [off] {sym} ptr idx val mem) 1222 (MOVQstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVQstoreidx1 [off] {sym} ptr idx val mem) 1223 (MOVSSstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSSstoreidx1 [off] {sym} ptr idx val mem) 1224 (MOVSDstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSDstoreidx1 [off] {sym} ptr idx val mem) 1225 1226 (MOVBstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1227 (MOVBstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1228 (MOVWstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1229 (MOVWstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1230 (MOVWstoreconst [x] {sym1} (LEAQ2 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1231 (MOVWstoreconstidx2 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1232 (MOVLstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1233 (MOVLstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1234 (MOVLstoreconst [x] {sym1} (LEAQ4 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1235 (MOVLstoreconstidx4 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1236 (MOVQstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1237 (MOVQstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1238 (MOVQstoreconst [x] {sym1} (LEAQ8 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1239 (MOVQstoreconstidx8 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1240 1241 (MOVBstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVBstoreconstidx1 [x] {sym} ptr idx mem) 1242 (MOVWstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVWstoreconstidx1 [x] {sym} ptr idx mem) 1243 (MOVLstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVLstoreconstidx1 [x] {sym} ptr idx mem) 1244 (MOVQstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVQstoreconstidx1 [x] {sym} ptr idx mem) 1245 1246 // combine SHLQ into indexed loads and stores 1247 (MOVWloadidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWloadidx2 [c] {sym} ptr idx mem) 1248 (MOVLloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLloadidx4 [c] {sym} ptr idx mem) 1249 (MOVLloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVLloadidx8 [c] {sym} ptr idx mem) 1250 (MOVQloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQloadidx8 [c] {sym} ptr idx mem) 1251 (MOVSSloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVSSloadidx4 [c] {sym} ptr idx mem) 1252 (MOVSDloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVSDloadidx8 [c] {sym} ptr idx mem) 1253 (MOVWstoreidx1 [c] {sym} ptr (SHLQconst [1] idx) val mem) -> (MOVWstoreidx2 [c] {sym} ptr idx val mem) 1254 (MOVLstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVLstoreidx4 [c] {sym} ptr idx val mem) 1255 (MOVLstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVLstoreidx8 [c] {sym} ptr idx val mem) 1256 (MOVQstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVQstoreidx8 [c] {sym} ptr idx val mem) 1257 (MOVSSstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVSSstoreidx4 [c] {sym} ptr idx val mem) 1258 (MOVSDstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVSDstoreidx8 [c] {sym} ptr idx val mem) 1259 (MOVWstoreconstidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWstoreconstidx2 [c] {sym} ptr idx mem) 1260 (MOVLstoreconstidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLstoreconstidx4 [c] {sym} ptr idx mem) 1261 (MOVQstoreconstidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQstoreconstidx8 [c] {sym} ptr idx mem) 1262 1263 // combine ADDQ into indexed loads and stores 1264 (MOVBloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 1265 (MOVWloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 1266 (MOVWloadidx2 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVWloadidx2 [c+d] {sym} ptr idx mem) 1267 (MOVLloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 1268 (MOVLloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVLloadidx4 [c+d] {sym} ptr idx mem) 1269 (MOVLloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVLloadidx8 [c+d] {sym} ptr idx mem) 1270 (MOVQloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 1271 (MOVQloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVQloadidx8 [c+d] {sym} ptr idx mem) 1272 (MOVSSloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 1273 (MOVSSloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVSSloadidx4 [c+d] {sym} ptr idx mem) 1274 (MOVSDloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 1275 (MOVSDloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) && is32Bit(c+d) -> (MOVSDloadidx8 [c+d] {sym} ptr idx mem) 1276 1277 (MOVBstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 1278 (MOVWstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 1279 (MOVWstoreidx2 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVWstoreidx2 [c+d] {sym} ptr idx val mem) 1280 (MOVLstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 1281 (MOVLstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVLstoreidx4 [c+d] {sym} ptr idx val mem) 1282 (MOVLstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVLstoreidx8 [c+d] {sym} ptr idx val mem) 1283 (MOVQstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 1284 (MOVQstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVQstoreidx8 [c+d] {sym} ptr idx val mem) 1285 (MOVSSstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 1286 (MOVSSstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVSSstoreidx4 [c+d] {sym} ptr idx val mem) 1287 (MOVSDstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 1288 (MOVSDstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) && is32Bit(c+d) -> (MOVSDstoreidx8 [c+d] {sym} ptr idx val mem) 1289 1290 (MOVBloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+d) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 1291 (MOVWloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+d) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 1292 (MOVWloadidx2 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+2*d) -> (MOVWloadidx2 [c+2*d] {sym} ptr idx mem) 1293 (MOVLloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+d) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 1294 (MOVLloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+4*d) -> (MOVLloadidx4 [c+4*d] {sym} ptr idx mem) 1295 (MOVLloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+8*d) -> (MOVLloadidx8 [c+8*d] {sym} ptr idx mem) 1296 (MOVQloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+d) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 1297 (MOVQloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+8*d) -> (MOVQloadidx8 [c+8*d] {sym} ptr idx mem) 1298 (MOVSSloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+d) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 1299 (MOVSSloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+4*d) -> (MOVSSloadidx4 [c+4*d] {sym} ptr idx mem) 1300 (MOVSDloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+d) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 1301 (MOVSDloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) && is32Bit(c+8*d) -> (MOVSDloadidx8 [c+8*d] {sym} ptr idx mem) 1302 1303 (MOVBstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+d) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 1304 (MOVWstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+d) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 1305 (MOVWstoreidx2 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+2*d) -> (MOVWstoreidx2 [c+2*d] {sym} ptr idx val mem) 1306 (MOVLstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+d) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 1307 (MOVLstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+4*d) -> (MOVLstoreidx4 [c+4*d] {sym} ptr idx val mem) 1308 (MOVLstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+8*d) -> (MOVLstoreidx8 [c+8*d] {sym} ptr idx val mem) 1309 (MOVQstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+d) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 1310 (MOVQstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+8*d) -> (MOVQstoreidx8 [c+8*d] {sym} ptr idx val mem) 1311 (MOVSSstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+d) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 1312 (MOVSSstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+4*d) -> (MOVSSstoreidx4 [c+4*d] {sym} ptr idx val mem) 1313 (MOVSDstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+d) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 1314 (MOVSDstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) && is32Bit(c+8*d) -> (MOVSDstoreidx8 [c+8*d] {sym} ptr idx val mem) 1315 1316 (MOVBstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1317 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1318 (MOVWstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1319 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1320 (MOVWstoreconstidx2 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1321 (MOVWstoreconstidx2 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1322 (MOVLstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1323 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1324 (MOVLstoreconstidx4 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1325 (MOVLstoreconstidx4 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1326 (MOVQstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1327 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1328 (MOVQstoreconstidx8 [x] {sym} (ADDQconst [c] ptr) idx mem) && ValAndOff(x).canAdd(c) -> 1329 (MOVQstoreconstidx8 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1330 1331 (MOVBstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(c) -> 1332 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1333 (MOVWstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(c) -> 1334 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1335 (MOVWstoreconstidx2 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(2*c) -> 1336 (MOVWstoreconstidx2 [ValAndOff(x).add(2*c)] {sym} ptr idx mem) 1337 (MOVLstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(c) -> 1338 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1339 (MOVLstoreconstidx4 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(4*c) -> 1340 (MOVLstoreconstidx4 [ValAndOff(x).add(4*c)] {sym} ptr idx mem) 1341 (MOVQstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(c) -> 1342 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1343 (MOVQstoreconstidx8 [x] {sym} ptr (ADDQconst [c] idx) mem) && ValAndOff(x).canAdd(8*c) -> 1344 (MOVQstoreconstidx8 [ValAndOff(x).add(8*c)] {sym} ptr idx mem) 1345 1346 // fold LEAQs together 1347 (LEAQ [off1] {sym1} (LEAQ [off2] {sym2} x)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1348 (LEAQ [off1+off2] {mergeSym(sym1,sym2)} x) 1349 1350 // LEAQ into LEAQ1 1351 (LEAQ1 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1352 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1353 1354 // LEAQ1 into LEAQ 1355 (LEAQ [off1] {sym1} (LEAQ1 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1356 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1357 1358 // LEAQ into LEAQ[248] 1359 (LEAQ2 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1360 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1361 (LEAQ4 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1362 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1363 (LEAQ8 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1364 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1365 1366 // LEAQ[248] into LEAQ 1367 (LEAQ [off1] {sym1} (LEAQ2 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1368 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1369 (LEAQ [off1] {sym1} (LEAQ4 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1370 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1371 (LEAQ [off1] {sym1} (LEAQ8 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1372 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1373 1374 // Absorb InvertFlags into branches. 1375 (LT (InvertFlags cmp) yes no) -> (GT cmp yes no) 1376 (GT (InvertFlags cmp) yes no) -> (LT cmp yes no) 1377 (LE (InvertFlags cmp) yes no) -> (GE cmp yes no) 1378 (GE (InvertFlags cmp) yes no) -> (LE cmp yes no) 1379 (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no) 1380 (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no) 1381 (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no) 1382 (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no) 1383 (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no) 1384 (NE (InvertFlags cmp) yes no) -> (NE cmp yes no) 1385 1386 // Constant comparisons. 1387 (CMPQconst (MOVQconst [x]) [y]) && x==y -> (FlagEQ) 1388 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)<uint64(y) -> (FlagLT_ULT) 1389 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)>uint64(y) -> (FlagLT_UGT) 1390 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)<uint64(y) -> (FlagGT_ULT) 1391 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)>uint64(y) -> (FlagGT_UGT) 1392 (CMPLconst (MOVLconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ) 1393 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT) 1394 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT) 1395 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT) 1396 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT) 1397 (CMPWconst (MOVLconst [x]) [y]) && int16(x)==int16(y) -> (FlagEQ) 1398 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)<uint16(y) -> (FlagLT_ULT) 1399 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)>uint16(y) -> (FlagLT_UGT) 1400 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)<uint16(y) -> (FlagGT_ULT) 1401 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)>uint16(y) -> (FlagGT_UGT) 1402 (CMPBconst (MOVLconst [x]) [y]) && int8(x)==int8(y) -> (FlagEQ) 1403 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)<uint8(y) -> (FlagLT_ULT) 1404 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)>uint8(y) -> (FlagLT_UGT) 1405 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)<uint8(y) -> (FlagGT_ULT) 1406 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)>uint8(y) -> (FlagGT_UGT) 1407 1408 // Other known comparisons. 1409 (CMPQconst (MOVBQZX _) [c]) && 0xFF < c -> (FlagLT_ULT) 1410 (CMPQconst (MOVWQZX _) [c]) && 0xFFFF < c -> (FlagLT_ULT) 1411 (CMPQconst (MOVLQZX _) [c]) && 0xFFFFFFFF < c -> (FlagLT_ULT) 1412 (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT_ULT) 1413 (CMPQconst (SHRQconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT) 1414 (CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1415 (CMPQconst (ANDLconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1416 (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT) 1417 (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT) 1418 (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT) 1419 1420 // TODO: DIVxU also. 1421 1422 // Absorb flag constants into SBB ops. 1423 (SBBQcarrymask (FlagEQ)) -> (MOVQconst [0]) 1424 (SBBQcarrymask (FlagLT_ULT)) -> (MOVQconst [-1]) 1425 (SBBQcarrymask (FlagLT_UGT)) -> (MOVQconst [0]) 1426 (SBBQcarrymask (FlagGT_ULT)) -> (MOVQconst [-1]) 1427 (SBBQcarrymask (FlagGT_UGT)) -> (MOVQconst [0]) 1428 (SBBLcarrymask (FlagEQ)) -> (MOVLconst [0]) 1429 (SBBLcarrymask (FlagLT_ULT)) -> (MOVLconst [-1]) 1430 (SBBLcarrymask (FlagLT_UGT)) -> (MOVLconst [0]) 1431 (SBBLcarrymask (FlagGT_ULT)) -> (MOVLconst [-1]) 1432 (SBBLcarrymask (FlagGT_UGT)) -> (MOVLconst [0]) 1433 1434 // Absorb flag constants into branches. 1435 (EQ (FlagEQ) yes no) -> (First nil yes no) 1436 (EQ (FlagLT_ULT) yes no) -> (First nil no yes) 1437 (EQ (FlagLT_UGT) yes no) -> (First nil no yes) 1438 (EQ (FlagGT_ULT) yes no) -> (First nil no yes) 1439 (EQ (FlagGT_UGT) yes no) -> (First nil no yes) 1440 1441 (NE (FlagEQ) yes no) -> (First nil no yes) 1442 (NE (FlagLT_ULT) yes no) -> (First nil yes no) 1443 (NE (FlagLT_UGT) yes no) -> (First nil yes no) 1444 (NE (FlagGT_ULT) yes no) -> (First nil yes no) 1445 (NE (FlagGT_UGT) yes no) -> (First nil yes no) 1446 1447 (LT (FlagEQ) yes no) -> (First nil no yes) 1448 (LT (FlagLT_ULT) yes no) -> (First nil yes no) 1449 (LT (FlagLT_UGT) yes no) -> (First nil yes no) 1450 (LT (FlagGT_ULT) yes no) -> (First nil no yes) 1451 (LT (FlagGT_UGT) yes no) -> (First nil no yes) 1452 1453 (LE (FlagEQ) yes no) -> (First nil yes no) 1454 (LE (FlagLT_ULT) yes no) -> (First nil yes no) 1455 (LE (FlagLT_UGT) yes no) -> (First nil yes no) 1456 (LE (FlagGT_ULT) yes no) -> (First nil no yes) 1457 (LE (FlagGT_UGT) yes no) -> (First nil no yes) 1458 1459 (GT (FlagEQ) yes no) -> (First nil no yes) 1460 (GT (FlagLT_ULT) yes no) -> (First nil no yes) 1461 (GT (FlagLT_UGT) yes no) -> (First nil no yes) 1462 (GT (FlagGT_ULT) yes no) -> (First nil yes no) 1463 (GT (FlagGT_UGT) yes no) -> (First nil yes no) 1464 1465 (GE (FlagEQ) yes no) -> (First nil yes no) 1466 (GE (FlagLT_ULT) yes no) -> (First nil no yes) 1467 (GE (FlagLT_UGT) yes no) -> (First nil no yes) 1468 (GE (FlagGT_ULT) yes no) -> (First nil yes no) 1469 (GE (FlagGT_UGT) yes no) -> (First nil yes no) 1470 1471 (ULT (FlagEQ) yes no) -> (First nil no yes) 1472 (ULT (FlagLT_ULT) yes no) -> (First nil yes no) 1473 (ULT (FlagLT_UGT) yes no) -> (First nil no yes) 1474 (ULT (FlagGT_ULT) yes no) -> (First nil yes no) 1475 (ULT (FlagGT_UGT) yes no) -> (First nil no yes) 1476 1477 (ULE (FlagEQ) yes no) -> (First nil yes no) 1478 (ULE (FlagLT_ULT) yes no) -> (First nil yes no) 1479 (ULE (FlagLT_UGT) yes no) -> (First nil no yes) 1480 (ULE (FlagGT_ULT) yes no) -> (First nil yes no) 1481 (ULE (FlagGT_UGT) yes no) -> (First nil no yes) 1482 1483 (UGT (FlagEQ) yes no) -> (First nil no yes) 1484 (UGT (FlagLT_ULT) yes no) -> (First nil no yes) 1485 (UGT (FlagLT_UGT) yes no) -> (First nil yes no) 1486 (UGT (FlagGT_ULT) yes no) -> (First nil no yes) 1487 (UGT (FlagGT_UGT) yes no) -> (First nil yes no) 1488 1489 (UGE (FlagEQ) yes no) -> (First nil yes no) 1490 (UGE (FlagLT_ULT) yes no) -> (First nil no yes) 1491 (UGE (FlagLT_UGT) yes no) -> (First nil yes no) 1492 (UGE (FlagGT_ULT) yes no) -> (First nil no yes) 1493 (UGE (FlagGT_UGT) yes no) -> (First nil yes no) 1494 1495 // Absorb flag constants into SETxx ops. 1496 (SETEQ (FlagEQ)) -> (MOVLconst [1]) 1497 (SETEQ (FlagLT_ULT)) -> (MOVLconst [0]) 1498 (SETEQ (FlagLT_UGT)) -> (MOVLconst [0]) 1499 (SETEQ (FlagGT_ULT)) -> (MOVLconst [0]) 1500 (SETEQ (FlagGT_UGT)) -> (MOVLconst [0]) 1501 1502 (SETNE (FlagEQ)) -> (MOVLconst [0]) 1503 (SETNE (FlagLT_ULT)) -> (MOVLconst [1]) 1504 (SETNE (FlagLT_UGT)) -> (MOVLconst [1]) 1505 (SETNE (FlagGT_ULT)) -> (MOVLconst [1]) 1506 (SETNE (FlagGT_UGT)) -> (MOVLconst [1]) 1507 1508 (SETL (FlagEQ)) -> (MOVLconst [0]) 1509 (SETL (FlagLT_ULT)) -> (MOVLconst [1]) 1510 (SETL (FlagLT_UGT)) -> (MOVLconst [1]) 1511 (SETL (FlagGT_ULT)) -> (MOVLconst [0]) 1512 (SETL (FlagGT_UGT)) -> (MOVLconst [0]) 1513 1514 (SETLE (FlagEQ)) -> (MOVLconst [1]) 1515 (SETLE (FlagLT_ULT)) -> (MOVLconst [1]) 1516 (SETLE (FlagLT_UGT)) -> (MOVLconst [1]) 1517 (SETLE (FlagGT_ULT)) -> (MOVLconst [0]) 1518 (SETLE (FlagGT_UGT)) -> (MOVLconst [0]) 1519 1520 (SETG (FlagEQ)) -> (MOVLconst [0]) 1521 (SETG (FlagLT_ULT)) -> (MOVLconst [0]) 1522 (SETG (FlagLT_UGT)) -> (MOVLconst [0]) 1523 (SETG (FlagGT_ULT)) -> (MOVLconst [1]) 1524 (SETG (FlagGT_UGT)) -> (MOVLconst [1]) 1525 1526 (SETGE (FlagEQ)) -> (MOVLconst [1]) 1527 (SETGE (FlagLT_ULT)) -> (MOVLconst [0]) 1528 (SETGE (FlagLT_UGT)) -> (MOVLconst [0]) 1529 (SETGE (FlagGT_ULT)) -> (MOVLconst [1]) 1530 (SETGE (FlagGT_UGT)) -> (MOVLconst [1]) 1531 1532 (SETB (FlagEQ)) -> (MOVLconst [0]) 1533 (SETB (FlagLT_ULT)) -> (MOVLconst [1]) 1534 (SETB (FlagLT_UGT)) -> (MOVLconst [0]) 1535 (SETB (FlagGT_ULT)) -> (MOVLconst [1]) 1536 (SETB (FlagGT_UGT)) -> (MOVLconst [0]) 1537 1538 (SETBE (FlagEQ)) -> (MOVLconst [1]) 1539 (SETBE (FlagLT_ULT)) -> (MOVLconst [1]) 1540 (SETBE (FlagLT_UGT)) -> (MOVLconst [0]) 1541 (SETBE (FlagGT_ULT)) -> (MOVLconst [1]) 1542 (SETBE (FlagGT_UGT)) -> (MOVLconst [0]) 1543 1544 (SETA (FlagEQ)) -> (MOVLconst [0]) 1545 (SETA (FlagLT_ULT)) -> (MOVLconst [0]) 1546 (SETA (FlagLT_UGT)) -> (MOVLconst [1]) 1547 (SETA (FlagGT_ULT)) -> (MOVLconst [0]) 1548 (SETA (FlagGT_UGT)) -> (MOVLconst [1]) 1549 1550 (SETAE (FlagEQ)) -> (MOVLconst [1]) 1551 (SETAE (FlagLT_ULT)) -> (MOVLconst [0]) 1552 (SETAE (FlagLT_UGT)) -> (MOVLconst [1]) 1553 (SETAE (FlagGT_ULT)) -> (MOVLconst [0]) 1554 (SETAE (FlagGT_UGT)) -> (MOVLconst [1]) 1555 1556 (SETEQmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1557 (SETEQmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1558 (SETEQmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1559 (SETEQmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1560 (SETEQmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1561 1562 (SETNEmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1563 (SETNEmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1564 (SETNEmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1565 (SETNEmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1566 (SETNEmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1567 1568 (SETLmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1569 (SETLmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1570 (SETLmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1571 (SETLmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1572 (SETLmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1573 1574 (SETLEmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1575 (SETLEmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1576 (SETLEmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1577 (SETLEmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1578 (SETLEmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1579 1580 (SETGmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1581 (SETGmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1582 (SETGmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1583 (SETGmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1584 (SETGmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1585 1586 (SETGEmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1587 (SETGEmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1588 (SETGEmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1589 (SETGEmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1590 (SETGEmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1591 1592 (SETBmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1593 (SETBmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1594 (SETBmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1595 (SETBmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1596 (SETBmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1597 1598 (SETBEmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1599 (SETBEmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1600 (SETBEmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1601 (SETBEmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1602 (SETBEmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1603 1604 (SETAmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1605 (SETAmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1606 (SETAmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1607 (SETAmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1608 (SETAmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1609 1610 (SETAEmem [off] {sym} ptr x:(FlagEQ) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1611 (SETAEmem [off] {sym} ptr x:(FlagLT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1612 (SETAEmem [off] {sym} ptr x:(FlagLT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1613 (SETAEmem [off] {sym} ptr x:(FlagGT_ULT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [0]) mem) 1614 (SETAEmem [off] {sym} ptr x:(FlagGT_UGT) mem) -> (MOVBstore [off] {sym} ptr (MOVLconst <x.Type> [1]) mem) 1615 1616 // Remove redundant *const ops 1617 (ADDQconst [0] x) -> x 1618 (ADDLconst [c] x) && int32(c)==0 -> x 1619 (SUBQconst [0] x) -> x 1620 (SUBLconst [c] x) && int32(c) == 0 -> x 1621 (ANDQconst [0] _) -> (MOVQconst [0]) 1622 (ANDLconst [c] _) && int32(c)==0 -> (MOVLconst [0]) 1623 (ANDQconst [-1] x) -> x 1624 (ANDLconst [c] x) && int32(c)==-1 -> x 1625 (ORQconst [0] x) -> x 1626 (ORLconst [c] x) && int32(c)==0 -> x 1627 (ORQconst [-1] _) -> (MOVQconst [-1]) 1628 (ORLconst [c] _) && int32(c)==-1 -> (MOVLconst [-1]) 1629 (XORQconst [0] x) -> x 1630 (XORLconst [c] x) && int32(c)==0 -> x 1631 // TODO: since we got rid of the W/B versions, we might miss 1632 // things like (ANDLconst [0x100] x) which were formerly 1633 // (ANDBconst [0] x). Probably doesn't happen very often. 1634 // If we cared, we might do: 1635 // (ANDLconst <t> [c] x) && t.Size()==1 && int8(x)==0 -> (MOVLconst [0]) 1636 1637 // Convert constant subtracts to constant adds 1638 (SUBQconst [c] x) && c != -(1<<31) -> (ADDQconst [-c] x) 1639 (SUBLconst [c] x) -> (ADDLconst [int64(int32(-c))] x) 1640 1641 // generic constant folding 1642 // TODO: more of this 1643 (ADDQconst [c] (MOVQconst [d])) -> (MOVQconst [c+d]) 1644 (ADDLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c+d))]) 1645 (ADDQconst [c] (ADDQconst [d] x)) && is32Bit(c+d) -> (ADDQconst [c+d] x) 1646 (ADDLconst [c] (ADDLconst [d] x)) -> (ADDLconst [int64(int32(c+d))] x) 1647 (SUBQconst (MOVQconst [d]) [c]) -> (MOVQconst [d-c]) 1648 (SUBQconst (SUBQconst x [d]) [c]) && is32Bit(-c-d) -> (ADDQconst [-c-d] x) 1649 (SARQconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1650 (SARLconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1651 (SARWconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1652 (SARBconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1653 (NEGQ (MOVQconst [c])) -> (MOVQconst [-c]) 1654 (NEGL (MOVLconst [c])) -> (MOVLconst [int64(int32(-c))]) 1655 (MULQconst [c] (MOVQconst [d])) -> (MOVQconst [c*d]) 1656 (MULLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c*d))]) 1657 (ANDQconst [c] (MOVQconst [d])) -> (MOVQconst [c&d]) 1658 (ANDLconst [c] (MOVLconst [d])) -> (MOVLconst [c&d]) 1659 (ORQconst [c] (MOVQconst [d])) -> (MOVQconst [c|d]) 1660 (ORLconst [c] (MOVLconst [d])) -> (MOVLconst [c|d]) 1661 (XORQconst [c] (MOVQconst [d])) -> (MOVQconst [c^d]) 1662 (XORLconst [c] (MOVLconst [d])) -> (MOVLconst [c^d]) 1663 (NOTQ (MOVQconst [c])) -> (MOVQconst [^c]) 1664 (NOTL (MOVLconst [c])) -> (MOVLconst [^c]) 1665 1666 // generic simplifications 1667 // TODO: more of this 1668 (ADDQ x (NEGQ y)) -> (SUBQ x y) 1669 (ADDL x (NEGL y)) -> (SUBL x y) 1670 (SUBQ x x) -> (MOVQconst [0]) 1671 (SUBL x x) -> (MOVLconst [0]) 1672 (ANDQ x x) -> x 1673 (ANDL x x) -> x 1674 (ORQ x x) -> x 1675 (ORL x x) -> x 1676 (XORQ x x) -> (MOVQconst [0]) 1677 (XORL x x) -> (MOVLconst [0]) 1678 (NEGQ (ADDQconst [c] (NEGQ x))) && c != -(1<<31) -> (ADDQconst [-c] x) 1679 1680 // checking AND against 0. 1681 (CMPQconst (ANDQ x y) [0]) -> (TESTQ x y) 1682 (CMPLconst (ANDL x y) [0]) -> (TESTL x y) 1683 (CMPWconst (ANDL x y) [0]) -> (TESTW x y) 1684 (CMPBconst (ANDL x y) [0]) -> (TESTB x y) 1685 (CMPQconst (ANDQconst [c] x) [0]) -> (TESTQconst [c] x) 1686 (CMPLconst (ANDLconst [c] x) [0]) -> (TESTLconst [c] x) 1687 (CMPWconst (ANDLconst [c] x) [0]) -> (TESTWconst [int64(int16(c))] x) 1688 (CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x) 1689 1690 // Convert TESTx to TESTxconst if possible. 1691 (TESTQ (MOVQconst [c]) x) && is32Bit(c) -> (TESTQconst [c] x) 1692 (TESTL (MOVLconst [c]) x) -> (TESTLconst [c] x) 1693 (TESTW (MOVLconst [c]) x) -> (TESTWconst [c] x) 1694 (TESTB (MOVLconst [c]) x) -> (TESTBconst [c] x) 1695 1696 // TEST %reg,%reg is shorter than CMP 1697 (CMPQconst x [0]) -> (TESTQ x x) 1698 (CMPLconst x [0]) -> (TESTL x x) 1699 (CMPWconst x [0]) -> (TESTW x x) 1700 (CMPBconst x [0]) -> (TESTB x x) 1701 1702 // Combining byte loads into larger (unaligned) loads. 1703 // There are many ways these combinations could occur. This is 1704 // designed to match the way encoding/binary.LittleEndian does it. 1705 1706 // Little-endian loads 1707 1708 (ORL x0:(MOVBload [i0] {s} p mem) 1709 sh:(SHLLconst [8] x1:(MOVBload [i1] {s} p mem))) 1710 && i1 == i0+1 1711 && x0.Uses == 1 1712 && x1.Uses == 1 1713 && sh.Uses == 1 1714 && mergePoint(b,x0,x1) != nil 1715 && clobber(x0) 1716 && clobber(x1) 1717 && clobber(sh) 1718 -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 1719 1720 (ORQ x0:(MOVBload [i0] {s} p mem) 1721 sh:(SHLQconst [8] x1:(MOVBload [i1] {s} p mem))) 1722 && i1 == i0+1 1723 && x0.Uses == 1 1724 && x1.Uses == 1 1725 && sh.Uses == 1 1726 && mergePoint(b,x0,x1) != nil 1727 && clobber(x0) 1728 && clobber(x1) 1729 && clobber(sh) 1730 -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 1731 1732 (ORL x0:(MOVWload [i0] {s} p mem) 1733 sh:(SHLLconst [16] x1:(MOVWload [i1] {s} p mem))) 1734 && i1 == i0+2 1735 && x0.Uses == 1 1736 && x1.Uses == 1 1737 && sh.Uses == 1 1738 && mergePoint(b,x0,x1) != nil 1739 && clobber(x0) 1740 && clobber(x1) 1741 && clobber(sh) 1742 -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem) 1743 1744 (ORQ x0:(MOVWload [i0] {s} p mem) 1745 sh:(SHLQconst [16] x1:(MOVWload [i1] {s} p mem))) 1746 && i1 == i0+2 1747 && x0.Uses == 1 1748 && x1.Uses == 1 1749 && sh.Uses == 1 1750 && mergePoint(b,x0,x1) != nil 1751 && clobber(x0) 1752 && clobber(x1) 1753 && clobber(sh) 1754 -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem) 1755 1756 (ORQ x0:(MOVLload [i0] {s} p mem) 1757 sh:(SHLQconst [32] x1:(MOVLload [i1] {s} p mem))) 1758 && i1 == i0+4 1759 && x0.Uses == 1 1760 && x1.Uses == 1 1761 && sh.Uses == 1 1762 && mergePoint(b,x0,x1) != nil 1763 && clobber(x0) 1764 && clobber(x1) 1765 && clobber(sh) 1766 -> @mergePoint(b,x0,x1) (MOVQload [i0] {s} p mem) 1767 1768 (ORL 1769 s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem)) 1770 or:(ORL 1771 s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem)) 1772 y)) 1773 && i1 == i0+1 1774 && j1 == j0+8 1775 && j0 % 16 == 0 1776 && x0.Uses == 1 1777 && x1.Uses == 1 1778 && s0.Uses == 1 1779 && s1.Uses == 1 1780 && or.Uses == 1 1781 && mergePoint(b,x0,x1) != nil 1782 && clobber(x0) 1783 && clobber(x1) 1784 && clobber(s0) 1785 && clobber(s1) 1786 && clobber(or) 1787 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y) 1788 1789 (ORQ 1790 s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem)) 1791 or:(ORQ 1792 s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem)) 1793 y)) 1794 && i1 == i0+1 1795 && j1 == j0+8 1796 && j0 % 16 == 0 1797 && x0.Uses == 1 1798 && x1.Uses == 1 1799 && s0.Uses == 1 1800 && s1.Uses == 1 1801 && or.Uses == 1 1802 && mergePoint(b,x0,x1) != nil 1803 && clobber(x0) 1804 && clobber(x1) 1805 && clobber(s0) 1806 && clobber(s1) 1807 && clobber(or) 1808 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y) 1809 1810 (ORQ 1811 s1:(SHLQconst [j1] x1:(MOVWload [i1] {s} p mem)) 1812 or:(ORQ 1813 s0:(SHLQconst [j0] x0:(MOVWload [i0] {s} p mem)) 1814 y)) 1815 && i1 == i0+2 1816 && j1 == j0+16 1817 && j0 % 32 == 0 1818 && x0.Uses == 1 1819 && x1.Uses == 1 1820 && s0.Uses == 1 1821 && s1.Uses == 1 1822 && or.Uses == 1 1823 && mergePoint(b,x0,x1) != nil 1824 && clobber(x0) 1825 && clobber(x1) 1826 && clobber(s0) 1827 && clobber(s1) 1828 && clobber(or) 1829 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLload [i0] {s} p mem)) y) 1830 1831 // Little-endian indexed loads 1832 1833 (ORL x0:(MOVBloadidx1 [i0] {s} p idx mem) 1834 sh:(SHLLconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem))) 1835 && i1 == i0+1 1836 && x0.Uses == 1 1837 && x1.Uses == 1 1838 && sh.Uses == 1 1839 && mergePoint(b,x0,x1) != nil 1840 && clobber(x0) 1841 && clobber(x1) 1842 && clobber(sh) 1843 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem) 1844 1845 (ORQ x0:(MOVBloadidx1 [i0] {s} p idx mem) 1846 sh:(SHLQconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem))) 1847 && i1 == i0+1 1848 && x0.Uses == 1 1849 && x1.Uses == 1 1850 && sh.Uses == 1 1851 && mergePoint(b,x0,x1) != nil 1852 && clobber(x0) 1853 && clobber(x1) 1854 && clobber(sh) 1855 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem) 1856 1857 (ORL x0:(MOVWloadidx1 [i0] {s} p idx mem) 1858 sh:(SHLLconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1859 && i1 == i0+2 1860 && x0.Uses == 1 1861 && x1.Uses == 1 1862 && sh.Uses == 1 1863 && mergePoint(b,x0,x1) != nil 1864 && clobber(x0) 1865 && clobber(x1) 1866 && clobber(sh) 1867 -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem) 1868 1869 (ORQ x0:(MOVWloadidx1 [i0] {s} p idx mem) 1870 sh:(SHLQconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1871 && i1 == i0+2 1872 && x0.Uses == 1 1873 && x1.Uses == 1 1874 && sh.Uses == 1 1875 && mergePoint(b,x0,x1) != nil 1876 && clobber(x0) 1877 && clobber(x1) 1878 && clobber(sh) 1879 -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem) 1880 1881 (ORQ x0:(MOVLloadidx1 [i0] {s} p idx mem) 1882 sh:(SHLQconst [32] x1:(MOVLloadidx1 [i1] {s} p idx mem))) 1883 && i1 == i0+4 1884 && x0.Uses == 1 1885 && x1.Uses == 1 1886 && sh.Uses == 1 1887 && mergePoint(b,x0,x1) != nil 1888 && clobber(x0) 1889 && clobber(x1) 1890 && clobber(sh) 1891 -> @mergePoint(b,x0,x1) (MOVQloadidx1 [i0] {s} p idx mem) 1892 1893 (ORL 1894 s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1895 or:(ORL 1896 s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1897 y)) 1898 && i1 == i0+1 1899 && j1 == j0+8 1900 && j0 % 16 == 0 1901 && x0.Uses == 1 1902 && x1.Uses == 1 1903 && s0.Uses == 1 1904 && s1.Uses == 1 1905 && or.Uses == 1 1906 && mergePoint(b,x0,x1) != nil 1907 && clobber(x0) 1908 && clobber(x1) 1909 && clobber(s0) 1910 && clobber(s1) 1911 && clobber(or) 1912 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y) 1913 1914 (ORQ 1915 s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1916 or:(ORQ 1917 s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1918 y)) 1919 && i1 == i0+1 1920 && j1 == j0+8 1921 && j0 % 16 == 0 1922 && x0.Uses == 1 1923 && x1.Uses == 1 1924 && s0.Uses == 1 1925 && s1.Uses == 1 1926 && or.Uses == 1 1927 && mergePoint(b,x0,x1) != nil 1928 && clobber(x0) 1929 && clobber(x1) 1930 && clobber(s0) 1931 && clobber(s1) 1932 && clobber(or) 1933 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y) 1934 1935 (ORQ 1936 s1:(SHLQconst [j1] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1937 or:(ORQ 1938 s0:(SHLQconst [j0] x0:(MOVWloadidx1 [i0] {s} p idx mem)) 1939 y)) 1940 && i1 == i0+2 1941 && j1 == j0+16 1942 && j0 % 32 == 0 1943 && x0.Uses == 1 1944 && x1.Uses == 1 1945 && s0.Uses == 1 1946 && s1.Uses == 1 1947 && or.Uses == 1 1948 && mergePoint(b,x0,x1) != nil 1949 && clobber(x0) 1950 && clobber(x1) 1951 && clobber(s0) 1952 && clobber(s1) 1953 && clobber(or) 1954 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLloadidx1 [i0] {s} p idx mem)) y) 1955 1956 // Big-endian loads 1957 1958 (ORL 1959 x1:(MOVBload [i1] {s} p mem) 1960 sh:(SHLLconst [8] x0:(MOVBload [i0] {s} p mem))) 1961 && i1 == i0+1 1962 && x0.Uses == 1 1963 && x1.Uses == 1 1964 && sh.Uses == 1 1965 && mergePoint(b,x0,x1) != nil 1966 && clobber(x0) 1967 && clobber(x1) 1968 && clobber(sh) 1969 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem)) 1970 1971 (ORQ 1972 x1:(MOVBload [i1] {s} p mem) 1973 sh:(SHLQconst [8] x0:(MOVBload [i0] {s} p mem))) 1974 && i1 == i0+1 1975 && x0.Uses == 1 1976 && x1.Uses == 1 1977 && sh.Uses == 1 1978 && mergePoint(b,x0,x1) != nil 1979 && clobber(x0) 1980 && clobber(x1) 1981 && clobber(sh) 1982 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem)) 1983 1984 (ORL 1985 r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)) 1986 sh:(SHLLconst [16] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))) 1987 && i1 == i0+2 1988 && x0.Uses == 1 1989 && x1.Uses == 1 1990 && r0.Uses == 1 1991 && r1.Uses == 1 1992 && sh.Uses == 1 1993 && mergePoint(b,x0,x1) != nil 1994 && clobber(x0) 1995 && clobber(x1) 1996 && clobber(r0) 1997 && clobber(r1) 1998 && clobber(sh) 1999 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem)) 2000 2001 (ORQ 2002 r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)) 2003 sh:(SHLQconst [16] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))) 2004 && i1 == i0+2 2005 && x0.Uses == 1 2006 && x1.Uses == 1 2007 && r0.Uses == 1 2008 && r1.Uses == 1 2009 && sh.Uses == 1 2010 && mergePoint(b,x0,x1) != nil 2011 && clobber(x0) 2012 && clobber(x1) 2013 && clobber(r0) 2014 && clobber(r1) 2015 && clobber(sh) 2016 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem)) 2017 2018 (ORQ 2019 r1:(BSWAPL x1:(MOVLload [i1] {s} p mem)) 2020 sh:(SHLQconst [32] r0:(BSWAPL x0:(MOVLload [i0] {s} p mem)))) 2021 && i1 == i0+4 2022 && x0.Uses == 1 2023 && x1.Uses == 1 2024 && r0.Uses == 1 2025 && r1.Uses == 1 2026 && sh.Uses == 1 2027 && mergePoint(b,x0,x1) != nil 2028 && clobber(x0) 2029 && clobber(x1) 2030 && clobber(r0) 2031 && clobber(r1) 2032 && clobber(sh) 2033 -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQload [i0] {s} p mem)) 2034 2035 (ORL 2036 s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem)) 2037 or:(ORL 2038 s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem)) 2039 y)) 2040 && i1 == i0+1 2041 && j1 == j0-8 2042 && j1 % 16 == 0 2043 && x0.Uses == 1 2044 && x1.Uses == 1 2045 && s0.Uses == 1 2046 && s1.Uses == 1 2047 && or.Uses == 1 2048 && mergePoint(b,x0,x1) != nil 2049 && clobber(x0) 2050 && clobber(x1) 2051 && clobber(s0) 2052 && clobber(s1) 2053 && clobber(or) 2054 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWload [i0] {s} p mem))) y) 2055 2056 (ORQ 2057 s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem)) 2058 or:(ORQ 2059 s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem)) 2060 y)) 2061 && i1 == i0+1 2062 && j1 == j0-8 2063 && j1 % 16 == 0 2064 && x0.Uses == 1 2065 && x1.Uses == 1 2066 && s0.Uses == 1 2067 && s1.Uses == 1 2068 && or.Uses == 1 2069 && mergePoint(b,x0,x1) != nil 2070 && clobber(x0) 2071 && clobber(x1) 2072 && clobber(s0) 2073 && clobber(s1) 2074 && clobber(or) 2075 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWload [i0] {s} p mem))) y) 2076 2077 (ORQ 2078 s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem))) 2079 or:(ORQ 2080 s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem))) 2081 y)) 2082 && i1 == i0+2 2083 && j1 == j0-16 2084 && j1 % 32 == 0 2085 && x0.Uses == 1 2086 && x1.Uses == 1 2087 && r0.Uses == 1 2088 && r1.Uses == 1 2089 && s0.Uses == 1 2090 && s1.Uses == 1 2091 && or.Uses == 1 2092 && mergePoint(b,x0,x1) != nil 2093 && clobber(x0) 2094 && clobber(x1) 2095 && clobber(r0) 2096 && clobber(r1) 2097 && clobber(s0) 2098 && clobber(s1) 2099 && clobber(or) 2100 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <typ.UInt32> (MOVLload [i0] {s} p mem))) y) 2101 2102 // Big-endian indexed loads 2103 2104 (ORL 2105 x1:(MOVBloadidx1 [i1] {s} p idx mem) 2106 sh:(SHLLconst [8] x0:(MOVBloadidx1 [i0] {s} p idx mem))) 2107 && i1 == i0+1 2108 && x0.Uses == 1 2109 && x1.Uses == 1 2110 && sh.Uses == 1 2111 && mergePoint(b,x0,x1) != nil 2112 && clobber(x0) 2113 && clobber(x1) 2114 && clobber(sh) 2115 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem)) 2116 2117 (ORQ 2118 x1:(MOVBloadidx1 [i1] {s} p idx mem) 2119 sh:(SHLQconst [8] x0:(MOVBloadidx1 [i0] {s} p idx mem))) 2120 && i1 == i0+1 2121 && x0.Uses == 1 2122 && x1.Uses == 1 2123 && sh.Uses == 1 2124 && mergePoint(b,x0,x1) != nil 2125 && clobber(x0) 2126 && clobber(x1) 2127 && clobber(sh) 2128 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem)) 2129 2130 (ORL 2131 r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 2132 sh:(SHLLconst [16] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))) 2133 && i1 == i0+2 2134 && x0.Uses == 1 2135 && x1.Uses == 1 2136 && r0.Uses == 1 2137 && r1.Uses == 1 2138 && sh.Uses == 1 2139 && mergePoint(b,x0,x1) != nil 2140 && clobber(x0) 2141 && clobber(x1) 2142 && clobber(r0) 2143 && clobber(r1) 2144 && clobber(sh) 2145 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem)) 2146 2147 (ORQ 2148 r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 2149 sh:(SHLQconst [16] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))) 2150 && i1 == i0+2 2151 && x0.Uses == 1 2152 && x1.Uses == 1 2153 && r0.Uses == 1 2154 && r1.Uses == 1 2155 && sh.Uses == 1 2156 && mergePoint(b,x0,x1) != nil 2157 && clobber(x0) 2158 && clobber(x1) 2159 && clobber(r0) 2160 && clobber(r1) 2161 && clobber(sh) 2162 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem)) 2163 2164 (ORQ 2165 r1:(BSWAPL x1:(MOVLloadidx1 [i1] {s} p idx mem)) 2166 sh:(SHLQconst [32] r0:(BSWAPL x0:(MOVLloadidx1 [i0] {s} p idx mem)))) 2167 && i1 == i0+4 2168 && x0.Uses == 1 2169 && x1.Uses == 1 2170 && r0.Uses == 1 2171 && r1.Uses == 1 2172 && sh.Uses == 1 2173 && mergePoint(b,x0,x1) != nil 2174 && clobber(x0) 2175 && clobber(x1) 2176 && clobber(r0) 2177 && clobber(r1) 2178 && clobber(sh) 2179 -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQloadidx1 [i0] {s} p idx mem)) 2180 2181 (ORL 2182 s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 2183 or:(ORL 2184 s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 2185 y)) 2186 && i1 == i0+1 2187 && j1 == j0-8 2188 && j1 % 16 == 0 2189 && x0.Uses == 1 2190 && x1.Uses == 1 2191 && s0.Uses == 1 2192 && s1.Uses == 1 2193 && or.Uses == 1 2194 && mergePoint(b,x0,x1) != nil 2195 && clobber(x0) 2196 && clobber(x1) 2197 && clobber(s0) 2198 && clobber(s1) 2199 && clobber(or) 2200 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y) 2201 2202 (ORQ 2203 s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 2204 or:(ORQ 2205 s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 2206 y)) 2207 && i1 == i0+1 2208 && j1 == j0-8 2209 && j1 % 16 == 0 2210 && x0.Uses == 1 2211 && x1.Uses == 1 2212 && s0.Uses == 1 2213 && s1.Uses == 1 2214 && or.Uses == 1 2215 && mergePoint(b,x0,x1) != nil 2216 && clobber(x0) 2217 && clobber(x1) 2218 && clobber(s0) 2219 && clobber(s1) 2220 && clobber(or) 2221 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y) 2222 2223 (ORQ 2224 s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem))) 2225 or:(ORQ 2226 s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 2227 y)) 2228 && i1 == i0+2 2229 && j1 == j0-16 2230 && j1 % 32 == 0 2231 && x0.Uses == 1 2232 && x1.Uses == 1 2233 && r0.Uses == 1 2234 && r1.Uses == 1 2235 && s0.Uses == 1 2236 && s1.Uses == 1 2237 && or.Uses == 1 2238 && mergePoint(b,x0,x1) != nil 2239 && clobber(x0) 2240 && clobber(x1) 2241 && clobber(r0) 2242 && clobber(r1) 2243 && clobber(s0) 2244 && clobber(s1) 2245 && clobber(or) 2246 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <typ.UInt32> (MOVLloadidx1 [i0] {s} p idx mem))) y) 2247 2248 // Combine 2 byte stores + shift into rolw 8 + word store 2249 (MOVBstore [i] {s} p w 2250 x0:(MOVBstore [i-1] {s} p (SHRWconst [8] w) mem)) 2251 && x0.Uses == 1 2252 && clobber(x0) 2253 -> (MOVWstore [i-1] {s} p (ROLWconst <w.Type> [8] w) mem) 2254 2255 (MOVBstoreidx1 [i] {s} p idx w 2256 x0:(MOVBstoreidx1 [i-1] {s} p idx (SHRWconst [8] w) mem)) 2257 && x0.Uses == 1 2258 && clobber(x0) 2259 -> (MOVWstoreidx1 [i-1] {s} p idx (ROLWconst <w.Type> [8] w) mem) 2260 2261 // Combine stores + shifts into bswap and larger (unaligned) stores 2262 (MOVBstore [i] {s} p w 2263 x2:(MOVBstore [i-1] {s} p (SHRLconst [8] w) 2264 x1:(MOVBstore [i-2] {s} p (SHRLconst [16] w) 2265 x0:(MOVBstore [i-3] {s} p (SHRLconst [24] w) mem)))) 2266 && x0.Uses == 1 2267 && x1.Uses == 1 2268 && x2.Uses == 1 2269 && clobber(x0) 2270 && clobber(x1) 2271 && clobber(x2) 2272 -> (MOVLstore [i-3] {s} p (BSWAPL <w.Type> w) mem) 2273 2274 (MOVBstoreidx1 [i] {s} p idx w 2275 x2:(MOVBstoreidx1 [i-1] {s} p idx (SHRLconst [8] w) 2276 x1:(MOVBstoreidx1 [i-2] {s} p idx (SHRLconst [16] w) 2277 x0:(MOVBstoreidx1 [i-3] {s} p idx (SHRLconst [24] w) mem)))) 2278 && x0.Uses == 1 2279 && x1.Uses == 1 2280 && x2.Uses == 1 2281 && clobber(x0) 2282 && clobber(x1) 2283 && clobber(x2) 2284 -> (MOVLstoreidx1 [i-3] {s} p idx (BSWAPL <w.Type> w) mem) 2285 2286 (MOVBstore [i] {s} p w 2287 x6:(MOVBstore [i-1] {s} p (SHRQconst [8] w) 2288 x5:(MOVBstore [i-2] {s} p (SHRQconst [16] w) 2289 x4:(MOVBstore [i-3] {s} p (SHRQconst [24] w) 2290 x3:(MOVBstore [i-4] {s} p (SHRQconst [32] w) 2291 x2:(MOVBstore [i-5] {s} p (SHRQconst [40] w) 2292 x1:(MOVBstore [i-6] {s} p (SHRQconst [48] w) 2293 x0:(MOVBstore [i-7] {s} p (SHRQconst [56] w) mem)))))))) 2294 && x0.Uses == 1 2295 && x1.Uses == 1 2296 && x2.Uses == 1 2297 && x3.Uses == 1 2298 && x4.Uses == 1 2299 && x5.Uses == 1 2300 && x6.Uses == 1 2301 && clobber(x0) 2302 && clobber(x1) 2303 && clobber(x2) 2304 && clobber(x3) 2305 && clobber(x4) 2306 && clobber(x5) 2307 && clobber(x6) 2308 -> (MOVQstore [i-7] {s} p (BSWAPQ <w.Type> w) mem) 2309 2310 (MOVBstoreidx1 [i] {s} p idx w 2311 x6:(MOVBstoreidx1 [i-1] {s} p idx (SHRQconst [8] w) 2312 x5:(MOVBstoreidx1 [i-2] {s} p idx (SHRQconst [16] w) 2313 x4:(MOVBstoreidx1 [i-3] {s} p idx (SHRQconst [24] w) 2314 x3:(MOVBstoreidx1 [i-4] {s} p idx (SHRQconst [32] w) 2315 x2:(MOVBstoreidx1 [i-5] {s} p idx (SHRQconst [40] w) 2316 x1:(MOVBstoreidx1 [i-6] {s} p idx (SHRQconst [48] w) 2317 x0:(MOVBstoreidx1 [i-7] {s} p idx (SHRQconst [56] w) mem)))))))) 2318 && x0.Uses == 1 2319 && x1.Uses == 1 2320 && x2.Uses == 1 2321 && x3.Uses == 1 2322 && x4.Uses == 1 2323 && x5.Uses == 1 2324 && x6.Uses == 1 2325 && clobber(x0) 2326 && clobber(x1) 2327 && clobber(x2) 2328 && clobber(x3) 2329 && clobber(x4) 2330 && clobber(x5) 2331 && clobber(x6) 2332 -> (MOVQstoreidx1 [i-7] {s} p idx (BSWAPQ <w.Type> w) mem) 2333 2334 // Combine constant stores into larger (unaligned) stores. 2335 (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem)) 2336 && x.Uses == 1 2337 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 2338 && clobber(x) 2339 -> (MOVWstoreconst [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p mem) 2340 (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem)) 2341 && x.Uses == 1 2342 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2343 && clobber(x) 2344 -> (MOVLstoreconst [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p mem) 2345 (MOVLstoreconst [c] {s} p x:(MOVLstoreconst [a] {s} p mem)) 2346 && x.Uses == 1 2347 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2348 && clobber(x) 2349 -> (MOVQstore [ValAndOff(a).Off()] {s} p (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2350 (MOVQstoreconst [c] {s} p x:(MOVQstoreconst [c2] {s} p mem)) 2351 && config.useSSE 2352 && x.Uses == 1 2353 && ValAndOff(c2).Off() + 8 == ValAndOff(c).Off() 2354 && ValAndOff(c).Val() == 0 2355 && ValAndOff(c2).Val() == 0 2356 && clobber(x) 2357 -> (MOVOstore [ValAndOff(c2).Off()] {s} p (MOVOconst [0]) mem) 2358 2359 (MOVBstoreconstidx1 [c] {s} p i x:(MOVBstoreconstidx1 [a] {s} p i mem)) 2360 && x.Uses == 1 2361 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 2362 && clobber(x) 2363 -> (MOVWstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p i mem) 2364 (MOVWstoreconstidx1 [c] {s} p i x:(MOVWstoreconstidx1 [a] {s} p i mem)) 2365 && x.Uses == 1 2366 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2367 && clobber(x) 2368 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p i mem) 2369 (MOVLstoreconstidx1 [c] {s} p i x:(MOVLstoreconstidx1 [a] {s} p i mem)) 2370 && x.Uses == 1 2371 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2372 && clobber(x) 2373 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p i (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2374 2375 (MOVWstoreconstidx2 [c] {s} p i x:(MOVWstoreconstidx2 [a] {s} p i mem)) 2376 && x.Uses == 1 2377 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2378 && clobber(x) 2379 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p (SHLQconst <i.Type> [1] i) mem) 2380 (MOVLstoreconstidx4 [c] {s} p i x:(MOVLstoreconstidx4 [a] {s} p i mem)) 2381 && x.Uses == 1 2382 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2383 && clobber(x) 2384 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p (SHLQconst <i.Type> [2] i) (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2385 2386 // Combine stores into larger (unaligned) stores. 2387 (MOVBstore [i] {s} p (SHRQconst [8] w) x:(MOVBstore [i-1] {s} p w mem)) 2388 && x.Uses == 1 2389 && clobber(x) 2390 -> (MOVWstore [i-1] {s} p w mem) 2391 (MOVBstore [i] {s} p (SHRQconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SHRQconst [j-8] w) mem)) 2392 && x.Uses == 1 2393 && clobber(x) 2394 -> (MOVWstore [i-1] {s} p w0 mem) 2395 (MOVWstore [i] {s} p (SHRQconst [16] w) x:(MOVWstore [i-2] {s} p w mem)) 2396 && x.Uses == 1 2397 && clobber(x) 2398 -> (MOVLstore [i-2] {s} p w mem) 2399 (MOVWstore [i] {s} p (SHRQconst [j] w) x:(MOVWstore [i-2] {s} p w0:(SHRQconst [j-16] w) mem)) 2400 && x.Uses == 1 2401 && clobber(x) 2402 -> (MOVLstore [i-2] {s} p w0 mem) 2403 (MOVLstore [i] {s} p (SHRQconst [32] w) x:(MOVLstore [i-4] {s} p w mem)) 2404 && x.Uses == 1 2405 && clobber(x) 2406 -> (MOVQstore [i-4] {s} p w mem) 2407 (MOVLstore [i] {s} p (SHRQconst [j] w) x:(MOVLstore [i-4] {s} p w0:(SHRQconst [j-32] w) mem)) 2408 && x.Uses == 1 2409 && clobber(x) 2410 -> (MOVQstore [i-4] {s} p w0 mem) 2411 2412 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [8] w) x:(MOVBstoreidx1 [i-1] {s} p idx w mem)) 2413 && x.Uses == 1 2414 && clobber(x) 2415 -> (MOVWstoreidx1 [i-1] {s} p idx w mem) 2416 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVBstoreidx1 [i-1] {s} p idx w0:(SHRQconst [j-8] w) mem)) 2417 && x.Uses == 1 2418 && clobber(x) 2419 -> (MOVWstoreidx1 [i-1] {s} p idx w0 mem) 2420 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx1 [i-2] {s} p idx w mem)) 2421 && x.Uses == 1 2422 && clobber(x) 2423 -> (MOVLstoreidx1 [i-2] {s} p idx w mem) 2424 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx1 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 2425 && x.Uses == 1 2426 && clobber(x) 2427 -> (MOVLstoreidx1 [i-2] {s} p idx w0 mem) 2428 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx1 [i-4] {s} p idx w mem)) 2429 && x.Uses == 1 2430 && clobber(x) 2431 -> (MOVQstoreidx1 [i-4] {s} p idx w mem) 2432 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx1 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 2433 && x.Uses == 1 2434 && clobber(x) 2435 -> (MOVQstoreidx1 [i-4] {s} p idx w0 mem) 2436 2437 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx2 [i-2] {s} p idx w mem)) 2438 && x.Uses == 1 2439 && clobber(x) 2440 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w mem) 2441 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx2 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 2442 && x.Uses == 1 2443 && clobber(x) 2444 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w0 mem) 2445 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx4 [i-4] {s} p idx w mem)) 2446 && x.Uses == 1 2447 && clobber(x) 2448 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w mem) 2449 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx4 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 2450 && x.Uses == 1 2451 && clobber(x) 2452 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w0 mem) 2453 2454 (MOVBstore [i] {s} p 2455 x1:(MOVBload [j] {s2} p2 mem) 2456 mem2:(MOVBstore [i-1] {s} p 2457 x2:(MOVBload [j-1] {s2} p2 mem) mem)) 2458 && x1.Uses == 1 2459 && x2.Uses == 1 2460 && mem2.Uses == 1 2461 && clobber(x1) 2462 && clobber(x2) 2463 && clobber(mem2) 2464 -> (MOVWstore [i-1] {s} p (MOVWload [j-1] {s2} p2 mem) mem) 2465 2466 (MOVWstore [i] {s} p 2467 x1:(MOVWload [j] {s2} p2 mem) 2468 mem2:(MOVWstore [i-2] {s} p 2469 x2:(MOVWload [j-2] {s2} p2 mem) mem)) 2470 && x1.Uses == 1 2471 && x2.Uses == 1 2472 && mem2.Uses == 1 2473 && clobber(x1) 2474 && clobber(x2) 2475 && clobber(mem2) 2476 -> (MOVLstore [i-2] {s} p (MOVLload [j-2] {s2} p2 mem) mem) 2477 2478 (MOVLstore [i] {s} p 2479 x1:(MOVLload [j] {s2} p2 mem) 2480 mem2:(MOVLstore [i-4] {s} p 2481 x2:(MOVLload [j-4] {s2} p2 mem) mem)) 2482 && x1.Uses == 1 2483 && x2.Uses == 1 2484 && mem2.Uses == 1 2485 && clobber(x1) 2486 && clobber(x2) 2487 && clobber(mem2) 2488 -> (MOVQstore [i-4] {s} p (MOVQload [j-4] {s2} p2 mem) mem) 2489 2490 // This is somewhat tricky. There may be pointers in SSE registers due to rule below. 2491 // However those register shouldn't live across GC safepoint. 2492 (MOVQstore [i] {s} p 2493 x1:(MOVQload [j] {s2} p2 mem) 2494 mem2:(MOVQstore [i-8] {s} p 2495 x2:(MOVQload [j-8] {s2} p2 mem) mem)) 2496 && x1.Uses == 1 2497 && x2.Uses == 1 2498 && mem2.Uses == 1 2499 && config.useSSE 2500 && clobber(x1) 2501 && clobber(x2) 2502 && clobber(mem2) 2503 -> (MOVOstore [i-8] {s} p (MOVOload [j-8] {s2} p2 mem) mem) 2504 2505 2506 // amd64p32 rules 2507 // same as the rules above, but with 32 instead of 64 bit pointer arithmetic. 2508 // LEAQ,ADDQ -> LEAL,ADDL 2509 (ADDLconst [c] (LEAL [d] {s} x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 2510 (LEAL [c] {s} (ADDLconst [d] x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 2511 2512 (MOVQload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2513 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2514 (MOVLload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2515 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2516 (MOVWload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2517 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2518 (MOVBload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2519 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2520 2521 (MOVQstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2522 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2523 (MOVLstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2524 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2525 (MOVWstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2526 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2527 (MOVBstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) && is32Bit(off1+off2) -> 2528 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2529 2530 (MOVQstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2531 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2532 (MOVLstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2533 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2534 (MOVWstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2535 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2536 (MOVBstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2537 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2538 2539 (MOVQload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 2540 (MOVLload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 2541 (MOVWload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 2542 (MOVBload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 2543 (MOVQstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 2544 (MOVLstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 2545 (MOVWstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 2546 (MOVBstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 2547 (MOVQstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2548 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2549 (MOVLstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2550 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2551 (MOVWstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2552 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2553 (MOVBstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2554 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2555 2556 // Merge load and op 2557 // TODO: add indexed variants? 2558 (ADDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDQmem x [off] {sym} ptr mem) 2559 (ADDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDLmem x [off] {sym} ptr mem) 2560 (SUBQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBQmem x [off] {sym} ptr mem) 2561 (SUBL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBLmem x [off] {sym} ptr mem) 2562 (ANDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDQmem x [off] {sym} ptr mem) 2563 (ANDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDLmem x [off] {sym} ptr mem) 2564 (ORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORQmem x [off] {sym} ptr mem) 2565 (ORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORLmem x [off] {sym} ptr mem) 2566 (XORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORQmem x [off] {sym} ptr mem) 2567 (XORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORLmem x [off] {sym} ptr mem) 2568 (ADDSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSDmem x [off] {sym} ptr mem) 2569 (ADDSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSSmem x [off] {sym} ptr mem) 2570 (SUBSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSDmem x [off] {sym} ptr mem) 2571 (SUBSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSSmem x [off] {sym} ptr mem) 2572 (MULSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSDmem x [off] {sym} ptr mem) 2573 (MULSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSSmem x [off] {sym} ptr mem) 2574 2575 // Merge ADDQconst and LEAQ into atomic loads. 2576 (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2577 (MOVQatomicload [off1+off2] {sym} ptr mem) 2578 (MOVLatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2579 (MOVLatomicload [off1+off2] {sym} ptr mem) 2580 (MOVQatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 2581 (MOVQatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 2582 (MOVLatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 2583 (MOVLatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 2584 2585 // Merge ADDQconst and LEAQ into atomic stores. 2586 (XCHGQ [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2587 (XCHGQ [off1+off2] {sym} val ptr mem) 2588 (XCHGQ [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 2589 (XCHGQ [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 2590 (XCHGL [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2591 (XCHGL [off1+off2] {sym} val ptr mem) 2592 (XCHGL [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 2593 (XCHGL [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 2594 2595 // Merge ADDQconst into atomic adds. 2596 // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions. 2597 (XADDQlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2598 (XADDQlock [off1+off2] {sym} val ptr mem) 2599 (XADDLlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2600 (XADDLlock [off1+off2] {sym} val ptr mem) 2601 2602 // Merge ADDQconst into atomic compare and swaps. 2603 // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions. 2604 (CMPXCHGQlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) -> 2605 (CMPXCHGQlock [off1+off2] {sym} ptr old new_ mem) 2606 (CMPXCHGLlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) -> 2607 (CMPXCHGLlock [off1+off2] {sym} ptr old new_ mem) 2608 2609 // We don't need the conditional move if we know the arg of BSF is not zero. 2610 (CMOVQEQ x _ (Select1 (BSFQ (ORQconst [c] _)))) && c != 0 -> x 2611 // Extension is unnecessary for trailing zeros. 2612 (BSFQ (ORQconst <t> [1<<8] (MOVBQZX x))) -> (BSFQ (ORQconst <t> [1<<8] x)) 2613 (BSFQ (ORQconst <t> [1<<16] (MOVWQZX x))) -> (BSFQ (ORQconst <t> [1<<16] x)) 2614 2615 // Redundant sign/zero extensions 2616 // Note: see issue 21963. We have to make sure we use the right type on 2617 // the resulting extension (the outer type, not the inner type). 2618 (MOVLQSX (MOVLQSX x)) -> (MOVLQSX x) 2619 (MOVLQSX (MOVWQSX x)) -> (MOVWQSX x) 2620 (MOVLQSX (MOVBQSX x)) -> (MOVBQSX x) 2621 (MOVWQSX (MOVWQSX x)) -> (MOVWQSX x) 2622 (MOVWQSX (MOVBQSX x)) -> (MOVBQSX x) 2623 (MOVBQSX (MOVBQSX x)) -> (MOVBQSX x) 2624 (MOVLQZX (MOVLQZX x)) -> (MOVLQZX x) 2625 (MOVLQZX (MOVWQZX x)) -> (MOVWQZX x) 2626 (MOVLQZX (MOVBQZX x)) -> (MOVBQZX x) 2627 (MOVWQZX (MOVWQZX x)) -> (MOVWQZX x) 2628 (MOVWQZX (MOVBQZX x)) -> (MOVBQZX x) 2629 (MOVBQZX (MOVBQZX x)) -> (MOVBQZX x) 2630 2631 (MOVQstore [off] {sym} ptr a:(ADDQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) 2632 && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) -> 2633 (ADDQconstmem {sym} [makeValAndOff(c,off)] ptr mem) 2634 (MOVLstore [off] {sym} ptr a:(ADDLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) 2635 && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) -> 2636 (ADDLconstmem {sym} [makeValAndOff(c,off)] ptr mem) 2637 2638 // float <-> int register moves, with no conversion. 2639 // These come up when compiling math.{Float{32,64}bits,Float{32,64}frombits}. 2640 (MOVQload [off] {sym} ptr (MOVSDstore [off] {sym} ptr val _)) -> (MOVQf2i val) 2641 (MOVLload [off] {sym} ptr (MOVSSstore [off] {sym} ptr val _)) -> (MOVLf2i val) 2642 (MOVSDload [off] {sym} ptr (MOVQstore [off] {sym} ptr val _)) -> (MOVQi2f val) 2643 (MOVSSload [off] {sym} ptr (MOVLstore [off] {sym} ptr val _)) -> (MOVLi2f val) 2644 2645 // Other load-like ops. 2646 (ADDQmem x [off] {sym} ptr (MOVSDstore [off] {sym} ptr y _)) -> (ADDQ x (MOVQf2i y)) 2647 (ADDLmem x [off] {sym} ptr (MOVSSstore [off] {sym} ptr y _)) -> (ADDL x (MOVLf2i y)) 2648 (SUBQmem x [off] {sym} ptr (MOVSDstore [off] {sym} ptr y _)) -> (SUBQ x (MOVQf2i y)) 2649 (SUBLmem x [off] {sym} ptr (MOVSSstore [off] {sym} ptr y _)) -> (SUBL x (MOVLf2i y)) 2650 (ANDQmem x [off] {sym} ptr (MOVSDstore [off] {sym} ptr y _)) -> (ANDQ x (MOVQf2i y)) 2651 (ANDLmem x [off] {sym} ptr (MOVSSstore [off] {sym} ptr y _)) -> (ANDL x (MOVLf2i y)) 2652 ( ORQmem x [off] {sym} ptr (MOVSDstore [off] {sym} ptr y _)) -> ( ORQ x (MOVQf2i y)) 2653 ( ORLmem x [off] {sym} ptr (MOVSSstore [off] {sym} ptr y _)) -> ( ORL x (MOVLf2i y)) 2654 (XORQmem x [off] {sym} ptr (MOVSDstore [off] {sym} ptr y _)) -> (XORQ x (MOVQf2i y)) 2655 (XORLmem x [off] {sym} ptr (MOVSSstore [off] {sym} ptr y _)) -> (XORL x (MOVLf2i y)) 2656 2657 (ADDQconstmem [valOff] {sym} ptr (MOVSDstore [ValAndOff(valOff).Off()] {sym} ptr x _)) -> 2658 (ADDQconst [ValAndOff(valOff).Val()] (MOVQf2i x)) 2659 (ADDLconstmem [valOff] {sym} ptr (MOVSSstore [ValAndOff(valOff).Off()] {sym} ptr x _)) -> 2660 (ADDLconst [ValAndOff(valOff).Val()] (MOVLf2i x)) 2661 2662 (ADDSDmem x [off] {sym} ptr (MOVQstore [off] {sym} ptr y _)) -> (ADDSD x (MOVQi2f y)) 2663 (ADDSSmem x [off] {sym} ptr (MOVLstore [off] {sym} ptr y _)) -> (ADDSS x (MOVLi2f y)) 2664 (SUBSDmem x [off] {sym} ptr (MOVQstore [off] {sym} ptr y _)) -> (SUBSD x (MOVQi2f y)) 2665 (SUBSSmem x [off] {sym} ptr (MOVLstore [off] {sym} ptr y _)) -> (SUBSS x (MOVLi2f y)) 2666 (MULSDmem x [off] {sym} ptr (MOVQstore [off] {sym} ptr y _)) -> (MULSD x (MOVQi2f y)) 2667 (MULSSmem x [off] {sym} ptr (MOVLstore [off] {sym} ptr y _)) -> (MULSS x (MOVLi2f y)) 2668 2669 // Redirect stores to use the other register set. 2670 (MOVQstore [off] {sym} ptr (MOVQf2i val) mem) -> (MOVSDstore [off] {sym} ptr val mem) 2671 (MOVLstore [off] {sym} ptr (MOVLf2i val) mem) -> (MOVSSstore [off] {sym} ptr val mem) 2672 (MOVSDstore [off] {sym} ptr (MOVQi2f val) mem) -> (MOVQstore [off] {sym} ptr val mem) 2673 (MOVSSstore [off] {sym} ptr (MOVLi2f val) mem) -> (MOVLstore [off] {sym} ptr val mem) 2674 2675 // Load args directly into the register class where it will be used. 2676 // We do this by just modifying the type of the Arg. 2677 (MOVQf2i <t> (Arg [off] {sym})) -> @b.Func.Entry (Arg <t> [off] {sym}) 2678 (MOVLf2i <t> (Arg [off] {sym})) -> @b.Func.Entry (Arg <t> [off] {sym}) 2679 (MOVQi2f <t> (Arg [off] {sym})) -> @b.Func.Entry (Arg <t> [off] {sym}) 2680 (MOVLi2f <t> (Arg [off] {sym})) -> @b.Func.Entry (Arg <t> [off] {sym})