github.com/tidwall/go@v0.0.0-20170415222209-6694a6888b7d/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 (SARL x (ANDLconst [31] y)) -> (SARL x y) 625 (SARQ x (ANDQconst [63] y)) -> (SARQ x y) 626 627 (SHLL x (ANDLconst [31] y)) -> (SHLL x y) 628 (SHLQ x (ANDQconst [63] y)) -> (SHLQ x y) 629 (SHLQ x (ANDLconst [63] y)) -> (SHLQ x y) 630 631 (SHRL x (ANDLconst [31] y)) -> (SHRL x y) 632 (SHRQ x (ANDQconst [63] y)) -> (SHRQ x y) 633 (SHRQ x (ANDLconst [63] y)) -> (SHRQ x y) 634 635 // Rotate instructions 636 637 (ADDQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 638 ( ORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 639 (XORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 640 641 (ADDL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 642 ( ORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 643 (XORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 644 645 (ADDL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 646 ( ORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 647 (XORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 648 649 (ADDL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 650 ( ORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 651 (XORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 652 653 (ROLQconst [c] (ROLQconst [d] x)) -> (ROLQconst [(c+d)&63] x) 654 (ROLLconst [c] (ROLLconst [d] x)) -> (ROLLconst [(c+d)&31] x) 655 (ROLWconst [c] (ROLWconst [d] x)) -> (ROLWconst [(c+d)&15] x) 656 (ROLBconst [c] (ROLBconst [d] x)) -> (ROLBconst [(c+d)& 7] x) 657 658 // TODO: non-constant rotates if shift amount is known to be bounded (shift & 63 or something). 659 660 // Constant shift simplifications 661 662 (SHLQconst x [0]) -> x 663 (SHRQconst x [0]) -> x 664 (SARQconst x [0]) -> x 665 666 (SHLLconst x [0]) -> x 667 (SHRLconst x [0]) -> x 668 (SARLconst x [0]) -> x 669 670 (SHRWconst x [0]) -> x 671 (SARWconst x [0]) -> x 672 673 (SHRBconst x [0]) -> x 674 (SARBconst x [0]) -> x 675 676 (ROLQconst x [0]) -> x 677 (ROLLconst x [0]) -> x 678 (ROLWconst x [0]) -> x 679 (ROLBconst x [0]) -> x 680 681 // Note: the word and byte shifts keep the low 5 bits (not the low 4 or 3 bits) 682 // because the x86 instructions are defined to use all 5 bits of the shift even 683 // for the small shifts. I don't think we'll ever generate a weird shift (e.g. 684 // (SHRW x (MOVLconst [24])), but just in case. 685 686 (CMPQ x (MOVQconst [c])) && is32Bit(c) -> (CMPQconst x [c]) 687 (CMPQ (MOVQconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPQconst x [c])) 688 (CMPL x (MOVLconst [c])) -> (CMPLconst x [c]) 689 (CMPL (MOVLconst [c]) x) -> (InvertFlags (CMPLconst x [c])) 690 (CMPW x (MOVLconst [c])) -> (CMPWconst x [int64(int16(c))]) 691 (CMPW (MOVLconst [c]) x) -> (InvertFlags (CMPWconst x [int64(int16(c))])) 692 (CMPB x (MOVLconst [c])) -> (CMPBconst x [int64(int8(c))]) 693 (CMPB (MOVLconst [c]) x) -> (InvertFlags (CMPBconst x [int64(int8(c))])) 694 695 // Using MOVZX instead of AND is cheaper. 696 (ANDLconst [0xFF] x) -> (MOVBQZX x) 697 (ANDLconst [0xFFFF] x) -> (MOVWQZX x) 698 (ANDQconst [0xFF] x) -> (MOVBQZX x) 699 (ANDQconst [0xFFFF] x) -> (MOVWQZX x) 700 (ANDQconst [0xFFFFFFFF] x) -> (MOVLQZX x) 701 702 // strength reduction 703 // Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf: 704 // 1 - addq, shlq, leaq, negq 705 // 3 - imulq 706 // This limits the rewrites to two instructions. 707 // TODO: 27, 81 708 (MULQconst [-1] x) -> (NEGQ x) 709 (MULQconst [0] _) -> (MOVQconst [0]) 710 (MULQconst [1] x) -> x 711 (MULQconst [3] x) -> (LEAQ2 x x) 712 (MULQconst [5] x) -> (LEAQ4 x x) 713 (MULQconst [7] x) -> (LEAQ8 (NEGQ <v.Type> x) x) 714 (MULQconst [9] x) -> (LEAQ8 x x) 715 (MULQconst [11] x) -> (LEAQ2 x (LEAQ4 <v.Type> x x)) 716 (MULQconst [13] x) -> (LEAQ4 x (LEAQ2 <v.Type> x x)) 717 (MULQconst [21] x) -> (LEAQ4 x (LEAQ4 <v.Type> x x)) 718 (MULQconst [25] x) -> (LEAQ8 x (LEAQ2 <v.Type> x x)) 719 (MULQconst [37] x) -> (LEAQ4 x (LEAQ8 <v.Type> x x)) 720 (MULQconst [41] x) -> (LEAQ8 x (LEAQ4 <v.Type> x x)) 721 (MULQconst [73] x) -> (LEAQ8 x (LEAQ8 <v.Type> x x)) 722 723 (MULQconst [c] x) && isPowerOfTwo(c) -> (SHLQconst [log2(c)] x) 724 (MULQconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUBQ (SHLQconst <v.Type> [log2(c+1)] x) x) 725 (MULQconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (LEAQ1 (SHLQconst <v.Type> [log2(c-1)] x) x) 726 (MULQconst [c] x) && isPowerOfTwo(c-2) && c >= 34 -> (LEAQ2 (SHLQconst <v.Type> [log2(c-2)] x) x) 727 (MULQconst [c] x) && isPowerOfTwo(c-4) && c >= 68 -> (LEAQ4 (SHLQconst <v.Type> [log2(c-4)] x) x) 728 (MULQconst [c] x) && isPowerOfTwo(c-8) && c >= 136 -> (LEAQ8 (SHLQconst <v.Type> [log2(c-8)] x) x) 729 (MULQconst [c] x) && c%3 == 0 && isPowerOfTwo(c/3) -> (SHLQconst [log2(c/3)] (LEAQ2 <v.Type> x x)) 730 (MULQconst [c] x) && c%5 == 0 && isPowerOfTwo(c/5) -> (SHLQconst [log2(c/5)] (LEAQ4 <v.Type> x x)) 731 (MULQconst [c] x) && c%9 == 0 && isPowerOfTwo(c/9) -> (SHLQconst [log2(c/9)] (LEAQ8 <v.Type> x x)) 732 733 // combine add/shift into LEAQ 734 (ADDQ x (SHLQconst [3] y)) -> (LEAQ8 x y) 735 (ADDQ x (SHLQconst [2] y)) -> (LEAQ4 x y) 736 (ADDQ x (SHLQconst [1] y)) -> (LEAQ2 x y) 737 (ADDQ x (ADDQ y y)) -> (LEAQ2 x y) 738 (ADDQ x (ADDQ x y)) -> (LEAQ2 y x) 739 740 // combine ADDQ/ADDQconst into LEAQ1 741 (ADDQconst [c] (ADDQ x y)) -> (LEAQ1 [c] x y) 742 (ADDQ (ADDQconst [c] x) y) -> (LEAQ1 [c] x y) 743 744 // fold ADDQ into LEAQ 745 (ADDQconst [c] (LEAQ [d] {s} x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 746 (LEAQ [c] {s} (ADDQconst [d] x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 747 (LEAQ [c] {s} (ADDQ x y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 748 (ADDQ x (LEAQ [c] {s} y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 749 750 // fold ADDQconst into LEAQx 751 (ADDQconst [c] (LEAQ1 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ1 [c+d] {s} x y) 752 (ADDQconst [c] (LEAQ2 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ2 [c+d] {s} x y) 753 (ADDQconst [c] (LEAQ4 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ4 [c+d] {s} x y) 754 (ADDQconst [c] (LEAQ8 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ8 [c+d] {s} x y) 755 (LEAQ1 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ1 [c+d] {s} x y) 756 (LEAQ2 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ2 [c+d] {s} x y) 757 (LEAQ2 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+2*d) && y.Op != OpSB -> (LEAQ2 [c+2*d] {s} x y) 758 (LEAQ4 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ4 [c+d] {s} x y) 759 (LEAQ4 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+4*d) && y.Op != OpSB -> (LEAQ4 [c+4*d] {s} x y) 760 (LEAQ8 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ8 [c+d] {s} x y) 761 (LEAQ8 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+8*d) && y.Op != OpSB -> (LEAQ8 [c+8*d] {s} x y) 762 763 // fold shifts into LEAQx 764 (LEAQ1 [c] {s} x (SHLQconst [1] y)) -> (LEAQ2 [c] {s} x y) 765 (LEAQ1 [c] {s} x (SHLQconst [2] y)) -> (LEAQ4 [c] {s} x y) 766 (LEAQ1 [c] {s} x (SHLQconst [3] y)) -> (LEAQ8 [c] {s} x y) 767 (LEAQ2 [c] {s} x (SHLQconst [1] y)) -> (LEAQ4 [c] {s} x y) 768 (LEAQ2 [c] {s} x (SHLQconst [2] y)) -> (LEAQ8 [c] {s} x y) 769 (LEAQ4 [c] {s} x (SHLQconst [1] y)) -> (LEAQ8 [c] {s} x y) 770 771 // reverse ordering of compare instruction 772 (SETL (InvertFlags x)) -> (SETG x) 773 (SETG (InvertFlags x)) -> (SETL x) 774 (SETB (InvertFlags x)) -> (SETA x) 775 (SETA (InvertFlags x)) -> (SETB x) 776 (SETLE (InvertFlags x)) -> (SETGE x) 777 (SETGE (InvertFlags x)) -> (SETLE x) 778 (SETBE (InvertFlags x)) -> (SETAE x) 779 (SETAE (InvertFlags x)) -> (SETBE x) 780 (SETEQ (InvertFlags x)) -> (SETEQ x) 781 (SETNE (InvertFlags x)) -> (SETNE x) 782 783 // sign extended loads 784 // Note: The combined instruction must end up in the same block 785 // as the original load. If not, we end up making a value with 786 // memory type live in two different blocks, which can lead to 787 // multiple memory values alive simultaneously. 788 // Make sure we don't combine these ops if the load has another use. 789 // This prevents a single load from being split into multiple loads 790 // which then might return different values. See test/atomicload.go. 791 (MOVBQSX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 792 (MOVBQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 793 (MOVBQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 794 (MOVBQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 795 (MOVBQZX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 796 (MOVBQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 797 (MOVBQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 798 (MOVBQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 799 (MOVWQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 800 (MOVWQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 801 (MOVWQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 802 (MOVWQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 803 (MOVWQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 804 (MOVWQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 805 (MOVLQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 806 (MOVLQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 807 (MOVLQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 808 (MOVLQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 809 810 (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBloadidx1 <v.Type> [off] {sym} ptr idx mem) 811 (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx1 <v.Type> [off] {sym} ptr idx mem) 812 (MOVWQZX x:(MOVWloadidx2 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx2 <v.Type> [off] {sym} ptr idx mem) 813 (MOVLQZX x:(MOVLloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx1 <v.Type> [off] {sym} ptr idx mem) 814 (MOVLQZX x:(MOVLloadidx4 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx4 <v.Type> [off] {sym} ptr idx mem) 815 816 // replace load from same location as preceding store with copy 817 (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 818 (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 819 (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 820 (MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 821 822 // Fold extensions and ANDs together. 823 (MOVBQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xff] x) 824 (MOVWQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xffff] x) 825 (MOVLQZX (ANDLconst [c] x)) -> (ANDLconst [c] x) 826 (MOVBQSX (ANDLconst [c] x)) && c & 0x80 == 0 -> (ANDLconst [c & 0x7f] x) 827 (MOVWQSX (ANDLconst [c] x)) && c & 0x8000 == 0 -> (ANDLconst [c & 0x7fff] x) 828 (MOVLQSX (ANDLconst [c] x)) && c & 0x80000000 == 0 -> (ANDLconst [c & 0x7fffffff] x) 829 830 // Don't extend before storing 831 (MOVLstore [off] {sym} ptr (MOVLQSX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 832 (MOVWstore [off] {sym} ptr (MOVWQSX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 833 (MOVBstore [off] {sym} ptr (MOVBQSX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 834 (MOVLstore [off] {sym} ptr (MOVLQZX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 835 (MOVWstore [off] {sym} ptr (MOVWQZX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 836 (MOVBstore [off] {sym} ptr (MOVBQZX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 837 838 // fold constants into memory operations 839 // Note that this is not always a good idea because if not all the uses of 840 // the ADDQconst get eliminated, we still have to compute the ADDQconst and we now 841 // have potentially two live values (ptr and (ADDQconst [off] ptr)) instead of one. 842 // Nevertheless, let's do it! 843 (MOVQload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 844 (MOVLload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 845 (MOVWload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 846 (MOVBload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 847 (MOVSSload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSSload [off1+off2] {sym} ptr mem) 848 (MOVSDload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSDload [off1+off2] {sym} ptr mem) 849 (MOVOload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVOload [off1+off2] {sym} ptr mem) 850 851 (MOVQstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 852 (MOVLstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 853 (MOVWstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 854 (MOVBstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 855 (MOVSSstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSSstore [off1+off2] {sym} ptr val mem) 856 (MOVSDstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSDstore [off1+off2] {sym} ptr val mem) 857 (MOVOstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVOstore [off1+off2] {sym} ptr val mem) 858 859 // Fold constants into stores. 860 (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> 861 (MOVQstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 862 (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 863 (MOVLstoreconst [makeValAndOff(int64(int32(c)),off)] {sym} ptr mem) 864 (MOVWstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 865 (MOVWstoreconst [makeValAndOff(int64(int16(c)),off)] {sym} ptr mem) 866 (MOVBstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 867 (MOVBstoreconst [makeValAndOff(int64(int8(c)),off)] {sym} ptr mem) 868 869 // Fold address offsets into constant stores. 870 (MOVQstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 871 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 872 (MOVLstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 873 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 874 (MOVWstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 875 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 876 (MOVBstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 877 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 878 879 // We need to fold LEAQ into the MOVx ops so that the live variable analysis knows 880 // what variables are being read/written by the ops. 881 (MOVQload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 882 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 883 (MOVLload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 884 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 885 (MOVWload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 886 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 887 (MOVBload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 888 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 889 (MOVSSload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 890 (MOVSSload [off1+off2] {mergeSym(sym1,sym2)} base mem) 891 (MOVSDload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 892 (MOVSDload [off1+off2] {mergeSym(sym1,sym2)} base mem) 893 (MOVOload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 894 (MOVOload [off1+off2] {mergeSym(sym1,sym2)} base mem) 895 896 (MOVBQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 897 (MOVBQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 898 (MOVWQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 899 (MOVWQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 900 (MOVLQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 901 (MOVLQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 902 903 (MOVQstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 904 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 905 (MOVLstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 906 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 907 (MOVWstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 908 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 909 (MOVBstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 910 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 911 (MOVSSstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 912 (MOVSSstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 913 (MOVSDstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 914 (MOVSDstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 915 (MOVOstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 916 (MOVOstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 917 918 (MOVQstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 919 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 920 (MOVLstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 921 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 922 (MOVWstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 923 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 924 (MOVBstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 925 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 926 927 // generating indexed loads and stores 928 (MOVBload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 929 (MOVBloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 930 (MOVWload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 931 (MOVWloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 932 (MOVWload [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 933 (MOVWloadidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 934 (MOVLload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 935 (MOVLloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 936 (MOVLload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 937 (MOVLloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 938 (MOVQload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 939 (MOVQloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 940 (MOVQload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 941 (MOVQloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 942 (MOVSSload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 943 (MOVSSloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 944 (MOVSSload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 945 (MOVSSloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 946 (MOVSDload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 947 (MOVSDloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 948 (MOVSDload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 949 (MOVSDloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 950 951 (MOVBstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 952 (MOVBstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 953 (MOVWstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 954 (MOVWstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 955 (MOVWstore [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 956 (MOVWstoreidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 957 (MOVLstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 958 (MOVLstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 959 (MOVLstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 960 (MOVLstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 961 (MOVQstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 962 (MOVQstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 963 (MOVQstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 964 (MOVQstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 965 (MOVSSstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 966 (MOVSSstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 967 (MOVSSstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 968 (MOVSSstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 969 (MOVSDstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 970 (MOVSDstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 971 (MOVSDstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 972 (MOVSDstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 973 974 (MOVBload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVBloadidx1 [off] {sym} ptr idx mem) 975 (MOVWload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVWloadidx1 [off] {sym} ptr idx mem) 976 (MOVLload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVLloadidx1 [off] {sym} ptr idx mem) 977 (MOVQload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVQloadidx1 [off] {sym} ptr idx mem) 978 (MOVSSload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSSloadidx1 [off] {sym} ptr idx mem) 979 (MOVSDload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSDloadidx1 [off] {sym} ptr idx mem) 980 (MOVBstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVBstoreidx1 [off] {sym} ptr idx val mem) 981 (MOVWstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVWstoreidx1 [off] {sym} ptr idx val mem) 982 (MOVLstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVLstoreidx1 [off] {sym} ptr idx val mem) 983 (MOVQstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVQstoreidx1 [off] {sym} ptr idx val mem) 984 (MOVSSstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSSstoreidx1 [off] {sym} ptr idx val mem) 985 (MOVSDstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSDstoreidx1 [off] {sym} ptr idx val mem) 986 987 (MOVBstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 988 (MOVBstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 989 (MOVWstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 990 (MOVWstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 991 (MOVWstoreconst [x] {sym1} (LEAQ2 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 992 (MOVWstoreconstidx2 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 993 (MOVLstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 994 (MOVLstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 995 (MOVLstoreconst [x] {sym1} (LEAQ4 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 996 (MOVLstoreconstidx4 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 997 (MOVQstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 998 (MOVQstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 999 (MOVQstoreconst [x] {sym1} (LEAQ8 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1000 (MOVQstoreconstidx8 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1001 1002 (MOVBstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVBstoreconstidx1 [x] {sym} ptr idx mem) 1003 (MOVWstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVWstoreconstidx1 [x] {sym} ptr idx mem) 1004 (MOVLstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVLstoreconstidx1 [x] {sym} ptr idx mem) 1005 (MOVQstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVQstoreconstidx1 [x] {sym} ptr idx mem) 1006 1007 // combine SHLQ into indexed loads and stores 1008 (MOVWloadidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWloadidx2 [c] {sym} ptr idx mem) 1009 (MOVLloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLloadidx4 [c] {sym} ptr idx mem) 1010 (MOVQloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQloadidx8 [c] {sym} ptr idx mem) 1011 (MOVSSloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVSSloadidx4 [c] {sym} ptr idx mem) 1012 (MOVSDloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVSDloadidx8 [c] {sym} ptr idx mem) 1013 (MOVWstoreidx1 [c] {sym} ptr (SHLQconst [1] idx) val mem) -> (MOVWstoreidx2 [c] {sym} ptr idx val mem) 1014 (MOVLstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVLstoreidx4 [c] {sym} ptr idx val mem) 1015 (MOVQstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVQstoreidx8 [c] {sym} ptr idx val mem) 1016 (MOVSSstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVSSstoreidx4 [c] {sym} ptr idx val mem) 1017 (MOVSDstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVSDstoreidx8 [c] {sym} ptr idx val mem) 1018 (MOVWstoreconstidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWstoreconstidx2 [c] {sym} ptr idx mem) 1019 (MOVLstoreconstidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLstoreconstidx4 [c] {sym} ptr idx mem) 1020 (MOVQstoreconstidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQstoreconstidx8 [c] {sym} ptr idx mem) 1021 1022 // combine ADDQ into indexed loads and stores 1023 (MOVBloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 1024 (MOVWloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 1025 (MOVWloadidx2 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx2 [c+d] {sym} ptr idx mem) 1026 (MOVLloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 1027 (MOVLloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx4 [c+d] {sym} ptr idx mem) 1028 (MOVQloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 1029 (MOVQloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx8 [c+d] {sym} ptr idx mem) 1030 (MOVSSloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 1031 (MOVSSloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx4 [c+d] {sym} ptr idx mem) 1032 (MOVSDloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 1033 (MOVSDloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx8 [c+d] {sym} ptr idx mem) 1034 1035 (MOVBstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 1036 (MOVWstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 1037 (MOVWstoreidx2 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx2 [c+d] {sym} ptr idx val mem) 1038 (MOVLstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 1039 (MOVLstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx4 [c+d] {sym} ptr idx val mem) 1040 (MOVQstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 1041 (MOVQstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx8 [c+d] {sym} ptr idx val mem) 1042 (MOVSSstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 1043 (MOVSSstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx4 [c+d] {sym} ptr idx val mem) 1044 (MOVSDstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 1045 (MOVSDstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx8 [c+d] {sym} ptr idx val mem) 1046 1047 (MOVBloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 1048 (MOVWloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 1049 (MOVWloadidx2 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx2 [c+2*d] {sym} ptr idx mem) 1050 (MOVLloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 1051 (MOVLloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx4 [c+4*d] {sym} ptr idx mem) 1052 (MOVQloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 1053 (MOVQloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx8 [c+8*d] {sym} ptr idx mem) 1054 (MOVSSloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 1055 (MOVSSloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx4 [c+4*d] {sym} ptr idx mem) 1056 (MOVSDloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 1057 (MOVSDloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx8 [c+8*d] {sym} ptr idx mem) 1058 1059 (MOVBstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 1060 (MOVWstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 1061 (MOVWstoreidx2 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx2 [c+2*d] {sym} ptr idx val mem) 1062 (MOVLstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 1063 (MOVLstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx4 [c+4*d] {sym} ptr idx val mem) 1064 (MOVQstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 1065 (MOVQstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx8 [c+8*d] {sym} ptr idx val mem) 1066 (MOVSSstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 1067 (MOVSSstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx4 [c+4*d] {sym} ptr idx val mem) 1068 (MOVSDstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 1069 (MOVSDstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx8 [c+8*d] {sym} ptr idx val mem) 1070 1071 (MOVBstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1072 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1073 (MOVWstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1074 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1075 (MOVWstoreconstidx2 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1076 (MOVWstoreconstidx2 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1077 (MOVLstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1078 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1079 (MOVLstoreconstidx4 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1080 (MOVLstoreconstidx4 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1081 (MOVQstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1082 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1083 (MOVQstoreconstidx8 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1084 (MOVQstoreconstidx8 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1085 1086 (MOVBstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1087 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1088 (MOVWstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1089 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1090 (MOVWstoreconstidx2 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1091 (MOVWstoreconstidx2 [ValAndOff(x).add(2*c)] {sym} ptr idx mem) 1092 (MOVLstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1093 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1094 (MOVLstoreconstidx4 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1095 (MOVLstoreconstidx4 [ValAndOff(x).add(4*c)] {sym} ptr idx mem) 1096 (MOVQstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1097 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1098 (MOVQstoreconstidx8 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1099 (MOVQstoreconstidx8 [ValAndOff(x).add(8*c)] {sym} ptr idx mem) 1100 1101 // fold LEAQs together 1102 (LEAQ [off1] {sym1} (LEAQ [off2] {sym2} x)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1103 (LEAQ [off1+off2] {mergeSym(sym1,sym2)} x) 1104 1105 // LEAQ into LEAQ1 1106 (LEAQ1 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1107 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1108 1109 // LEAQ1 into LEAQ 1110 (LEAQ [off1] {sym1} (LEAQ1 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1111 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1112 1113 // LEAQ into LEAQ[248] 1114 (LEAQ2 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1115 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1116 (LEAQ4 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1117 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1118 (LEAQ8 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1119 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1120 1121 // LEAQ[248] into LEAQ 1122 (LEAQ [off1] {sym1} (LEAQ2 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1123 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1124 (LEAQ [off1] {sym1} (LEAQ4 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1125 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1126 (LEAQ [off1] {sym1} (LEAQ8 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1127 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1128 1129 // Absorb InvertFlags into branches. 1130 (LT (InvertFlags cmp) yes no) -> (GT cmp yes no) 1131 (GT (InvertFlags cmp) yes no) -> (LT cmp yes no) 1132 (LE (InvertFlags cmp) yes no) -> (GE cmp yes no) 1133 (GE (InvertFlags cmp) yes no) -> (LE cmp yes no) 1134 (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no) 1135 (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no) 1136 (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no) 1137 (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no) 1138 (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no) 1139 (NE (InvertFlags cmp) yes no) -> (NE cmp yes no) 1140 1141 // Constant comparisons. 1142 (CMPQconst (MOVQconst [x]) [y]) && x==y -> (FlagEQ) 1143 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)<uint64(y) -> (FlagLT_ULT) 1144 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)>uint64(y) -> (FlagLT_UGT) 1145 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)<uint64(y) -> (FlagGT_ULT) 1146 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)>uint64(y) -> (FlagGT_UGT) 1147 (CMPLconst (MOVLconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ) 1148 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT) 1149 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT) 1150 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT) 1151 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT) 1152 (CMPWconst (MOVLconst [x]) [y]) && int16(x)==int16(y) -> (FlagEQ) 1153 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)<uint16(y) -> (FlagLT_ULT) 1154 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)>uint16(y) -> (FlagLT_UGT) 1155 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)<uint16(y) -> (FlagGT_ULT) 1156 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)>uint16(y) -> (FlagGT_UGT) 1157 (CMPBconst (MOVLconst [x]) [y]) && int8(x)==int8(y) -> (FlagEQ) 1158 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)<uint8(y) -> (FlagLT_ULT) 1159 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)>uint8(y) -> (FlagLT_UGT) 1160 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)<uint8(y) -> (FlagGT_ULT) 1161 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)>uint8(y) -> (FlagGT_UGT) 1162 1163 // Other known comparisons. 1164 (CMPQconst (MOVBQZX _) [c]) && 0xFF < c -> (FlagLT_ULT) 1165 (CMPQconst (MOVWQZX _) [c]) && 0xFFFF < c -> (FlagLT_ULT) 1166 (CMPQconst (MOVLQZX _) [c]) && 0xFFFFFFFF < c -> (FlagLT_ULT) 1167 (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT_ULT) 1168 (CMPQconst (SHRQconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT) 1169 (CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1170 (CMPQconst (ANDLconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1171 (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT) 1172 (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT) 1173 (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT) 1174 // TODO: DIVxU also. 1175 1176 // Absorb flag constants into SBB ops. 1177 (SBBQcarrymask (FlagEQ)) -> (MOVQconst [0]) 1178 (SBBQcarrymask (FlagLT_ULT)) -> (MOVQconst [-1]) 1179 (SBBQcarrymask (FlagLT_UGT)) -> (MOVQconst [0]) 1180 (SBBQcarrymask (FlagGT_ULT)) -> (MOVQconst [-1]) 1181 (SBBQcarrymask (FlagGT_UGT)) -> (MOVQconst [0]) 1182 (SBBLcarrymask (FlagEQ)) -> (MOVLconst [0]) 1183 (SBBLcarrymask (FlagLT_ULT)) -> (MOVLconst [-1]) 1184 (SBBLcarrymask (FlagLT_UGT)) -> (MOVLconst [0]) 1185 (SBBLcarrymask (FlagGT_ULT)) -> (MOVLconst [-1]) 1186 (SBBLcarrymask (FlagGT_UGT)) -> (MOVLconst [0]) 1187 1188 // Absorb flag constants into branches. 1189 (EQ (FlagEQ) yes no) -> (First nil yes no) 1190 (EQ (FlagLT_ULT) yes no) -> (First nil no yes) 1191 (EQ (FlagLT_UGT) yes no) -> (First nil no yes) 1192 (EQ (FlagGT_ULT) yes no) -> (First nil no yes) 1193 (EQ (FlagGT_UGT) yes no) -> (First nil no yes) 1194 1195 (NE (FlagEQ) yes no) -> (First nil no yes) 1196 (NE (FlagLT_ULT) yes no) -> (First nil yes no) 1197 (NE (FlagLT_UGT) yes no) -> (First nil yes no) 1198 (NE (FlagGT_ULT) yes no) -> (First nil yes no) 1199 (NE (FlagGT_UGT) yes no) -> (First nil yes no) 1200 1201 (LT (FlagEQ) yes no) -> (First nil no yes) 1202 (LT (FlagLT_ULT) yes no) -> (First nil yes no) 1203 (LT (FlagLT_UGT) yes no) -> (First nil yes no) 1204 (LT (FlagGT_ULT) yes no) -> (First nil no yes) 1205 (LT (FlagGT_UGT) yes no) -> (First nil no yes) 1206 1207 (LE (FlagEQ) yes no) -> (First nil yes no) 1208 (LE (FlagLT_ULT) yes no) -> (First nil yes no) 1209 (LE (FlagLT_UGT) yes no) -> (First nil yes no) 1210 (LE (FlagGT_ULT) yes no) -> (First nil no yes) 1211 (LE (FlagGT_UGT) yes no) -> (First nil no yes) 1212 1213 (GT (FlagEQ) yes no) -> (First nil no yes) 1214 (GT (FlagLT_ULT) yes no) -> (First nil no yes) 1215 (GT (FlagLT_UGT) yes no) -> (First nil no yes) 1216 (GT (FlagGT_ULT) yes no) -> (First nil yes no) 1217 (GT (FlagGT_UGT) yes no) -> (First nil yes no) 1218 1219 (GE (FlagEQ) yes no) -> (First nil yes no) 1220 (GE (FlagLT_ULT) yes no) -> (First nil no yes) 1221 (GE (FlagLT_UGT) yes no) -> (First nil no yes) 1222 (GE (FlagGT_ULT) yes no) -> (First nil yes no) 1223 (GE (FlagGT_UGT) yes no) -> (First nil yes no) 1224 1225 (ULT (FlagEQ) yes no) -> (First nil no yes) 1226 (ULT (FlagLT_ULT) yes no) -> (First nil yes no) 1227 (ULT (FlagLT_UGT) yes no) -> (First nil no yes) 1228 (ULT (FlagGT_ULT) yes no) -> (First nil yes no) 1229 (ULT (FlagGT_UGT) yes no) -> (First nil no yes) 1230 1231 (ULE (FlagEQ) yes no) -> (First nil yes no) 1232 (ULE (FlagLT_ULT) yes no) -> (First nil yes no) 1233 (ULE (FlagLT_UGT) yes no) -> (First nil no yes) 1234 (ULE (FlagGT_ULT) yes no) -> (First nil yes no) 1235 (ULE (FlagGT_UGT) yes no) -> (First nil no yes) 1236 1237 (UGT (FlagEQ) yes no) -> (First nil no yes) 1238 (UGT (FlagLT_ULT) yes no) -> (First nil no yes) 1239 (UGT (FlagLT_UGT) yes no) -> (First nil yes no) 1240 (UGT (FlagGT_ULT) yes no) -> (First nil no yes) 1241 (UGT (FlagGT_UGT) yes no) -> (First nil yes no) 1242 1243 (UGE (FlagEQ) yes no) -> (First nil yes no) 1244 (UGE (FlagLT_ULT) yes no) -> (First nil no yes) 1245 (UGE (FlagLT_UGT) yes no) -> (First nil yes no) 1246 (UGE (FlagGT_ULT) yes no) -> (First nil no yes) 1247 (UGE (FlagGT_UGT) yes no) -> (First nil yes no) 1248 1249 // Absorb flag constants into SETxx ops. 1250 (SETEQ (FlagEQ)) -> (MOVLconst [1]) 1251 (SETEQ (FlagLT_ULT)) -> (MOVLconst [0]) 1252 (SETEQ (FlagLT_UGT)) -> (MOVLconst [0]) 1253 (SETEQ (FlagGT_ULT)) -> (MOVLconst [0]) 1254 (SETEQ (FlagGT_UGT)) -> (MOVLconst [0]) 1255 1256 (SETNE (FlagEQ)) -> (MOVLconst [0]) 1257 (SETNE (FlagLT_ULT)) -> (MOVLconst [1]) 1258 (SETNE (FlagLT_UGT)) -> (MOVLconst [1]) 1259 (SETNE (FlagGT_ULT)) -> (MOVLconst [1]) 1260 (SETNE (FlagGT_UGT)) -> (MOVLconst [1]) 1261 1262 (SETL (FlagEQ)) -> (MOVLconst [0]) 1263 (SETL (FlagLT_ULT)) -> (MOVLconst [1]) 1264 (SETL (FlagLT_UGT)) -> (MOVLconst [1]) 1265 (SETL (FlagGT_ULT)) -> (MOVLconst [0]) 1266 (SETL (FlagGT_UGT)) -> (MOVLconst [0]) 1267 1268 (SETLE (FlagEQ)) -> (MOVLconst [1]) 1269 (SETLE (FlagLT_ULT)) -> (MOVLconst [1]) 1270 (SETLE (FlagLT_UGT)) -> (MOVLconst [1]) 1271 (SETLE (FlagGT_ULT)) -> (MOVLconst [0]) 1272 (SETLE (FlagGT_UGT)) -> (MOVLconst [0]) 1273 1274 (SETG (FlagEQ)) -> (MOVLconst [0]) 1275 (SETG (FlagLT_ULT)) -> (MOVLconst [0]) 1276 (SETG (FlagLT_UGT)) -> (MOVLconst [0]) 1277 (SETG (FlagGT_ULT)) -> (MOVLconst [1]) 1278 (SETG (FlagGT_UGT)) -> (MOVLconst [1]) 1279 1280 (SETGE (FlagEQ)) -> (MOVLconst [1]) 1281 (SETGE (FlagLT_ULT)) -> (MOVLconst [0]) 1282 (SETGE (FlagLT_UGT)) -> (MOVLconst [0]) 1283 (SETGE (FlagGT_ULT)) -> (MOVLconst [1]) 1284 (SETGE (FlagGT_UGT)) -> (MOVLconst [1]) 1285 1286 (SETB (FlagEQ)) -> (MOVLconst [0]) 1287 (SETB (FlagLT_ULT)) -> (MOVLconst [1]) 1288 (SETB (FlagLT_UGT)) -> (MOVLconst [0]) 1289 (SETB (FlagGT_ULT)) -> (MOVLconst [1]) 1290 (SETB (FlagGT_UGT)) -> (MOVLconst [0]) 1291 1292 (SETBE (FlagEQ)) -> (MOVLconst [1]) 1293 (SETBE (FlagLT_ULT)) -> (MOVLconst [1]) 1294 (SETBE (FlagLT_UGT)) -> (MOVLconst [0]) 1295 (SETBE (FlagGT_ULT)) -> (MOVLconst [1]) 1296 (SETBE (FlagGT_UGT)) -> (MOVLconst [0]) 1297 1298 (SETA (FlagEQ)) -> (MOVLconst [0]) 1299 (SETA (FlagLT_ULT)) -> (MOVLconst [0]) 1300 (SETA (FlagLT_UGT)) -> (MOVLconst [1]) 1301 (SETA (FlagGT_ULT)) -> (MOVLconst [0]) 1302 (SETA (FlagGT_UGT)) -> (MOVLconst [1]) 1303 1304 (SETAE (FlagEQ)) -> (MOVLconst [1]) 1305 (SETAE (FlagLT_ULT)) -> (MOVLconst [0]) 1306 (SETAE (FlagLT_UGT)) -> (MOVLconst [1]) 1307 (SETAE (FlagGT_ULT)) -> (MOVLconst [0]) 1308 (SETAE (FlagGT_UGT)) -> (MOVLconst [1]) 1309 1310 // Remove redundant *const ops 1311 (ADDQconst [0] x) -> x 1312 (ADDLconst [c] x) && int32(c)==0 -> x 1313 (SUBQconst [0] x) -> x 1314 (SUBLconst [c] x) && int32(c) == 0 -> x 1315 (ANDQconst [0] _) -> (MOVQconst [0]) 1316 (ANDLconst [c] _) && int32(c)==0 -> (MOVLconst [0]) 1317 (ANDQconst [-1] x) -> x 1318 (ANDLconst [c] x) && int32(c)==-1 -> x 1319 (ORQconst [0] x) -> x 1320 (ORLconst [c] x) && int32(c)==0 -> x 1321 (ORQconst [-1] _) -> (MOVQconst [-1]) 1322 (ORLconst [c] _) && int32(c)==-1 -> (MOVLconst [-1]) 1323 (XORQconst [0] x) -> x 1324 (XORLconst [c] x) && int32(c)==0 -> x 1325 // TODO: since we got rid of the W/B versions, we might miss 1326 // things like (ANDLconst [0x100] x) which were formerly 1327 // (ANDBconst [0] x). Probably doesn't happen very often. 1328 // If we cared, we might do: 1329 // (ANDLconst <t> [c] x) && t.Size()==1 && int8(x)==0 -> (MOVLconst [0]) 1330 1331 // Convert constant subtracts to constant adds 1332 (SUBQconst [c] x) && c != -(1<<31) -> (ADDQconst [-c] x) 1333 (SUBLconst [c] x) -> (ADDLconst [int64(int32(-c))] x) 1334 1335 // generic constant folding 1336 // TODO: more of this 1337 (ADDQconst [c] (MOVQconst [d])) -> (MOVQconst [c+d]) 1338 (ADDLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c+d))]) 1339 (ADDQconst [c] (ADDQconst [d] x)) && is32Bit(c+d) -> (ADDQconst [c+d] x) 1340 (ADDLconst [c] (ADDLconst [d] x)) -> (ADDLconst [int64(int32(c+d))] x) 1341 (SUBQconst (MOVQconst [d]) [c]) -> (MOVQconst [d-c]) 1342 (SUBQconst (SUBQconst x [d]) [c]) && is32Bit(-c-d) -> (ADDQconst [-c-d] x) 1343 (SARQconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1344 (SARLconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1345 (SARWconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1346 (SARBconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1347 (NEGQ (MOVQconst [c])) -> (MOVQconst [-c]) 1348 (NEGL (MOVLconst [c])) -> (MOVLconst [int64(int32(-c))]) 1349 (MULQconst [c] (MOVQconst [d])) -> (MOVQconst [c*d]) 1350 (MULLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c*d))]) 1351 (ANDQconst [c] (MOVQconst [d])) -> (MOVQconst [c&d]) 1352 (ANDLconst [c] (MOVLconst [d])) -> (MOVLconst [c&d]) 1353 (ORQconst [c] (MOVQconst [d])) -> (MOVQconst [c|d]) 1354 (ORLconst [c] (MOVLconst [d])) -> (MOVLconst [c|d]) 1355 (XORQconst [c] (MOVQconst [d])) -> (MOVQconst [c^d]) 1356 (XORLconst [c] (MOVLconst [d])) -> (MOVLconst [c^d]) 1357 (NOTQ (MOVQconst [c])) -> (MOVQconst [^c]) 1358 (NOTL (MOVLconst [c])) -> (MOVLconst [^c]) 1359 1360 // generic simplifications 1361 // TODO: more of this 1362 (ADDQ x (NEGQ y)) -> (SUBQ x y) 1363 (ADDL x (NEGL y)) -> (SUBL x y) 1364 (SUBQ x x) -> (MOVQconst [0]) 1365 (SUBL x x) -> (MOVLconst [0]) 1366 (ANDQ x x) -> x 1367 (ANDL x x) -> x 1368 (ORQ x x) -> x 1369 (ORL x x) -> x 1370 (XORQ x x) -> (MOVQconst [0]) 1371 (XORL x x) -> (MOVLconst [0]) 1372 (NEGQ (ADDQconst [c] (NEGQ x))) && c != -(1<<31) -> (ADDQconst [-c] x) 1373 1374 // checking AND against 0. 1375 (CMPQconst (ANDQ x y) [0]) -> (TESTQ x y) 1376 (CMPLconst (ANDL x y) [0]) -> (TESTL x y) 1377 (CMPWconst (ANDL x y) [0]) -> (TESTW x y) 1378 (CMPBconst (ANDL x y) [0]) -> (TESTB x y) 1379 (CMPQconst (ANDQconst [c] x) [0]) -> (TESTQconst [c] x) 1380 (CMPLconst (ANDLconst [c] x) [0]) -> (TESTLconst [c] x) 1381 (CMPWconst (ANDLconst [c] x) [0]) -> (TESTWconst [int64(int16(c))] x) 1382 (CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x) 1383 1384 // Convert TESTx to TESTxconst if possible. 1385 (TESTQ (MOVQconst [c]) x) && is32Bit(c) -> (TESTQconst [c] x) 1386 (TESTL (MOVLconst [c]) x) -> (TESTLconst [c] x) 1387 (TESTW (MOVLconst [c]) x) -> (TESTWconst [c] x) 1388 (TESTB (MOVLconst [c]) x) -> (TESTBconst [c] x) 1389 1390 // TEST %reg,%reg is shorter than CMP 1391 (CMPQconst x [0]) -> (TESTQ x x) 1392 (CMPLconst x [0]) -> (TESTL x x) 1393 (CMPWconst x [0]) -> (TESTW x x) 1394 (CMPBconst x [0]) -> (TESTB x x) 1395 1396 // Combining byte loads into larger (unaligned) loads. 1397 // There are many ways these combinations could occur. This is 1398 // designed to match the way encoding/binary.LittleEndian does it. 1399 1400 // Little-endian loads 1401 1402 (ORL x0:(MOVBload [i0] {s} p mem) 1403 sh:(SHLLconst [8] x1:(MOVBload [i1] {s} p mem))) 1404 && i1 == i0+1 1405 && x0.Uses == 1 1406 && x1.Uses == 1 1407 && sh.Uses == 1 1408 && mergePoint(b,x0,x1) != nil 1409 && clobber(x0) 1410 && clobber(x1) 1411 && clobber(sh) 1412 -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 1413 1414 (ORQ x0:(MOVBload [i0] {s} p mem) 1415 sh:(SHLQconst [8] x1:(MOVBload [i1] {s} p mem))) 1416 && i1 == i0+1 1417 && x0.Uses == 1 1418 && x1.Uses == 1 1419 && sh.Uses == 1 1420 && mergePoint(b,x0,x1) != nil 1421 && clobber(x0) 1422 && clobber(x1) 1423 && clobber(sh) 1424 -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 1425 1426 (ORL x0:(MOVWload [i0] {s} p mem) 1427 sh:(SHLLconst [16] x1:(MOVWload [i1] {s} p mem))) 1428 && i1 == i0+2 1429 && x0.Uses == 1 1430 && x1.Uses == 1 1431 && sh.Uses == 1 1432 && mergePoint(b,x0,x1) != nil 1433 && clobber(x0) 1434 && clobber(x1) 1435 && clobber(sh) 1436 -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem) 1437 1438 (ORQ x0:(MOVWload [i0] {s} p mem) 1439 sh:(SHLQconst [16] x1:(MOVWload [i1] {s} p mem))) 1440 && i1 == i0+2 1441 && x0.Uses == 1 1442 && x1.Uses == 1 1443 && sh.Uses == 1 1444 && mergePoint(b,x0,x1) != nil 1445 && clobber(x0) 1446 && clobber(x1) 1447 && clobber(sh) 1448 -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem) 1449 1450 (ORQ x0:(MOVLload [i0] {s} p mem) 1451 sh:(SHLQconst [32] x1:(MOVLload [i1] {s} p mem))) 1452 && i1 == i0+4 1453 && x0.Uses == 1 1454 && x1.Uses == 1 1455 && sh.Uses == 1 1456 && mergePoint(b,x0,x1) != nil 1457 && clobber(x0) 1458 && clobber(x1) 1459 && clobber(sh) 1460 -> @mergePoint(b,x0,x1) (MOVQload [i0] {s} p mem) 1461 1462 (ORL 1463 s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem)) 1464 or:(ORL 1465 s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem)) 1466 y)) 1467 && i1 == i0+1 1468 && j1 == j0+8 1469 && j0 % 16 == 0 1470 && x0.Uses == 1 1471 && x1.Uses == 1 1472 && s0.Uses == 1 1473 && s1.Uses == 1 1474 && or.Uses == 1 1475 && mergePoint(b,x0,x1) != nil 1476 && clobber(x0) 1477 && clobber(x1) 1478 && clobber(s0) 1479 && clobber(s1) 1480 && clobber(or) 1481 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y) 1482 1483 (ORQ 1484 s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem)) 1485 or:(ORQ 1486 s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem)) 1487 y)) 1488 && i1 == i0+1 1489 && j1 == j0+8 1490 && j0 % 16 == 0 1491 && x0.Uses == 1 1492 && x1.Uses == 1 1493 && s0.Uses == 1 1494 && s1.Uses == 1 1495 && or.Uses == 1 1496 && mergePoint(b,x0,x1) != nil 1497 && clobber(x0) 1498 && clobber(x1) 1499 && clobber(s0) 1500 && clobber(s1) 1501 && clobber(or) 1502 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y) 1503 1504 (ORQ 1505 s1:(SHLQconst [j1] x1:(MOVWload [i1] {s} p mem)) 1506 or:(ORQ 1507 s0:(SHLQconst [j0] x0:(MOVWload [i0] {s} p mem)) 1508 y)) 1509 && i1 == i0+2 1510 && j1 == j0+16 1511 && j0 % 32 == 0 1512 && x0.Uses == 1 1513 && x1.Uses == 1 1514 && s0.Uses == 1 1515 && s1.Uses == 1 1516 && or.Uses == 1 1517 && mergePoint(b,x0,x1) != nil 1518 && clobber(x0) 1519 && clobber(x1) 1520 && clobber(s0) 1521 && clobber(s1) 1522 && clobber(or) 1523 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLload [i0] {s} p mem)) y) 1524 1525 // Little-endian indexed loads 1526 1527 (ORL x0:(MOVBloadidx1 [i0] {s} p idx mem) 1528 sh:(SHLLconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem))) 1529 && i1 == i0+1 1530 && x0.Uses == 1 1531 && x1.Uses == 1 1532 && sh.Uses == 1 1533 && mergePoint(b,x0,x1) != nil 1534 && clobber(x0) 1535 && clobber(x1) 1536 && clobber(sh) 1537 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem) 1538 1539 (ORQ x0:(MOVBloadidx1 [i0] {s} p idx mem) 1540 sh:(SHLQconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem))) 1541 && i1 == i0+1 1542 && x0.Uses == 1 1543 && x1.Uses == 1 1544 && sh.Uses == 1 1545 && mergePoint(b,x0,x1) != nil 1546 && clobber(x0) 1547 && clobber(x1) 1548 && clobber(sh) 1549 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem) 1550 1551 (ORL x0:(MOVWloadidx1 [i0] {s} p idx mem) 1552 sh:(SHLLconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1553 && i1 == i0+2 1554 && x0.Uses == 1 1555 && x1.Uses == 1 1556 && sh.Uses == 1 1557 && mergePoint(b,x0,x1) != nil 1558 && clobber(x0) 1559 && clobber(x1) 1560 && clobber(sh) 1561 -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem) 1562 1563 (ORQ x0:(MOVWloadidx1 [i0] {s} p idx mem) 1564 sh:(SHLQconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1565 && i1 == i0+2 1566 && x0.Uses == 1 1567 && x1.Uses == 1 1568 && sh.Uses == 1 1569 && mergePoint(b,x0,x1) != nil 1570 && clobber(x0) 1571 && clobber(x1) 1572 && clobber(sh) 1573 -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem) 1574 1575 (ORQ x0:(MOVLloadidx1 [i0] {s} p idx mem) 1576 sh:(SHLQconst [32] x1:(MOVLloadidx1 [i1] {s} p idx mem))) 1577 && i1 == i0+4 1578 && x0.Uses == 1 1579 && x1.Uses == 1 1580 && sh.Uses == 1 1581 && mergePoint(b,x0,x1) != nil 1582 && clobber(x0) 1583 && clobber(x1) 1584 && clobber(sh) 1585 -> @mergePoint(b,x0,x1) (MOVQloadidx1 [i0] {s} p idx mem) 1586 1587 (ORL 1588 s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1589 or:(ORL 1590 s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1591 y)) 1592 && i1 == i0+1 1593 && j1 == j0+8 1594 && j0 % 16 == 0 1595 && x0.Uses == 1 1596 && x1.Uses == 1 1597 && s0.Uses == 1 1598 && s1.Uses == 1 1599 && or.Uses == 1 1600 && mergePoint(b,x0,x1) != nil 1601 && clobber(x0) 1602 && clobber(x1) 1603 && clobber(s0) 1604 && clobber(s1) 1605 && clobber(or) 1606 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y) 1607 1608 (ORQ 1609 s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1610 or:(ORQ 1611 s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1612 y)) 1613 && i1 == i0+1 1614 && j1 == j0+8 1615 && j0 % 16 == 0 1616 && x0.Uses == 1 1617 && x1.Uses == 1 1618 && s0.Uses == 1 1619 && s1.Uses == 1 1620 && or.Uses == 1 1621 && mergePoint(b,x0,x1) != nil 1622 && clobber(x0) 1623 && clobber(x1) 1624 && clobber(s0) 1625 && clobber(s1) 1626 && clobber(or) 1627 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y) 1628 1629 (ORQ 1630 s1:(SHLQconst [j1] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1631 or:(ORQ 1632 s0:(SHLQconst [j0] x0:(MOVWloadidx1 [i0] {s} p idx mem)) 1633 y)) 1634 && i1 == i0+2 1635 && j1 == j0+16 1636 && j0 % 32 == 0 1637 && x0.Uses == 1 1638 && x1.Uses == 1 1639 && s0.Uses == 1 1640 && s1.Uses == 1 1641 && or.Uses == 1 1642 && mergePoint(b,x0,x1) != nil 1643 && clobber(x0) 1644 && clobber(x1) 1645 && clobber(s0) 1646 && clobber(s1) 1647 && clobber(or) 1648 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLloadidx1 [i0] {s} p idx mem)) y) 1649 1650 // Big-endian loads 1651 1652 (ORL 1653 x1:(MOVBload [i1] {s} p mem) 1654 sh:(SHLLconst [8] x0:(MOVBload [i0] {s} p mem))) 1655 && i1 == i0+1 1656 && x0.Uses == 1 1657 && x1.Uses == 1 1658 && sh.Uses == 1 1659 && mergePoint(b,x0,x1) != nil 1660 && clobber(x0) 1661 && clobber(x1) 1662 && clobber(sh) 1663 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem)) 1664 1665 (ORQ 1666 x1:(MOVBload [i1] {s} p mem) 1667 sh:(SHLQconst [8] x0:(MOVBload [i0] {s} p mem))) 1668 && i1 == i0+1 1669 && x0.Uses == 1 1670 && x1.Uses == 1 1671 && sh.Uses == 1 1672 && mergePoint(b,x0,x1) != nil 1673 && clobber(x0) 1674 && clobber(x1) 1675 && clobber(sh) 1676 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem)) 1677 1678 (ORL 1679 r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)) 1680 sh:(SHLLconst [16] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))) 1681 && i1 == i0+2 1682 && x0.Uses == 1 1683 && x1.Uses == 1 1684 && r0.Uses == 1 1685 && r1.Uses == 1 1686 && sh.Uses == 1 1687 && mergePoint(b,x0,x1) != nil 1688 && clobber(x0) 1689 && clobber(x1) 1690 && clobber(r0) 1691 && clobber(r1) 1692 && clobber(sh) 1693 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem)) 1694 1695 (ORQ 1696 r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)) 1697 sh:(SHLQconst [16] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))) 1698 && i1 == i0+2 1699 && x0.Uses == 1 1700 && x1.Uses == 1 1701 && r0.Uses == 1 1702 && r1.Uses == 1 1703 && sh.Uses == 1 1704 && mergePoint(b,x0,x1) != nil 1705 && clobber(x0) 1706 && clobber(x1) 1707 && clobber(r0) 1708 && clobber(r1) 1709 && clobber(sh) 1710 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem)) 1711 1712 (ORQ 1713 r1:(BSWAPL x1:(MOVLload [i1] {s} p mem)) 1714 sh:(SHLQconst [32] r0:(BSWAPL x0:(MOVLload [i0] {s} p mem)))) 1715 && i1 == i0+4 1716 && x0.Uses == 1 1717 && x1.Uses == 1 1718 && r0.Uses == 1 1719 && r1.Uses == 1 1720 && sh.Uses == 1 1721 && mergePoint(b,x0,x1) != nil 1722 && clobber(x0) 1723 && clobber(x1) 1724 && clobber(r0) 1725 && clobber(r1) 1726 && clobber(sh) 1727 -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQload [i0] {s} p mem)) 1728 1729 (ORL 1730 s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem)) 1731 or:(ORL 1732 s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem)) 1733 y)) 1734 && i1 == i0+1 1735 && j1 == j0-8 1736 && j1 % 16 == 0 1737 && x0.Uses == 1 1738 && x1.Uses == 1 1739 && s0.Uses == 1 1740 && s1.Uses == 1 1741 && or.Uses == 1 1742 && mergePoint(b,x0,x1) != nil 1743 && clobber(x0) 1744 && clobber(x1) 1745 && clobber(s0) 1746 && clobber(s1) 1747 && clobber(or) 1748 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <types.UInt16> [8] (MOVWload [i0] {s} p mem))) y) 1749 1750 (ORQ 1751 s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem)) 1752 or:(ORQ 1753 s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem)) 1754 y)) 1755 && i1 == i0+1 1756 && j1 == j0-8 1757 && j1 % 16 == 0 1758 && x0.Uses == 1 1759 && x1.Uses == 1 1760 && s0.Uses == 1 1761 && s1.Uses == 1 1762 && or.Uses == 1 1763 && mergePoint(b,x0,x1) != nil 1764 && clobber(x0) 1765 && clobber(x1) 1766 && clobber(s0) 1767 && clobber(s1) 1768 && clobber(or) 1769 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <types.UInt16> [8] (MOVWload [i0] {s} p mem))) y) 1770 1771 (ORQ 1772 s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem))) 1773 or:(ORQ 1774 s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem))) 1775 y)) 1776 && i1 == i0+2 1777 && j1 == j0-16 1778 && j1 % 32 == 0 1779 && x0.Uses == 1 1780 && x1.Uses == 1 1781 && r0.Uses == 1 1782 && r1.Uses == 1 1783 && s0.Uses == 1 1784 && s1.Uses == 1 1785 && or.Uses == 1 1786 && mergePoint(b,x0,x1) != nil 1787 && clobber(x0) 1788 && clobber(x1) 1789 && clobber(r0) 1790 && clobber(r1) 1791 && clobber(s0) 1792 && clobber(s1) 1793 && clobber(or) 1794 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <types.UInt32> (MOVLload [i0] {s} p mem))) y) 1795 1796 // Big-endian indexed loads 1797 1798 (ORL 1799 x1:(MOVBloadidx1 [i1] {s} p idx mem) 1800 sh:(SHLLconst [8] x0:(MOVBloadidx1 [i0] {s} p idx mem))) 1801 && i1 == i0+1 1802 && x0.Uses == 1 1803 && x1.Uses == 1 1804 && sh.Uses == 1 1805 && mergePoint(b,x0,x1) != nil 1806 && clobber(x0) 1807 && clobber(x1) 1808 && clobber(sh) 1809 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem)) 1810 1811 (ORQ 1812 x1:(MOVBloadidx1 [i1] {s} p idx mem) 1813 sh:(SHLQconst [8] x0:(MOVBloadidx1 [i0] {s} p idx mem))) 1814 && i1 == i0+1 1815 && x0.Uses == 1 1816 && x1.Uses == 1 1817 && sh.Uses == 1 1818 && mergePoint(b,x0,x1) != nil 1819 && clobber(x0) 1820 && clobber(x1) 1821 && clobber(sh) 1822 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem)) 1823 1824 (ORL 1825 r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1826 sh:(SHLLconst [16] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))) 1827 && i1 == i0+2 1828 && x0.Uses == 1 1829 && x1.Uses == 1 1830 && r0.Uses == 1 1831 && r1.Uses == 1 1832 && sh.Uses == 1 1833 && mergePoint(b,x0,x1) != nil 1834 && clobber(x0) 1835 && clobber(x1) 1836 && clobber(r0) 1837 && clobber(r1) 1838 && clobber(sh) 1839 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem)) 1840 1841 (ORQ 1842 r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1843 sh:(SHLQconst [16] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))) 1844 && i1 == i0+2 1845 && x0.Uses == 1 1846 && x1.Uses == 1 1847 && r0.Uses == 1 1848 && r1.Uses == 1 1849 && sh.Uses == 1 1850 && mergePoint(b,x0,x1) != nil 1851 && clobber(x0) 1852 && clobber(x1) 1853 && clobber(r0) 1854 && clobber(r1) 1855 && clobber(sh) 1856 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem)) 1857 1858 (ORQ 1859 r1:(BSWAPL x1:(MOVLloadidx1 [i1] {s} p idx mem)) 1860 sh:(SHLQconst [32] r0:(BSWAPL x0:(MOVLloadidx1 [i0] {s} p idx mem)))) 1861 && i1 == i0+4 1862 && x0.Uses == 1 1863 && x1.Uses == 1 1864 && r0.Uses == 1 1865 && r1.Uses == 1 1866 && sh.Uses == 1 1867 && mergePoint(b,x0,x1) != nil 1868 && clobber(x0) 1869 && clobber(x1) 1870 && clobber(r0) 1871 && clobber(r1) 1872 && clobber(sh) 1873 -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQloadidx1 [i0] {s} p idx mem)) 1874 1875 (ORL 1876 s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1877 or:(ORL 1878 s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1879 y)) 1880 && i1 == i0+1 1881 && j1 == j0-8 1882 && j1 % 16 == 0 1883 && x0.Uses == 1 1884 && x1.Uses == 1 1885 && s0.Uses == 1 1886 && s1.Uses == 1 1887 && or.Uses == 1 1888 && mergePoint(b,x0,x1) != nil 1889 && clobber(x0) 1890 && clobber(x1) 1891 && clobber(s0) 1892 && clobber(s1) 1893 && clobber(or) 1894 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <types.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y) 1895 1896 (ORQ 1897 s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1898 or:(ORQ 1899 s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1900 y)) 1901 && i1 == i0+1 1902 && j1 == j0-8 1903 && j1 % 16 == 0 1904 && x0.Uses == 1 1905 && x1.Uses == 1 1906 && s0.Uses == 1 1907 && s1.Uses == 1 1908 && or.Uses == 1 1909 && mergePoint(b,x0,x1) != nil 1910 && clobber(x0) 1911 && clobber(x1) 1912 && clobber(s0) 1913 && clobber(s1) 1914 && clobber(or) 1915 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <types.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y) 1916 1917 (ORQ 1918 s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem))) 1919 or:(ORQ 1920 s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1921 y)) 1922 && i1 == i0+2 1923 && j1 == j0-16 1924 && j1 % 32 == 0 1925 && x0.Uses == 1 1926 && x1.Uses == 1 1927 && r0.Uses == 1 1928 && r1.Uses == 1 1929 && s0.Uses == 1 1930 && s1.Uses == 1 1931 && or.Uses == 1 1932 && mergePoint(b,x0,x1) != nil 1933 && clobber(x0) 1934 && clobber(x1) 1935 && clobber(r0) 1936 && clobber(r1) 1937 && clobber(s0) 1938 && clobber(s1) 1939 && clobber(or) 1940 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <types.UInt32> (MOVLloadidx1 [i0] {s} p idx mem))) y) 1941 1942 // Combine 2 byte stores + shift into rolw 8 + word store 1943 (MOVBstore [i] {s} p w 1944 x0:(MOVBstore [i-1] {s} p (SHRWconst [8] w) mem)) 1945 && x0.Uses == 1 1946 && clobber(x0) 1947 -> (MOVWstore [i-1] {s} p (ROLWconst <w.Type> [8] w) mem) 1948 1949 (MOVBstoreidx1 [i] {s} p idx w 1950 x0:(MOVBstoreidx1 [i-1] {s} p idx (SHRWconst [8] w) mem)) 1951 && x0.Uses == 1 1952 && clobber(x0) 1953 -> (MOVWstoreidx1 [i-1] {s} p idx (ROLWconst <w.Type> [8] w) mem) 1954 1955 // Combine stores + shifts into bswap and larger (unaligned) stores 1956 (MOVBstore [i] {s} p w 1957 x2:(MOVBstore [i-1] {s} p (SHRLconst [8] w) 1958 x1:(MOVBstore [i-2] {s} p (SHRLconst [16] w) 1959 x0:(MOVBstore [i-3] {s} p (SHRLconst [24] w) mem)))) 1960 && x0.Uses == 1 1961 && x1.Uses == 1 1962 && x2.Uses == 1 1963 && clobber(x0) 1964 && clobber(x1) 1965 && clobber(x2) 1966 -> (MOVLstore [i-3] {s} p (BSWAPL <w.Type> w) mem) 1967 1968 (MOVBstoreidx1 [i] {s} p idx w 1969 x2:(MOVBstoreidx1 [i-1] {s} p idx (SHRLconst [8] w) 1970 x1:(MOVBstoreidx1 [i-2] {s} p idx (SHRLconst [16] w) 1971 x0:(MOVBstoreidx1 [i-3] {s} p idx (SHRLconst [24] w) mem)))) 1972 && x0.Uses == 1 1973 && x1.Uses == 1 1974 && x2.Uses == 1 1975 && clobber(x0) 1976 && clobber(x1) 1977 && clobber(x2) 1978 -> (MOVLstoreidx1 [i-3] {s} p idx (BSWAPL <w.Type> w) mem) 1979 1980 (MOVBstore [i] {s} p w 1981 x6:(MOVBstore [i-1] {s} p (SHRQconst [8] w) 1982 x5:(MOVBstore [i-2] {s} p (SHRQconst [16] w) 1983 x4:(MOVBstore [i-3] {s} p (SHRQconst [24] w) 1984 x3:(MOVBstore [i-4] {s} p (SHRQconst [32] w) 1985 x2:(MOVBstore [i-5] {s} p (SHRQconst [40] w) 1986 x1:(MOVBstore [i-6] {s} p (SHRQconst [48] w) 1987 x0:(MOVBstore [i-7] {s} p (SHRQconst [56] w) mem)))))))) 1988 && x0.Uses == 1 1989 && x1.Uses == 1 1990 && x2.Uses == 1 1991 && x3.Uses == 1 1992 && x4.Uses == 1 1993 && x5.Uses == 1 1994 && x6.Uses == 1 1995 && clobber(x0) 1996 && clobber(x1) 1997 && clobber(x2) 1998 && clobber(x3) 1999 && clobber(x4) 2000 && clobber(x5) 2001 && clobber(x6) 2002 -> (MOVQstore [i-7] {s} p (BSWAPQ <w.Type> w) mem) 2003 2004 (MOVBstoreidx1 [i] {s} p idx w 2005 x6:(MOVBstoreidx1 [i-1] {s} p idx (SHRQconst [8] w) 2006 x5:(MOVBstoreidx1 [i-2] {s} p idx (SHRQconst [16] w) 2007 x4:(MOVBstoreidx1 [i-3] {s} p idx (SHRQconst [24] w) 2008 x3:(MOVBstoreidx1 [i-4] {s} p idx (SHRQconst [32] w) 2009 x2:(MOVBstoreidx1 [i-5] {s} p idx (SHRQconst [40] w) 2010 x1:(MOVBstoreidx1 [i-6] {s} p idx (SHRQconst [48] w) 2011 x0:(MOVBstoreidx1 [i-7] {s} p idx (SHRQconst [56] w) mem)))))))) 2012 && x0.Uses == 1 2013 && x1.Uses == 1 2014 && x2.Uses == 1 2015 && x3.Uses == 1 2016 && x4.Uses == 1 2017 && x5.Uses == 1 2018 && x6.Uses == 1 2019 && clobber(x0) 2020 && clobber(x1) 2021 && clobber(x2) 2022 && clobber(x3) 2023 && clobber(x4) 2024 && clobber(x5) 2025 && clobber(x6) 2026 -> (MOVQstoreidx1 [i-7] {s} p idx (BSWAPQ <w.Type> w) mem) 2027 2028 // Combine constant stores into larger (unaligned) stores. 2029 (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem)) 2030 && x.Uses == 1 2031 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 2032 && clobber(x) 2033 -> (MOVWstoreconst [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p mem) 2034 (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem)) 2035 && x.Uses == 1 2036 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2037 && clobber(x) 2038 -> (MOVLstoreconst [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p mem) 2039 (MOVLstoreconst [c] {s} p x:(MOVLstoreconst [a] {s} p mem)) 2040 && x.Uses == 1 2041 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2042 && clobber(x) 2043 -> (MOVQstore [ValAndOff(a).Off()] {s} p (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2044 2045 (MOVBstoreconstidx1 [c] {s} p i x:(MOVBstoreconstidx1 [a] {s} p i mem)) 2046 && x.Uses == 1 2047 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 2048 && clobber(x) 2049 -> (MOVWstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p i mem) 2050 (MOVWstoreconstidx1 [c] {s} p i x:(MOVWstoreconstidx1 [a] {s} p i mem)) 2051 && x.Uses == 1 2052 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2053 && clobber(x) 2054 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p i mem) 2055 (MOVLstoreconstidx1 [c] {s} p i x:(MOVLstoreconstidx1 [a] {s} p i mem)) 2056 && x.Uses == 1 2057 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2058 && clobber(x) 2059 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p i (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2060 2061 (MOVWstoreconstidx2 [c] {s} p i x:(MOVWstoreconstidx2 [a] {s} p i mem)) 2062 && x.Uses == 1 2063 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2064 && clobber(x) 2065 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p (SHLQconst <i.Type> [1] i) mem) 2066 (MOVLstoreconstidx4 [c] {s} p i x:(MOVLstoreconstidx4 [a] {s} p i mem)) 2067 && x.Uses == 1 2068 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2069 && clobber(x) 2070 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p (SHLQconst <i.Type> [2] i) (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2071 2072 // Combine stores into larger (unaligned) stores. 2073 (MOVBstore [i] {s} p (SHRQconst [8] w) x:(MOVBstore [i-1] {s} p w mem)) 2074 && x.Uses == 1 2075 && clobber(x) 2076 -> (MOVWstore [i-1] {s} p w mem) 2077 (MOVBstore [i] {s} p (SHRQconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SHRQconst [j-8] w) mem)) 2078 && x.Uses == 1 2079 && clobber(x) 2080 -> (MOVWstore [i-1] {s} p w0 mem) 2081 (MOVWstore [i] {s} p (SHRQconst [16] w) x:(MOVWstore [i-2] {s} p w mem)) 2082 && x.Uses == 1 2083 && clobber(x) 2084 -> (MOVLstore [i-2] {s} p w mem) 2085 (MOVWstore [i] {s} p (SHRQconst [j] w) x:(MOVWstore [i-2] {s} p w0:(SHRQconst [j-16] w) mem)) 2086 && x.Uses == 1 2087 && clobber(x) 2088 -> (MOVLstore [i-2] {s} p w0 mem) 2089 (MOVLstore [i] {s} p (SHRQconst [32] w) x:(MOVLstore [i-4] {s} p w mem)) 2090 && x.Uses == 1 2091 && clobber(x) 2092 -> (MOVQstore [i-4] {s} p w mem) 2093 (MOVLstore [i] {s} p (SHRQconst [j] w) x:(MOVLstore [i-4] {s} p w0:(SHRQconst [j-32] w) mem)) 2094 && x.Uses == 1 2095 && clobber(x) 2096 -> (MOVQstore [i-4] {s} p w0 mem) 2097 2098 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [8] w) x:(MOVBstoreidx1 [i-1] {s} p idx w mem)) 2099 && x.Uses == 1 2100 && clobber(x) 2101 -> (MOVWstoreidx1 [i-1] {s} p idx w mem) 2102 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVBstoreidx1 [i-1] {s} p idx w0:(SHRQconst [j-8] w) mem)) 2103 && x.Uses == 1 2104 && clobber(x) 2105 -> (MOVWstoreidx1 [i-1] {s} p idx w0 mem) 2106 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx1 [i-2] {s} p idx w mem)) 2107 && x.Uses == 1 2108 && clobber(x) 2109 -> (MOVLstoreidx1 [i-2] {s} p idx w mem) 2110 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx1 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 2111 && x.Uses == 1 2112 && clobber(x) 2113 -> (MOVLstoreidx1 [i-2] {s} p idx w0 mem) 2114 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx1 [i-4] {s} p idx w mem)) 2115 && x.Uses == 1 2116 && clobber(x) 2117 -> (MOVQstoreidx1 [i-4] {s} p idx w mem) 2118 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx1 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 2119 && x.Uses == 1 2120 && clobber(x) 2121 -> (MOVQstoreidx1 [i-4] {s} p idx w0 mem) 2122 2123 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx2 [i-2] {s} p idx w mem)) 2124 && x.Uses == 1 2125 && clobber(x) 2126 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w mem) 2127 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx2 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 2128 && x.Uses == 1 2129 && clobber(x) 2130 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w0 mem) 2131 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx4 [i-4] {s} p idx w mem)) 2132 && x.Uses == 1 2133 && clobber(x) 2134 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w mem) 2135 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx4 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 2136 && x.Uses == 1 2137 && clobber(x) 2138 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w0 mem) 2139 2140 // amd64p32 rules 2141 // same as the rules above, but with 32 instead of 64 bit pointer arithmetic. 2142 // LEAQ,ADDQ -> LEAL,ADDL 2143 (ADDLconst [c] (LEAL [d] {s} x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 2144 (LEAL [c] {s} (ADDLconst [d] x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 2145 2146 (MOVQload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2147 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2148 (MOVLload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2149 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2150 (MOVWload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2151 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2152 (MOVBload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2153 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2154 2155 (MOVQstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2156 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2157 (MOVLstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2158 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2159 (MOVWstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2160 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2161 (MOVBstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2162 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2163 2164 (MOVQstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2165 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2166 (MOVLstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2167 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2168 (MOVWstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2169 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2170 (MOVBstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2171 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2172 2173 (MOVQload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 2174 (MOVLload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 2175 (MOVWload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 2176 (MOVBload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 2177 (MOVQstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 2178 (MOVLstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 2179 (MOVWstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 2180 (MOVBstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 2181 (MOVQstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2182 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2183 (MOVLstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2184 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2185 (MOVWstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2186 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2187 (MOVBstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2188 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2189 2190 // Merge load and op 2191 // TODO: add indexed variants? 2192 (ADDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDQmem x [off] {sym} ptr mem) 2193 (ADDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDLmem x [off] {sym} ptr mem) 2194 (SUBQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBQmem x [off] {sym} ptr mem) 2195 (SUBL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBLmem x [off] {sym} ptr mem) 2196 (ANDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDQmem x [off] {sym} ptr mem) 2197 (ANDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDLmem x [off] {sym} ptr mem) 2198 (ORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORQmem x [off] {sym} ptr mem) 2199 (ORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORLmem x [off] {sym} ptr mem) 2200 (XORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORQmem x [off] {sym} ptr mem) 2201 (XORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORLmem x [off] {sym} ptr mem) 2202 (ADDSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSDmem x [off] {sym} ptr mem) 2203 (ADDSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSSmem x [off] {sym} ptr mem) 2204 (SUBSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSDmem x [off] {sym} ptr mem) 2205 (SUBSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSSmem x [off] {sym} ptr mem) 2206 (MULSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSDmem x [off] {sym} ptr mem) 2207 (MULSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSSmem x [off] {sym} ptr mem) 2208 2209 // Merge ADDQconst and LEAQ into atomic loads. 2210 (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2211 (MOVQatomicload [off1+off2] {sym} ptr mem) 2212 (MOVLatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2213 (MOVLatomicload [off1+off2] {sym} ptr mem) 2214 (MOVQatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 2215 (MOVQatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 2216 (MOVLatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 2217 (MOVLatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 2218 2219 // Merge ADDQconst and LEAQ into atomic stores. 2220 (XCHGQ [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2221 (XCHGQ [off1+off2] {sym} val ptr mem) 2222 (XCHGQ [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 2223 (XCHGQ [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 2224 (XCHGL [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2225 (XCHGL [off1+off2] {sym} val ptr mem) 2226 (XCHGL [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 2227 (XCHGL [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 2228 2229 // Merge ADDQconst into atomic adds. 2230 // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions. 2231 (XADDQlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2232 (XADDQlock [off1+off2] {sym} val ptr mem) 2233 (XADDLlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2234 (XADDLlock [off1+off2] {sym} val ptr mem) 2235 2236 // Merge ADDQconst into atomic compare and swaps. 2237 // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions. 2238 (CMPXCHGQlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) -> 2239 (CMPXCHGQlock [off1+off2] {sym} ptr old new_ mem) 2240 (CMPXCHGLlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) -> 2241 (CMPXCHGLlock [off1+off2] {sym} ptr old new_ mem) 2242 2243 // We don't need the conditional move if we know the arg of BSF is not zero. 2244 (CMOVQEQ x _ (Select1 (BSFQ (ORQconst [c] _)))) && c != 0 -> x 2245 // Extension is unnecessary for trailing zeros. 2246 (BSFQ (ORQconst <t> [1<<8] (MOVBQZX x))) -> (BSFQ (ORQconst <t> [1<<8] x)) 2247 (BSFQ (ORQconst <t> [1<<16] (MOVWQZX x))) -> (BSFQ (ORQconst <t> [1<<16] x)) 2248 2249 // Redundant sign/zero extensions 2250 (MOVLQSX x:(MOVLQSX _)) -> x 2251 (MOVLQSX x:(MOVWQSX _)) -> x 2252 (MOVLQSX x:(MOVBQSX _)) -> x 2253 (MOVWQSX x:(MOVWQSX _)) -> x 2254 (MOVWQSX x:(MOVBQSX _)) -> x 2255 (MOVBQSX x:(MOVBQSX _)) -> x 2256 (MOVLQZX x:(MOVLQZX _)) -> x 2257 (MOVLQZX x:(MOVWQZX _)) -> x 2258 (MOVLQZX x:(MOVBQZX _)) -> x 2259 (MOVWQZX x:(MOVWQZX _)) -> x 2260 (MOVWQZX x:(MOVBQZX _)) -> x 2261 (MOVBQZX x:(MOVBQZX _)) -> x