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