github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/src/cmd/compile/internal/ssa/gen/AMD64.rules (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Lowering arithmetic 6 (Add64 x y) -> (ADDQ x y) 7 (AddPtr x y) && config.PtrSize == 8 -> (ADDQ x y) 8 (AddPtr x y) && config.PtrSize == 4 -> (ADDL x y) 9 (Add32 x y) -> (ADDL x y) 10 (Add16 x y) -> (ADDL x y) 11 (Add8 x y) -> (ADDL x y) 12 (Add32F x y) -> (ADDSS x y) 13 (Add64F x y) -> (ADDSD x y) 14 15 (Sub64 x y) -> (SUBQ x y) 16 (SubPtr x y) && config.PtrSize == 8 -> (SUBQ x y) 17 (SubPtr x y) && config.PtrSize == 4 -> (SUBL x y) 18 (Sub32 x y) -> (SUBL x y) 19 (Sub16 x y) -> (SUBL x y) 20 (Sub8 x y) -> (SUBL x y) 21 (Sub32F x y) -> (SUBSS x y) 22 (Sub64F x y) -> (SUBSD x y) 23 24 (Mul64 x y) -> (MULQ x y) 25 (Mul32 x y) -> (MULL x y) 26 (Mul16 x y) -> (MULL x y) 27 (Mul8 x y) -> (MULL x y) 28 (Mul32F x y) -> (MULSS x y) 29 (Mul64F x y) -> (MULSD x y) 30 31 (Div32F x y) -> (DIVSS x y) 32 (Div64F x y) -> (DIVSD x y) 33 34 (Div64 x y) -> (Select0 (DIVQ x y)) 35 (Div64u x y) -> (Select0 (DIVQU x y)) 36 (Div32 x y) -> (Select0 (DIVL x y)) 37 (Div32u x y) -> (Select0 (DIVLU x y)) 38 (Div16 x y) -> (Select0 (DIVW x y)) 39 (Div16u x y) -> (Select0 (DIVWU x y)) 40 (Div8 x y) -> (Select0 (DIVW (SignExt8to16 x) (SignExt8to16 y))) 41 (Div8u x y) -> (Select0 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y))) 42 43 (Hmul64 x y) -> (HMULQ x y) 44 (Hmul64u x y) -> (HMULQU x y) 45 (Hmul32 x y) -> (HMULL x y) 46 (Hmul32u x y) -> (HMULLU x y) 47 48 (Mul64uhilo x y) -> (MULQU2 x y) 49 (Div128u xhi xlo y) -> (DIVQU2 xhi xlo y) 50 51 (Avg64u x y) -> (AVGQU x y) 52 53 (Mod64 x y) -> (Select1 (DIVQ x y)) 54 (Mod64u x y) -> (Select1 (DIVQU x y)) 55 (Mod32 x y) -> (Select1 (DIVL x y)) 56 (Mod32u x y) -> (Select1 (DIVLU x y)) 57 (Mod16 x y) -> (Select1 (DIVW x y)) 58 (Mod16u x y) -> (Select1 (DIVWU x y)) 59 (Mod8 x y) -> (Select1 (DIVW (SignExt8to16 x) (SignExt8to16 y))) 60 (Mod8u x y) -> (Select1 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y))) 61 62 (And64 x y) -> (ANDQ x y) 63 (And32 x y) -> (ANDL x y) 64 (And16 x y) -> (ANDL x y) 65 (And8 x y) -> (ANDL x y) 66 67 (Or64 x y) -> (ORQ x y) 68 (Or32 x y) -> (ORL x y) 69 (Or16 x y) -> (ORL x y) 70 (Or8 x y) -> (ORL x y) 71 72 (Xor64 x y) -> (XORQ x y) 73 (Xor32 x y) -> (XORL x y) 74 (Xor16 x y) -> (XORL x y) 75 (Xor8 x y) -> (XORL x y) 76 77 (Neg64 x) -> (NEGQ x) 78 (Neg32 x) -> (NEGL x) 79 (Neg16 x) -> (NEGL x) 80 (Neg8 x) -> (NEGL x) 81 (Neg32F x) -> (PXOR x (MOVSSconst <typ.Float32> [f2i(math.Copysign(0, -1))])) 82 (Neg64F x) -> (PXOR x (MOVSDconst <typ.Float64> [f2i(math.Copysign(0, -1))])) 83 84 (Com64 x) -> (NOTQ x) 85 (Com32 x) -> (NOTL x) 86 (Com16 x) -> (NOTL x) 87 (Com8 x) -> (NOTL x) 88 89 // Lowering boolean ops 90 (AndB x y) -> (ANDL x y) 91 (OrB x y) -> (ORL x y) 92 (Not x) -> (XORLconst [1] x) 93 94 // Lowering pointer arithmetic 95 (OffPtr [off] ptr) && config.PtrSize == 8 && is32Bit(off) -> (ADDQconst [off] ptr) 96 (OffPtr [off] ptr) && config.PtrSize == 8 -> (ADDQ (MOVQconst [off]) ptr) 97 (OffPtr [off] ptr) && config.PtrSize == 4 -> (ADDLconst [off] ptr) 98 99 // Lowering other arithmetic 100 (Ctz64 <t> x) -> (CMOVQEQ (Select0 <t> (BSFQ x)) (MOVQconst <t> [64]) (Select1 <types.TypeFlags> (BSFQ x))) 101 (Ctz32 x) -> (Select0 (BSFQ (ORQ <typ.UInt64> (MOVQconst [1<<32]) x))) 102 103 (BitLen64 <t> x) -> (ADDQconst [1] (CMOVQEQ <t> (Select0 <t> (BSRQ x)) (MOVQconst <t> [-1]) (Select1 <types.TypeFlags> (BSRQ x)))) 104 (BitLen32 x) -> (BitLen64 (MOVLQZX <typ.UInt64> x)) 105 106 (Bswap64 x) -> (BSWAPQ x) 107 (Bswap32 x) -> (BSWAPL x) 108 109 (PopCount64 x) -> (POPCNTQ x) 110 (PopCount32 x) -> (POPCNTL x) 111 (PopCount16 x) -> (POPCNTL (MOVWQZX <typ.UInt32> x)) 112 (PopCount8 x) -> (POPCNTL (MOVBQZX <typ.UInt32> x)) 113 114 (Sqrt x) -> (SQRTSD x) 115 116 // 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.(*types.Type).Size() == 8 && is64BitFloat(val.Type) -> (MOVSDstore ptr val mem) 309 (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && is32BitFloat(val.Type) -> (MOVSSstore ptr val mem) 310 311 (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 -> (MOVQstore ptr val mem) 312 (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 -> (MOVLstore ptr val mem) 313 (Store {t} ptr val mem) && t.(*types.Type).Size() == 2 -> (MOVWstore ptr val mem) 314 (Store {t} ptr val mem) && t.(*types.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 <types.NewTuple(typ.UInt32,types.TypeMem)> val ptr mem)) 481 (AtomicStore64 ptr val mem) -> (Select1 (XCHGQ <types.NewTuple(typ.UInt64,types.TypeMem)> val ptr mem)) 482 (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 8 -> (Select1 (XCHGQ <types.NewTuple(typ.BytePtr,types.TypeMem)> val ptr mem)) 483 (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 4 -> (Select1 (XCHGL <types.NewTuple(typ.BytePtr,types.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 val (XADDLlock val ptr mem)) 491 (AtomicAdd64 ptr val mem) -> (AddTupleFirst64 val (XADDQlock val ptr mem)) 492 (Select0 <t> (AddTupleFirst32 val tuple)) -> (ADDL val (Select0 <t> tuple)) 493 (Select1 (AddTupleFirst32 _ tuple)) -> (Select1 tuple) 494 (Select0 <t> (AddTupleFirst64 val tuple)) -> (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 // Fold boolean negation into SETcc. 548 (XORLconst [1] (SETNE x)) -> (SETEQ x) 549 (XORLconst [1] (SETEQ x)) -> (SETNE x) 550 (XORLconst [1] (SETL x)) -> (SETGE x) 551 (XORLconst [1] (SETGE x)) -> (SETL x) 552 (XORLconst [1] (SETLE x)) -> (SETG x) 553 (XORLconst [1] (SETG x)) -> (SETLE x) 554 (XORLconst [1] (SETB x)) -> (SETAE x) 555 (XORLconst [1] (SETAE x)) -> (SETB x) 556 (XORLconst [1] (SETBE x)) -> (SETA x) 557 (XORLconst [1] (SETA x)) -> (SETBE x) 558 559 // Convert BTQconst to BTLconst if possible. It has a shorter encoding. 560 (BTQconst [c] x) && c < 32 -> (BTLconst [c] x) 561 562 // Special case for floating point - LF/LEF not generated 563 (NE (TESTB (SETGF cmp) (SETGF cmp)) yes no) -> (UGT cmp yes no) 564 (NE (TESTB (SETGEF cmp) (SETGEF cmp)) yes no) -> (UGE cmp yes no) 565 (NE (TESTB (SETEQF cmp) (SETEQF cmp)) yes no) -> (EQF cmp yes no) 566 (NE (TESTB (SETNEF cmp) (SETNEF cmp)) yes no) -> (NEF cmp yes no) 567 568 // Disabled because it interferes with the pattern match above and makes worse code. 569 // (SETNEF x) -> (ORQ (SETNE <typ.Int8> x) (SETNAN <typ.Int8> x)) 570 // (SETEQF x) -> (ANDQ (SETEQ <typ.Int8> x) (SETORD <typ.Int8> x)) 571 572 // fold constants into instructions 573 (ADDQ x (MOVQconst [c])) && is32Bit(c) -> (ADDQconst [c] x) 574 (ADDL x (MOVLconst [c])) -> (ADDLconst [c] x) 575 576 (SUBQ x (MOVQconst [c])) && is32Bit(c) -> (SUBQconst x [c]) 577 (SUBQ (MOVQconst [c]) x) && is32Bit(c) -> (NEGQ (SUBQconst <v.Type> x [c])) 578 (SUBL x (MOVLconst [c])) -> (SUBLconst x [c]) 579 (SUBL (MOVLconst [c]) x) -> (NEGL (SUBLconst <v.Type> x [c])) 580 581 (MULQ x (MOVQconst [c])) && is32Bit(c) -> (MULQconst [c] x) 582 (MULL x (MOVLconst [c])) -> (MULLconst [c] x) 583 584 (ANDQ x (MOVQconst [c])) && is32Bit(c) -> (ANDQconst [c] x) 585 (ANDL x (MOVLconst [c])) -> (ANDLconst [c] x) 586 587 (ANDLconst [c] (ANDLconst [d] x)) -> (ANDLconst [c & d] x) 588 (ANDQconst [c] (ANDQconst [d] x)) -> (ANDQconst [c & d] x) 589 590 (XORLconst [c] (XORLconst [d] x)) -> (XORLconst [c ^ d] x) 591 (XORQconst [c] (XORQconst [d] x)) -> (XORQconst [c ^ d] x) 592 593 (MULLconst [c] (MULLconst [d] x)) -> (MULLconst [int64(int32(c * d))] x) 594 (MULQconst [c] (MULQconst [d] x)) && is32Bit(c*d) -> (MULQconst [c * d] x) 595 596 (ORQ x (MOVQconst [c])) && is32Bit(c) -> (ORQconst [c] x) 597 (ORL x (MOVLconst [c])) -> (ORLconst [c] x) 598 599 (XORQ x (MOVQconst [c])) && is32Bit(c) -> (XORQconst [c] x) 600 (XORL x (MOVLconst [c])) -> (XORLconst [c] x) 601 602 (SHLQ x (MOVQconst [c])) -> (SHLQconst [c&63] x) 603 (SHLQ x (MOVLconst [c])) -> (SHLQconst [c&63] x) 604 605 (SHLL x (MOVQconst [c])) -> (SHLLconst [c&31] x) 606 (SHLL x (MOVLconst [c])) -> (SHLLconst [c&31] x) 607 608 (SHRQ x (MOVQconst [c])) -> (SHRQconst [c&63] x) 609 (SHRQ x (MOVLconst [c])) -> (SHRQconst [c&63] x) 610 611 (SHRL x (MOVQconst [c])) -> (SHRLconst [c&31] x) 612 (SHRL x (MOVLconst [c])) -> (SHRLconst [c&31] x) 613 614 (SHRW x (MOVQconst [c])) && c&31 < 16 -> (SHRWconst [c&31] x) 615 (SHRW x (MOVLconst [c])) && c&31 < 16 -> (SHRWconst [c&31] x) 616 (SHRW _ (MOVQconst [c])) && c&31 >= 16 -> (MOVLconst [0]) 617 (SHRW _ (MOVLconst [c])) && c&31 >= 16 -> (MOVLconst [0]) 618 619 (SHRB x (MOVQconst [c])) && c&31 < 8 -> (SHRBconst [c&31] x) 620 (SHRB x (MOVLconst [c])) && c&31 < 8 -> (SHRBconst [c&31] x) 621 (SHRB _ (MOVQconst [c])) && c&31 >= 8 -> (MOVLconst [0]) 622 (SHRB _ (MOVLconst [c])) && c&31 >= 8 -> (MOVLconst [0]) 623 624 (SARQ x (MOVQconst [c])) -> (SARQconst [c&63] x) 625 (SARQ x (MOVLconst [c])) -> (SARQconst [c&63] x) 626 627 (SARL x (MOVQconst [c])) -> (SARLconst [c&31] x) 628 (SARL x (MOVLconst [c])) -> (SARLconst [c&31] x) 629 630 (SARW x (MOVQconst [c])) -> (SARWconst [min(c&31,15)] x) 631 (SARW x (MOVLconst [c])) -> (SARWconst [min(c&31,15)] x) 632 633 (SARB x (MOVQconst [c])) -> (SARBconst [min(c&31,7)] x) 634 (SARB x (MOVLconst [c])) -> (SARBconst [min(c&31,7)] x) 635 636 // Operations which don't affect the low 6/5 bits of the shift amount are NOPs. 637 (SHLQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SHLQ x y) 638 (SHRQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SHRQ x y) 639 (SARQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SARQ x y) 640 (SHLQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SHLQ x (NEGQ <t> y)) 641 (SHRQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SHRQ x (NEGQ <t> y)) 642 (SARQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SARQ x (NEGQ <t> y)) 643 (SHLQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SHLQ x y) 644 (SHRQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SHRQ x y) 645 (SARQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SARQ x y) 646 (SHLQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SHLQ x (NEGQ <t> y)) 647 (SHRQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SHRQ x (NEGQ <t> y)) 648 (SARQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SARQ x (NEGQ <t> y)) 649 650 (SHLL x (ADDQconst [c] y)) && c & 31 == 0 -> (SHLL x y) 651 (SHRL x (ADDQconst [c] y)) && c & 31 == 0 -> (SHRL x y) 652 (SARL x (ADDQconst [c] y)) && c & 31 == 0 -> (SARL x y) 653 (SHLL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SHLL x (NEGQ <t> y)) 654 (SHRL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SHRL x (NEGQ <t> y)) 655 (SARL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SARL x (NEGQ <t> y)) 656 (SHLL x (ANDQconst [c] y)) && c & 31 == 31 -> (SHLL x y) 657 (SHRL x (ANDQconst [c] y)) && c & 31 == 31 -> (SHRL x y) 658 (SARL x (ANDQconst [c] y)) && c & 31 == 31 -> (SARL x y) 659 (SHLL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SHLL x (NEGQ <t> y)) 660 (SHRL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SHRL x (NEGQ <t> y)) 661 (SARL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SARL x (NEGQ <t> y)) 662 663 (SHLQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SHLQ x y) 664 (SHRQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SHRQ x y) 665 (SARQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SARQ x y) 666 (SHLQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SHLQ x (NEGL <t> y)) 667 (SHRQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SHRQ x (NEGL <t> y)) 668 (SARQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SARQ x (NEGL <t> y)) 669 (SHLQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SHLQ x y) 670 (SHRQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SHRQ x y) 671 (SARQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SARQ x y) 672 (SHLQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SHLQ x (NEGL <t> y)) 673 (SHRQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SHRQ x (NEGL <t> y)) 674 (SARQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SARQ x (NEGL <t> y)) 675 676 (SHLL x (ADDLconst [c] y)) && c & 31 == 0 -> (SHLL x y) 677 (SHRL x (ADDLconst [c] y)) && c & 31 == 0 -> (SHRL x y) 678 (SARL x (ADDLconst [c] y)) && c & 31 == 0 -> (SARL x y) 679 (SHLL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SHLL x (NEGL <t> y)) 680 (SHRL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SHRL x (NEGL <t> y)) 681 (SARL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SARL x (NEGL <t> y)) 682 (SHLL x (ANDLconst [c] y)) && c & 31 == 31 -> (SHLL x y) 683 (SHRL x (ANDLconst [c] y)) && c & 31 == 31 -> (SHRL x y) 684 (SARL x (ANDLconst [c] y)) && c & 31 == 31 -> (SARL x y) 685 (SHLL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SHLL x (NEGL <t> y)) 686 (SHRL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SHRL x (NEGL <t> y)) 687 (SARL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SARL x (NEGL <t> y)) 688 689 // Constant rotate instructions 690 (ADDQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 691 ( ORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 692 (XORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c]) 693 694 (ADDL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 695 ( ORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 696 (XORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c]) 697 698 (ADDL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 699 ( ORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 700 (XORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c]) 701 702 (ADDL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 703 ( ORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 704 (XORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c && c < 8 && t.Size() == 1 -> (ROLBconst x [c]) 705 706 (ROLQconst [c] (ROLQconst [d] x)) -> (ROLQconst [(c+d)&63] x) 707 (ROLLconst [c] (ROLLconst [d] x)) -> (ROLLconst [(c+d)&31] x) 708 (ROLWconst [c] (ROLWconst [d] x)) -> (ROLWconst [(c+d)&15] x) 709 (ROLBconst [c] (ROLBconst [d] x)) -> (ROLBconst [(c+d)& 7] x) 710 711 // Non-constant rotates. 712 // We want to issue a rotate when the Go source contains code like 713 // y &= 63 714 // x << y | x >> (64-y) 715 // The shift rules above convert << to SHLx and >> to SHRx. 716 // SHRx converts its shift argument from 64-y to -y. 717 // A tricky situation occurs when y==0. Then the original code would be: 718 // x << 0 | x >> 64 719 // But x >> 64 is 0, not x. So there's an additional mask that is ANDed in 720 // to force the second term to 0. We don't need that mask, but we must match 721 // it in order to strip it out. 722 (ORQ (SHLQ x y) (ANDQ (SHRQ x (NEGQ y)) (SBBQcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [63]) [-64])) [64])))) -> (ROLQ x y) 723 (ORQ (SHLQ x y) (ANDQ (SHRQ x (NEGL y)) (SBBQcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [63]) [-64])) [64])))) -> (ROLQ x y) 724 (ORQ (SHRQ x y) (ANDQ (SHLQ x (NEGQ y)) (SBBQcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [63]) [-64])) [64])))) -> (RORQ x y) 725 (ORQ (SHRQ x y) (ANDQ (SHLQ x (NEGL y)) (SBBQcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [63]) [-64])) [64])))) -> (RORQ x y) 726 727 (ORL (SHLL x y) (ANDL (SHRL x (NEGQ y)) (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [31]) [-32])) [32])))) -> (ROLL x y) 728 (ORL (SHLL x y) (ANDL (SHRL x (NEGL y)) (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [31]) [-32])) [32])))) -> (ROLL x y) 729 (ORL (SHRL x y) (ANDL (SHLL x (NEGQ y)) (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [31]) [-32])) [32])))) -> (RORL x y) 730 (ORL (SHRL x y) (ANDL (SHLL x (NEGL y)) (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [31]) [-32])) [32])))) -> (RORL x y) 731 732 // Help with rotate detection 733 (CMPQconst (NEGQ (ADDQconst [-16] (ANDQconst [15] _))) [32]) -> (FlagLT_ULT) 734 (CMPQconst (NEGQ (ADDQconst [ -8] (ANDQconst [7] _))) [32]) -> (FlagLT_ULT) 735 736 (ORL (SHLL x (ANDQconst y [15])) 737 (ANDL (SHRW x (NEGQ (ADDQconst (ANDQconst y [15]) [-16]))) 738 (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [15]) [-16])) [16])))) 739 && v.Type.Size() == 2 740 -> (ROLW x y) 741 (ORL (SHLL x (ANDLconst y [15])) 742 (ANDL (SHRW x (NEGL (ADDLconst (ANDLconst y [15]) [-16]))) 743 (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [15]) [-16])) [16])))) 744 && v.Type.Size() == 2 745 -> (ROLW x y) 746 (ORL (SHRW x (ANDQconst y [15])) 747 (SHLL x (NEGQ (ADDQconst (ANDQconst y [15]) [-16])))) 748 && v.Type.Size() == 2 749 -> (RORW x y) 750 (ORL (SHRW x (ANDLconst y [15])) 751 (SHLL x (NEGL (ADDLconst (ANDLconst y [15]) [-16])))) 752 && v.Type.Size() == 2 753 -> (RORW x y) 754 755 (ORL (SHLL x (ANDQconst y [ 7])) 756 (ANDL (SHRB x (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8]))) 757 (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8])) [ 8])))) 758 && v.Type.Size() == 1 759 -> (ROLB x y) 760 (ORL (SHLL x (ANDLconst y [ 7])) 761 (ANDL (SHRB x (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8]))) 762 (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8])) [ 8])))) 763 && v.Type.Size() == 1 764 -> (ROLB x y) 765 (ORL (SHRB x (ANDQconst y [ 7])) 766 (SHLL x (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8])))) 767 && v.Type.Size() == 1 768 -> (RORB x y) 769 (ORL (SHRB x (ANDLconst y [ 7])) 770 (SHLL x (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8])))) 771 && v.Type.Size() == 1 772 -> (RORB x y) 773 774 // rotate left negative = rotate right 775 (ROLQ x (NEGQ y)) -> (RORQ x y) 776 (ROLQ x (NEGL y)) -> (RORQ x y) 777 (ROLL x (NEGQ y)) -> (RORL x y) 778 (ROLL x (NEGL y)) -> (RORL x y) 779 (ROLW x (NEGQ y)) -> (RORW x y) 780 (ROLW x (NEGL y)) -> (RORW x y) 781 (ROLB x (NEGQ y)) -> (RORB x y) 782 (ROLB x (NEGL y)) -> (RORB x y) 783 784 // rotate right negative = rotate left 785 (RORQ x (NEGQ y)) -> (ROLQ x y) 786 (RORQ x (NEGL y)) -> (ROLQ x y) 787 (RORL x (NEGQ y)) -> (ROLL x y) 788 (RORL x (NEGL y)) -> (ROLL x y) 789 (RORW x (NEGQ y)) -> (ROLW x y) 790 (RORW x (NEGL y)) -> (ROLW x y) 791 (RORB x (NEGQ y)) -> (ROLB x y) 792 (RORB x (NEGL y)) -> (ROLB x y) 793 794 // rotate by constants 795 (ROLQ x (MOVQconst [c])) -> (ROLQconst [c&63] x) 796 (ROLQ x (MOVLconst [c])) -> (ROLQconst [c&63] x) 797 (ROLL x (MOVQconst [c])) -> (ROLLconst [c&31] x) 798 (ROLL x (MOVLconst [c])) -> (ROLLconst [c&31] x) 799 (ROLW x (MOVQconst [c])) -> (ROLWconst [c&15] x) 800 (ROLW x (MOVLconst [c])) -> (ROLWconst [c&15] x) 801 (ROLB x (MOVQconst [c])) -> (ROLBconst [c&7 ] x) 802 (ROLB x (MOVLconst [c])) -> (ROLBconst [c&7 ] x) 803 804 (RORQ x (MOVQconst [c])) -> (ROLQconst [(-c)&63] x) 805 (RORQ x (MOVLconst [c])) -> (ROLQconst [(-c)&63] x) 806 (RORL x (MOVQconst [c])) -> (ROLLconst [(-c)&31] x) 807 (RORL x (MOVLconst [c])) -> (ROLLconst [(-c)&31] x) 808 (RORW x (MOVQconst [c])) -> (ROLWconst [(-c)&15] x) 809 (RORW x (MOVLconst [c])) -> (ROLWconst [(-c)&15] x) 810 (RORB x (MOVQconst [c])) -> (ROLBconst [(-c)&7 ] x) 811 (RORB x (MOVLconst [c])) -> (ROLBconst [(-c)&7 ] x) 812 813 // Constant shift simplifications 814 (SHLQconst x [0]) -> x 815 (SHRQconst x [0]) -> x 816 (SARQconst x [0]) -> x 817 818 (SHLLconst x [0]) -> x 819 (SHRLconst x [0]) -> x 820 (SARLconst x [0]) -> x 821 822 (SHRWconst x [0]) -> x 823 (SARWconst x [0]) -> x 824 825 (SHRBconst x [0]) -> x 826 (SARBconst x [0]) -> x 827 828 (ROLQconst x [0]) -> x 829 (ROLLconst x [0]) -> x 830 (ROLWconst x [0]) -> x 831 (ROLBconst x [0]) -> x 832 833 // Note: the word and byte shifts keep the low 5 bits (not the low 4 or 3 bits) 834 // because the x86 instructions are defined to use all 5 bits of the shift even 835 // for the small shifts. I don't think we'll ever generate a weird shift (e.g. 836 // (SHRW x (MOVLconst [24])), but just in case. 837 838 (CMPQ x (MOVQconst [c])) && is32Bit(c) -> (CMPQconst x [c]) 839 (CMPQ (MOVQconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPQconst x [c])) 840 (CMPL x (MOVLconst [c])) -> (CMPLconst x [c]) 841 (CMPL (MOVLconst [c]) x) -> (InvertFlags (CMPLconst x [c])) 842 (CMPW x (MOVLconst [c])) -> (CMPWconst x [int64(int16(c))]) 843 (CMPW (MOVLconst [c]) x) -> (InvertFlags (CMPWconst x [int64(int16(c))])) 844 (CMPB x (MOVLconst [c])) -> (CMPBconst x [int64(int8(c))]) 845 (CMPB (MOVLconst [c]) x) -> (InvertFlags (CMPBconst x [int64(int8(c))])) 846 847 // Using MOVZX instead of AND is cheaper. 848 (ANDLconst [0xFF] x) -> (MOVBQZX x) 849 (ANDLconst [0xFFFF] x) -> (MOVWQZX x) 850 (ANDQconst [0xFF] x) -> (MOVBQZX x) 851 (ANDQconst [0xFFFF] x) -> (MOVWQZX x) 852 (ANDQconst [0xFFFFFFFF] x) -> (MOVLQZX x) 853 854 // strength reduction 855 // Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf: 856 // 1 - addq, shlq, leaq, negq 857 // 3 - imulq 858 // This limits the rewrites to two instructions. 859 // TODO: 27, 81 860 (MULQconst [-1] x) -> (NEGQ x) 861 (MULQconst [0] _) -> (MOVQconst [0]) 862 (MULQconst [1] x) -> x 863 (MULQconst [3] x) -> (LEAQ2 x x) 864 (MULQconst [5] x) -> (LEAQ4 x x) 865 (MULQconst [7] x) -> (LEAQ8 (NEGQ <v.Type> x) x) 866 (MULQconst [9] x) -> (LEAQ8 x x) 867 (MULQconst [11] x) -> (LEAQ2 x (LEAQ4 <v.Type> x x)) 868 (MULQconst [13] x) -> (LEAQ4 x (LEAQ2 <v.Type> x x)) 869 (MULQconst [21] x) -> (LEAQ4 x (LEAQ4 <v.Type> x x)) 870 (MULQconst [25] x) -> (LEAQ8 x (LEAQ2 <v.Type> x x)) 871 (MULQconst [37] x) -> (LEAQ4 x (LEAQ8 <v.Type> x x)) 872 (MULQconst [41] x) -> (LEAQ8 x (LEAQ4 <v.Type> x x)) 873 (MULQconst [73] x) -> (LEAQ8 x (LEAQ8 <v.Type> x x)) 874 875 (MULQconst [c] x) && isPowerOfTwo(c) -> (SHLQconst [log2(c)] x) 876 (MULQconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUBQ (SHLQconst <v.Type> [log2(c+1)] x) x) 877 (MULQconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (LEAQ1 (SHLQconst <v.Type> [log2(c-1)] x) x) 878 (MULQconst [c] x) && isPowerOfTwo(c-2) && c >= 34 -> (LEAQ2 (SHLQconst <v.Type> [log2(c-2)] x) x) 879 (MULQconst [c] x) && isPowerOfTwo(c-4) && c >= 68 -> (LEAQ4 (SHLQconst <v.Type> [log2(c-4)] x) x) 880 (MULQconst [c] x) && isPowerOfTwo(c-8) && c >= 136 -> (LEAQ8 (SHLQconst <v.Type> [log2(c-8)] x) x) 881 (MULQconst [c] x) && c%3 == 0 && isPowerOfTwo(c/3) -> (SHLQconst [log2(c/3)] (LEAQ2 <v.Type> x x)) 882 (MULQconst [c] x) && c%5 == 0 && isPowerOfTwo(c/5) -> (SHLQconst [log2(c/5)] (LEAQ4 <v.Type> x x)) 883 (MULQconst [c] x) && c%9 == 0 && isPowerOfTwo(c/9) -> (SHLQconst [log2(c/9)] (LEAQ8 <v.Type> x x)) 884 885 // combine add/shift into LEAQ 886 (ADDQ x (SHLQconst [3] y)) -> (LEAQ8 x y) 887 (ADDQ x (SHLQconst [2] y)) -> (LEAQ4 x y) 888 (ADDQ x (SHLQconst [1] y)) -> (LEAQ2 x y) 889 (ADDQ x (ADDQ y y)) -> (LEAQ2 x y) 890 (ADDQ x (ADDQ x y)) -> (LEAQ2 y x) 891 892 // combine ADDQ/ADDQconst into LEAQ1 893 (ADDQconst [c] (ADDQ x y)) -> (LEAQ1 [c] x y) 894 (ADDQ (ADDQconst [c] x) y) -> (LEAQ1 [c] x y) 895 896 // fold ADDQ into LEAQ 897 (ADDQconst [c] (LEAQ [d] {s} x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 898 (LEAQ [c] {s} (ADDQconst [d] x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 899 (LEAQ [c] {s} (ADDQ x y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 900 (ADDQ x (LEAQ [c] {s} y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 901 902 // fold ADDQconst into LEAQx 903 (ADDQconst [c] (LEAQ1 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ1 [c+d] {s} x y) 904 (ADDQconst [c] (LEAQ2 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ2 [c+d] {s} x y) 905 (ADDQconst [c] (LEAQ4 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ4 [c+d] {s} x y) 906 (ADDQconst [c] (LEAQ8 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ8 [c+d] {s} x y) 907 (LEAQ1 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ1 [c+d] {s} x y) 908 (LEAQ2 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ2 [c+d] {s} x y) 909 (LEAQ2 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+2*d) && y.Op != OpSB -> (LEAQ2 [c+2*d] {s} x y) 910 (LEAQ4 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ4 [c+d] {s} x y) 911 (LEAQ4 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+4*d) && y.Op != OpSB -> (LEAQ4 [c+4*d] {s} x y) 912 (LEAQ8 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ8 [c+d] {s} x y) 913 (LEAQ8 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+8*d) && y.Op != OpSB -> (LEAQ8 [c+8*d] {s} x y) 914 915 // fold shifts into LEAQx 916 (LEAQ1 [c] {s} x (SHLQconst [1] y)) -> (LEAQ2 [c] {s} x y) 917 (LEAQ1 [c] {s} x (SHLQconst [2] y)) -> (LEAQ4 [c] {s} x y) 918 (LEAQ1 [c] {s} x (SHLQconst [3] y)) -> (LEAQ8 [c] {s} x y) 919 (LEAQ2 [c] {s} x (SHLQconst [1] y)) -> (LEAQ4 [c] {s} x y) 920 (LEAQ2 [c] {s} x (SHLQconst [2] y)) -> (LEAQ8 [c] {s} x y) 921 (LEAQ4 [c] {s} x (SHLQconst [1] y)) -> (LEAQ8 [c] {s} x y) 922 923 // reverse ordering of compare instruction 924 (SETL (InvertFlags x)) -> (SETG x) 925 (SETG (InvertFlags x)) -> (SETL x) 926 (SETB (InvertFlags x)) -> (SETA x) 927 (SETA (InvertFlags x)) -> (SETB x) 928 (SETLE (InvertFlags x)) -> (SETGE x) 929 (SETGE (InvertFlags x)) -> (SETLE x) 930 (SETBE (InvertFlags x)) -> (SETAE x) 931 (SETAE (InvertFlags x)) -> (SETBE x) 932 (SETEQ (InvertFlags x)) -> (SETEQ x) 933 (SETNE (InvertFlags x)) -> (SETNE x) 934 935 // sign extended loads 936 // Note: The combined instruction must end up in the same block 937 // as the original load. If not, we end up making a value with 938 // memory type live in two different blocks, which can lead to 939 // multiple memory values alive simultaneously. 940 // Make sure we don't combine these ops if the load has another use. 941 // This prevents a single load from being split into multiple loads 942 // which then might return different values. See test/atomicload.go. 943 (MOVBQSX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 944 (MOVBQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 945 (MOVBQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 946 (MOVBQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 947 (MOVBQZX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 948 (MOVBQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 949 (MOVBQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 950 (MOVBQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 951 (MOVWQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 952 (MOVWQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 953 (MOVWQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 954 (MOVWQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 955 (MOVWQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 956 (MOVWQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 957 (MOVLQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 958 (MOVLQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 959 (MOVLQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 960 (MOVLQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 961 962 (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBloadidx1 <v.Type> [off] {sym} ptr idx mem) 963 (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx1 <v.Type> [off] {sym} ptr idx mem) 964 (MOVWQZX x:(MOVWloadidx2 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx2 <v.Type> [off] {sym} ptr idx mem) 965 (MOVLQZX x:(MOVLloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx1 <v.Type> [off] {sym} ptr idx mem) 966 (MOVLQZX x:(MOVLloadidx4 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx4 <v.Type> [off] {sym} ptr idx mem) 967 968 // replace load from same location as preceding store with zero/sign extension (or copy in case of full width) 969 (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBQZX x) 970 (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWQZX x) 971 (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVLQZX x) 972 (MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 973 (MOVBQSXload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBQSX x) 974 (MOVWQSXload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWQSX x) 975 (MOVLQSXload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVLQSX x) 976 977 // Fold extensions and ANDs together. 978 (MOVBQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xff] x) 979 (MOVWQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xffff] x) 980 (MOVLQZX (ANDLconst [c] x)) -> (ANDLconst [c] x) 981 (MOVBQSX (ANDLconst [c] x)) && c & 0x80 == 0 -> (ANDLconst [c & 0x7f] x) 982 (MOVWQSX (ANDLconst [c] x)) && c & 0x8000 == 0 -> (ANDLconst [c & 0x7fff] x) 983 (MOVLQSX (ANDLconst [c] x)) && c & 0x80000000 == 0 -> (ANDLconst [c & 0x7fffffff] x) 984 985 // Don't extend before storing 986 (MOVLstore [off] {sym} ptr (MOVLQSX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 987 (MOVWstore [off] {sym} ptr (MOVWQSX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 988 (MOVBstore [off] {sym} ptr (MOVBQSX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 989 (MOVLstore [off] {sym} ptr (MOVLQZX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 990 (MOVWstore [off] {sym} ptr (MOVWQZX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 991 (MOVBstore [off] {sym} ptr (MOVBQZX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 992 993 // fold constants into memory operations 994 // Note that this is not always a good idea because if not all the uses of 995 // the ADDQconst get eliminated, we still have to compute the ADDQconst and we now 996 // have potentially two live values (ptr and (ADDQconst [off] ptr)) instead of one. 997 // Nevertheless, let's do it! 998 (MOVQload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 999 (MOVLload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 1000 (MOVWload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 1001 (MOVBload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 1002 (MOVSSload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSSload [off1+off2] {sym} ptr mem) 1003 (MOVSDload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSDload [off1+off2] {sym} ptr mem) 1004 (MOVOload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVOload [off1+off2] {sym} ptr mem) 1005 1006 (MOVQstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 1007 (MOVLstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 1008 (MOVWstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 1009 (MOVBstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 1010 (MOVSSstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSSstore [off1+off2] {sym} ptr val mem) 1011 (MOVSDstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSDstore [off1+off2] {sym} ptr val mem) 1012 (MOVOstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVOstore [off1+off2] {sym} ptr val mem) 1013 1014 // Fold constants into stores. 1015 (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> 1016 (MOVQstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 1017 (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 1018 (MOVLstoreconst [makeValAndOff(int64(int32(c)),off)] {sym} ptr mem) 1019 (MOVWstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 1020 (MOVWstoreconst [makeValAndOff(int64(int16(c)),off)] {sym} ptr mem) 1021 (MOVBstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 1022 (MOVBstoreconst [makeValAndOff(int64(int8(c)),off)] {sym} ptr mem) 1023 1024 // Fold address offsets into constant stores. 1025 (MOVQstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1026 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1027 (MOVLstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1028 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1029 (MOVWstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1030 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1031 (MOVBstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1032 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1033 1034 // We need to fold LEAQ into the MOVx ops so that the live variable analysis knows 1035 // what variables are being read/written by the ops. 1036 (MOVQload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1037 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1038 (MOVLload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1039 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1040 (MOVWload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1041 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1042 (MOVBload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1043 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1044 (MOVSSload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1045 (MOVSSload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1046 (MOVSDload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1047 (MOVSDload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1048 (MOVOload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1049 (MOVOload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1050 1051 (MOVBQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1052 (MOVBQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1053 (MOVWQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1054 (MOVWQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1055 (MOVLQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1056 (MOVLQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1057 1058 (MOVQstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1059 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1060 (MOVLstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1061 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1062 (MOVWstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1063 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1064 (MOVBstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1065 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1066 (MOVSSstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1067 (MOVSSstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1068 (MOVSDstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1069 (MOVSDstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1070 (MOVOstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1071 (MOVOstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1072 1073 (MOVQstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1074 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1075 (MOVLstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1076 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1077 (MOVWstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1078 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1079 (MOVBstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1080 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1081 1082 // generating indexed loads and stores 1083 (MOVBload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1084 (MOVBloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1085 (MOVWload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1086 (MOVWloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1087 (MOVWload [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1088 (MOVWloadidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1089 (MOVLload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1090 (MOVLloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1091 (MOVLload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1092 (MOVLloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1093 (MOVQload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1094 (MOVQloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1095 (MOVQload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1096 (MOVQloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1097 (MOVSSload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1098 (MOVSSloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1099 (MOVSSload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1100 (MOVSSloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1101 (MOVSDload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1102 (MOVSDloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1103 (MOVSDload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1104 (MOVSDloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 1105 1106 (MOVBstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1107 (MOVBstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1108 (MOVWstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1109 (MOVWstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1110 (MOVWstore [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1111 (MOVWstoreidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1112 (MOVLstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1113 (MOVLstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1114 (MOVLstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1115 (MOVLstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1116 (MOVQstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1117 (MOVQstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1118 (MOVQstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1119 (MOVQstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1120 (MOVSSstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1121 (MOVSSstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1122 (MOVSSstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1123 (MOVSSstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1124 (MOVSDstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1125 (MOVSDstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1126 (MOVSDstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1127 (MOVSDstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 1128 1129 (MOVBload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVBloadidx1 [off] {sym} ptr idx mem) 1130 (MOVWload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVWloadidx1 [off] {sym} ptr idx mem) 1131 (MOVLload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVLloadidx1 [off] {sym} ptr idx mem) 1132 (MOVQload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVQloadidx1 [off] {sym} ptr idx mem) 1133 (MOVSSload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSSloadidx1 [off] {sym} ptr idx mem) 1134 (MOVSDload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSDloadidx1 [off] {sym} ptr idx mem) 1135 (MOVBstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVBstoreidx1 [off] {sym} ptr idx val mem) 1136 (MOVWstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVWstoreidx1 [off] {sym} ptr idx val mem) 1137 (MOVLstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVLstoreidx1 [off] {sym} ptr idx val mem) 1138 (MOVQstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVQstoreidx1 [off] {sym} ptr idx val mem) 1139 (MOVSSstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSSstoreidx1 [off] {sym} ptr idx val mem) 1140 (MOVSDstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSDstoreidx1 [off] {sym} ptr idx val mem) 1141 1142 (MOVBstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1143 (MOVBstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1144 (MOVWstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1145 (MOVWstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1146 (MOVWstoreconst [x] {sym1} (LEAQ2 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1147 (MOVWstoreconstidx2 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1148 (MOVLstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1149 (MOVLstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1150 (MOVLstoreconst [x] {sym1} (LEAQ4 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1151 (MOVLstoreconstidx4 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1152 (MOVQstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1153 (MOVQstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1154 (MOVQstoreconst [x] {sym1} (LEAQ8 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 1155 (MOVQstoreconstidx8 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 1156 1157 (MOVBstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVBstoreconstidx1 [x] {sym} ptr idx mem) 1158 (MOVWstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVWstoreconstidx1 [x] {sym} ptr idx mem) 1159 (MOVLstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVLstoreconstidx1 [x] {sym} ptr idx mem) 1160 (MOVQstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVQstoreconstidx1 [x] {sym} ptr idx mem) 1161 1162 // combine SHLQ into indexed loads and stores 1163 (MOVWloadidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWloadidx2 [c] {sym} ptr idx mem) 1164 (MOVLloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLloadidx4 [c] {sym} ptr idx mem) 1165 (MOVQloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQloadidx8 [c] {sym} ptr idx mem) 1166 (MOVSSloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVSSloadidx4 [c] {sym} ptr idx mem) 1167 (MOVSDloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVSDloadidx8 [c] {sym} ptr idx mem) 1168 (MOVWstoreidx1 [c] {sym} ptr (SHLQconst [1] idx) val mem) -> (MOVWstoreidx2 [c] {sym} ptr idx val mem) 1169 (MOVLstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVLstoreidx4 [c] {sym} ptr idx val mem) 1170 (MOVQstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVQstoreidx8 [c] {sym} ptr idx val mem) 1171 (MOVSSstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVSSstoreidx4 [c] {sym} ptr idx val mem) 1172 (MOVSDstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVSDstoreidx8 [c] {sym} ptr idx val mem) 1173 (MOVWstoreconstidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWstoreconstidx2 [c] {sym} ptr idx mem) 1174 (MOVLstoreconstidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLstoreconstidx4 [c] {sym} ptr idx mem) 1175 (MOVQstoreconstidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQstoreconstidx8 [c] {sym} ptr idx mem) 1176 1177 // combine ADDQ into indexed loads and stores 1178 (MOVBloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 1179 (MOVWloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 1180 (MOVWloadidx2 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx2 [c+d] {sym} ptr idx mem) 1181 (MOVLloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 1182 (MOVLloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx4 [c+d] {sym} ptr idx mem) 1183 (MOVQloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 1184 (MOVQloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx8 [c+d] {sym} ptr idx mem) 1185 (MOVSSloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 1186 (MOVSSloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx4 [c+d] {sym} ptr idx mem) 1187 (MOVSDloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 1188 (MOVSDloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx8 [c+d] {sym} ptr idx mem) 1189 1190 (MOVBstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 1191 (MOVWstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 1192 (MOVWstoreidx2 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx2 [c+d] {sym} ptr idx val mem) 1193 (MOVLstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 1194 (MOVLstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx4 [c+d] {sym} ptr idx val mem) 1195 (MOVQstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 1196 (MOVQstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx8 [c+d] {sym} ptr idx val mem) 1197 (MOVSSstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 1198 (MOVSSstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx4 [c+d] {sym} ptr idx val mem) 1199 (MOVSDstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 1200 (MOVSDstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx8 [c+d] {sym} ptr idx val mem) 1201 1202 (MOVBloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 1203 (MOVWloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 1204 (MOVWloadidx2 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx2 [c+2*d] {sym} ptr idx mem) 1205 (MOVLloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 1206 (MOVLloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx4 [c+4*d] {sym} ptr idx mem) 1207 (MOVQloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 1208 (MOVQloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx8 [c+8*d] {sym} ptr idx mem) 1209 (MOVSSloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 1210 (MOVSSloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx4 [c+4*d] {sym} ptr idx mem) 1211 (MOVSDloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 1212 (MOVSDloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx8 [c+8*d] {sym} ptr idx mem) 1213 1214 (MOVBstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 1215 (MOVWstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 1216 (MOVWstoreidx2 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx2 [c+2*d] {sym} ptr idx val mem) 1217 (MOVLstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 1218 (MOVLstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx4 [c+4*d] {sym} ptr idx val mem) 1219 (MOVQstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 1220 (MOVQstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx8 [c+8*d] {sym} ptr idx val mem) 1221 (MOVSSstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 1222 (MOVSSstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx4 [c+4*d] {sym} ptr idx val mem) 1223 (MOVSDstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 1224 (MOVSDstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx8 [c+8*d] {sym} ptr idx val mem) 1225 1226 (MOVBstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1227 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1228 (MOVWstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1229 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1230 (MOVWstoreconstidx2 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1231 (MOVWstoreconstidx2 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1232 (MOVLstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1233 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1234 (MOVLstoreconstidx4 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1235 (MOVLstoreconstidx4 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1236 (MOVQstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1237 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1238 (MOVQstoreconstidx8 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 1239 (MOVQstoreconstidx8 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1240 1241 (MOVBstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1242 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1243 (MOVWstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1244 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1245 (MOVWstoreconstidx2 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1246 (MOVWstoreconstidx2 [ValAndOff(x).add(2*c)] {sym} ptr idx mem) 1247 (MOVLstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1248 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1249 (MOVLstoreconstidx4 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1250 (MOVLstoreconstidx4 [ValAndOff(x).add(4*c)] {sym} ptr idx mem) 1251 (MOVQstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1252 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1253 (MOVQstoreconstidx8 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1254 (MOVQstoreconstidx8 [ValAndOff(x).add(8*c)] {sym} ptr idx mem) 1255 1256 // fold LEAQs together 1257 (LEAQ [off1] {sym1} (LEAQ [off2] {sym2} x)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1258 (LEAQ [off1+off2] {mergeSym(sym1,sym2)} x) 1259 1260 // LEAQ into LEAQ1 1261 (LEAQ1 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1262 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1263 1264 // LEAQ1 into LEAQ 1265 (LEAQ [off1] {sym1} (LEAQ1 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1266 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1267 1268 // LEAQ into LEAQ[248] 1269 (LEAQ2 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1270 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1271 (LEAQ4 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1272 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1273 (LEAQ8 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1274 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1275 1276 // LEAQ[248] into LEAQ 1277 (LEAQ [off1] {sym1} (LEAQ2 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1278 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1279 (LEAQ [off1] {sym1} (LEAQ4 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1280 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1281 (LEAQ [off1] {sym1} (LEAQ8 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1282 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1283 1284 // Absorb InvertFlags into branches. 1285 (LT (InvertFlags cmp) yes no) -> (GT cmp yes no) 1286 (GT (InvertFlags cmp) yes no) -> (LT cmp yes no) 1287 (LE (InvertFlags cmp) yes no) -> (GE cmp yes no) 1288 (GE (InvertFlags cmp) yes no) -> (LE cmp yes no) 1289 (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no) 1290 (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no) 1291 (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no) 1292 (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no) 1293 (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no) 1294 (NE (InvertFlags cmp) yes no) -> (NE cmp yes no) 1295 1296 // Constant comparisons. 1297 (CMPQconst (MOVQconst [x]) [y]) && x==y -> (FlagEQ) 1298 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)<uint64(y) -> (FlagLT_ULT) 1299 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)>uint64(y) -> (FlagLT_UGT) 1300 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)<uint64(y) -> (FlagGT_ULT) 1301 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)>uint64(y) -> (FlagGT_UGT) 1302 (CMPLconst (MOVLconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ) 1303 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT) 1304 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT) 1305 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT) 1306 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT) 1307 (CMPWconst (MOVLconst [x]) [y]) && int16(x)==int16(y) -> (FlagEQ) 1308 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)<uint16(y) -> (FlagLT_ULT) 1309 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)>uint16(y) -> (FlagLT_UGT) 1310 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)<uint16(y) -> (FlagGT_ULT) 1311 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)>uint16(y) -> (FlagGT_UGT) 1312 (CMPBconst (MOVLconst [x]) [y]) && int8(x)==int8(y) -> (FlagEQ) 1313 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)<uint8(y) -> (FlagLT_ULT) 1314 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)>uint8(y) -> (FlagLT_UGT) 1315 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)<uint8(y) -> (FlagGT_ULT) 1316 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)>uint8(y) -> (FlagGT_UGT) 1317 1318 // Other known comparisons. 1319 (CMPQconst (MOVBQZX _) [c]) && 0xFF < c -> (FlagLT_ULT) 1320 (CMPQconst (MOVWQZX _) [c]) && 0xFFFF < c -> (FlagLT_ULT) 1321 (CMPQconst (MOVLQZX _) [c]) && 0xFFFFFFFF < c -> (FlagLT_ULT) 1322 (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT_ULT) 1323 (CMPQconst (SHRQconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT) 1324 (CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1325 (CMPQconst (ANDLconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1326 (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT) 1327 (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT) 1328 (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT) 1329 1330 // TODO: DIVxU also. 1331 1332 // Absorb flag constants into SBB ops. 1333 (SBBQcarrymask (FlagEQ)) -> (MOVQconst [0]) 1334 (SBBQcarrymask (FlagLT_ULT)) -> (MOVQconst [-1]) 1335 (SBBQcarrymask (FlagLT_UGT)) -> (MOVQconst [0]) 1336 (SBBQcarrymask (FlagGT_ULT)) -> (MOVQconst [-1]) 1337 (SBBQcarrymask (FlagGT_UGT)) -> (MOVQconst [0]) 1338 (SBBLcarrymask (FlagEQ)) -> (MOVLconst [0]) 1339 (SBBLcarrymask (FlagLT_ULT)) -> (MOVLconst [-1]) 1340 (SBBLcarrymask (FlagLT_UGT)) -> (MOVLconst [0]) 1341 (SBBLcarrymask (FlagGT_ULT)) -> (MOVLconst [-1]) 1342 (SBBLcarrymask (FlagGT_UGT)) -> (MOVLconst [0]) 1343 1344 // Absorb flag constants into branches. 1345 (EQ (FlagEQ) yes no) -> (First nil yes no) 1346 (EQ (FlagLT_ULT) yes no) -> (First nil no yes) 1347 (EQ (FlagLT_UGT) yes no) -> (First nil no yes) 1348 (EQ (FlagGT_ULT) yes no) -> (First nil no yes) 1349 (EQ (FlagGT_UGT) yes no) -> (First nil no yes) 1350 1351 (NE (FlagEQ) yes no) -> (First nil no yes) 1352 (NE (FlagLT_ULT) yes no) -> (First nil yes no) 1353 (NE (FlagLT_UGT) yes no) -> (First nil yes no) 1354 (NE (FlagGT_ULT) yes no) -> (First nil yes no) 1355 (NE (FlagGT_UGT) yes no) -> (First nil yes no) 1356 1357 (LT (FlagEQ) yes no) -> (First nil no yes) 1358 (LT (FlagLT_ULT) yes no) -> (First nil yes no) 1359 (LT (FlagLT_UGT) yes no) -> (First nil yes no) 1360 (LT (FlagGT_ULT) yes no) -> (First nil no yes) 1361 (LT (FlagGT_UGT) yes no) -> (First nil no yes) 1362 1363 (LE (FlagEQ) yes no) -> (First nil yes no) 1364 (LE (FlagLT_ULT) yes no) -> (First nil yes no) 1365 (LE (FlagLT_UGT) yes no) -> (First nil yes no) 1366 (LE (FlagGT_ULT) yes no) -> (First nil no yes) 1367 (LE (FlagGT_UGT) yes no) -> (First nil no yes) 1368 1369 (GT (FlagEQ) yes no) -> (First nil no yes) 1370 (GT (FlagLT_ULT) yes no) -> (First nil no yes) 1371 (GT (FlagLT_UGT) yes no) -> (First nil no yes) 1372 (GT (FlagGT_ULT) yes no) -> (First nil yes no) 1373 (GT (FlagGT_UGT) yes no) -> (First nil yes no) 1374 1375 (GE (FlagEQ) yes no) -> (First nil yes no) 1376 (GE (FlagLT_ULT) yes no) -> (First nil no yes) 1377 (GE (FlagLT_UGT) yes no) -> (First nil no yes) 1378 (GE (FlagGT_ULT) yes no) -> (First nil yes no) 1379 (GE (FlagGT_UGT) yes no) -> (First nil yes no) 1380 1381 (ULT (FlagEQ) yes no) -> (First nil no yes) 1382 (ULT (FlagLT_ULT) yes no) -> (First nil yes no) 1383 (ULT (FlagLT_UGT) yes no) -> (First nil no yes) 1384 (ULT (FlagGT_ULT) yes no) -> (First nil yes no) 1385 (ULT (FlagGT_UGT) yes no) -> (First nil no yes) 1386 1387 (ULE (FlagEQ) yes no) -> (First nil yes no) 1388 (ULE (FlagLT_ULT) yes no) -> (First nil yes no) 1389 (ULE (FlagLT_UGT) yes no) -> (First nil no yes) 1390 (ULE (FlagGT_ULT) yes no) -> (First nil yes no) 1391 (ULE (FlagGT_UGT) yes no) -> (First nil no yes) 1392 1393 (UGT (FlagEQ) yes no) -> (First nil no yes) 1394 (UGT (FlagLT_ULT) yes no) -> (First nil no yes) 1395 (UGT (FlagLT_UGT) yes no) -> (First nil yes no) 1396 (UGT (FlagGT_ULT) yes no) -> (First nil no yes) 1397 (UGT (FlagGT_UGT) yes no) -> (First nil yes no) 1398 1399 (UGE (FlagEQ) yes no) -> (First nil yes no) 1400 (UGE (FlagLT_ULT) yes no) -> (First nil no yes) 1401 (UGE (FlagLT_UGT) yes no) -> (First nil yes no) 1402 (UGE (FlagGT_ULT) yes no) -> (First nil no yes) 1403 (UGE (FlagGT_UGT) yes no) -> (First nil yes no) 1404 1405 // Absorb flag constants into SETxx ops. 1406 (SETEQ (FlagEQ)) -> (MOVLconst [1]) 1407 (SETEQ (FlagLT_ULT)) -> (MOVLconst [0]) 1408 (SETEQ (FlagLT_UGT)) -> (MOVLconst [0]) 1409 (SETEQ (FlagGT_ULT)) -> (MOVLconst [0]) 1410 (SETEQ (FlagGT_UGT)) -> (MOVLconst [0]) 1411 1412 (SETNE (FlagEQ)) -> (MOVLconst [0]) 1413 (SETNE (FlagLT_ULT)) -> (MOVLconst [1]) 1414 (SETNE (FlagLT_UGT)) -> (MOVLconst [1]) 1415 (SETNE (FlagGT_ULT)) -> (MOVLconst [1]) 1416 (SETNE (FlagGT_UGT)) -> (MOVLconst [1]) 1417 1418 (SETL (FlagEQ)) -> (MOVLconst [0]) 1419 (SETL (FlagLT_ULT)) -> (MOVLconst [1]) 1420 (SETL (FlagLT_UGT)) -> (MOVLconst [1]) 1421 (SETL (FlagGT_ULT)) -> (MOVLconst [0]) 1422 (SETL (FlagGT_UGT)) -> (MOVLconst [0]) 1423 1424 (SETLE (FlagEQ)) -> (MOVLconst [1]) 1425 (SETLE (FlagLT_ULT)) -> (MOVLconst [1]) 1426 (SETLE (FlagLT_UGT)) -> (MOVLconst [1]) 1427 (SETLE (FlagGT_ULT)) -> (MOVLconst [0]) 1428 (SETLE (FlagGT_UGT)) -> (MOVLconst [0]) 1429 1430 (SETG (FlagEQ)) -> (MOVLconst [0]) 1431 (SETG (FlagLT_ULT)) -> (MOVLconst [0]) 1432 (SETG (FlagLT_UGT)) -> (MOVLconst [0]) 1433 (SETG (FlagGT_ULT)) -> (MOVLconst [1]) 1434 (SETG (FlagGT_UGT)) -> (MOVLconst [1]) 1435 1436 (SETGE (FlagEQ)) -> (MOVLconst [1]) 1437 (SETGE (FlagLT_ULT)) -> (MOVLconst [0]) 1438 (SETGE (FlagLT_UGT)) -> (MOVLconst [0]) 1439 (SETGE (FlagGT_ULT)) -> (MOVLconst [1]) 1440 (SETGE (FlagGT_UGT)) -> (MOVLconst [1]) 1441 1442 (SETB (FlagEQ)) -> (MOVLconst [0]) 1443 (SETB (FlagLT_ULT)) -> (MOVLconst [1]) 1444 (SETB (FlagLT_UGT)) -> (MOVLconst [0]) 1445 (SETB (FlagGT_ULT)) -> (MOVLconst [1]) 1446 (SETB (FlagGT_UGT)) -> (MOVLconst [0]) 1447 1448 (SETBE (FlagEQ)) -> (MOVLconst [1]) 1449 (SETBE (FlagLT_ULT)) -> (MOVLconst [1]) 1450 (SETBE (FlagLT_UGT)) -> (MOVLconst [0]) 1451 (SETBE (FlagGT_ULT)) -> (MOVLconst [1]) 1452 (SETBE (FlagGT_UGT)) -> (MOVLconst [0]) 1453 1454 (SETA (FlagEQ)) -> (MOVLconst [0]) 1455 (SETA (FlagLT_ULT)) -> (MOVLconst [0]) 1456 (SETA (FlagLT_UGT)) -> (MOVLconst [1]) 1457 (SETA (FlagGT_ULT)) -> (MOVLconst [0]) 1458 (SETA (FlagGT_UGT)) -> (MOVLconst [1]) 1459 1460 (SETAE (FlagEQ)) -> (MOVLconst [1]) 1461 (SETAE (FlagLT_ULT)) -> (MOVLconst [0]) 1462 (SETAE (FlagLT_UGT)) -> (MOVLconst [1]) 1463 (SETAE (FlagGT_ULT)) -> (MOVLconst [0]) 1464 (SETAE (FlagGT_UGT)) -> (MOVLconst [1]) 1465 1466 // Remove redundant *const ops 1467 (ADDQconst [0] x) -> x 1468 (ADDLconst [c] x) && int32(c)==0 -> x 1469 (SUBQconst [0] x) -> x 1470 (SUBLconst [c] x) && int32(c) == 0 -> x 1471 (ANDQconst [0] _) -> (MOVQconst [0]) 1472 (ANDLconst [c] _) && int32(c)==0 -> (MOVLconst [0]) 1473 (ANDQconst [-1] x) -> x 1474 (ANDLconst [c] x) && int32(c)==-1 -> x 1475 (ORQconst [0] x) -> x 1476 (ORLconst [c] x) && int32(c)==0 -> x 1477 (ORQconst [-1] _) -> (MOVQconst [-1]) 1478 (ORLconst [c] _) && int32(c)==-1 -> (MOVLconst [-1]) 1479 (XORQconst [0] x) -> x 1480 (XORLconst [c] x) && int32(c)==0 -> x 1481 // TODO: since we got rid of the W/B versions, we might miss 1482 // things like (ANDLconst [0x100] x) which were formerly 1483 // (ANDBconst [0] x). Probably doesn't happen very often. 1484 // If we cared, we might do: 1485 // (ANDLconst <t> [c] x) && t.Size()==1 && int8(x)==0 -> (MOVLconst [0]) 1486 1487 // Convert constant subtracts to constant adds 1488 (SUBQconst [c] x) && c != -(1<<31) -> (ADDQconst [-c] x) 1489 (SUBLconst [c] x) -> (ADDLconst [int64(int32(-c))] x) 1490 1491 // generic constant folding 1492 // TODO: more of this 1493 (ADDQconst [c] (MOVQconst [d])) -> (MOVQconst [c+d]) 1494 (ADDLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c+d))]) 1495 (ADDQconst [c] (ADDQconst [d] x)) && is32Bit(c+d) -> (ADDQconst [c+d] x) 1496 (ADDLconst [c] (ADDLconst [d] x)) -> (ADDLconst [int64(int32(c+d))] x) 1497 (SUBQconst (MOVQconst [d]) [c]) -> (MOVQconst [d-c]) 1498 (SUBQconst (SUBQconst x [d]) [c]) && is32Bit(-c-d) -> (ADDQconst [-c-d] x) 1499 (SARQconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1500 (SARLconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1501 (SARWconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1502 (SARBconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1503 (NEGQ (MOVQconst [c])) -> (MOVQconst [-c]) 1504 (NEGL (MOVLconst [c])) -> (MOVLconst [int64(int32(-c))]) 1505 (MULQconst [c] (MOVQconst [d])) -> (MOVQconst [c*d]) 1506 (MULLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c*d))]) 1507 (ANDQconst [c] (MOVQconst [d])) -> (MOVQconst [c&d]) 1508 (ANDLconst [c] (MOVLconst [d])) -> (MOVLconst [c&d]) 1509 (ORQconst [c] (MOVQconst [d])) -> (MOVQconst [c|d]) 1510 (ORLconst [c] (MOVLconst [d])) -> (MOVLconst [c|d]) 1511 (XORQconst [c] (MOVQconst [d])) -> (MOVQconst [c^d]) 1512 (XORLconst [c] (MOVLconst [d])) -> (MOVLconst [c^d]) 1513 (NOTQ (MOVQconst [c])) -> (MOVQconst [^c]) 1514 (NOTL (MOVLconst [c])) -> (MOVLconst [^c]) 1515 1516 // generic simplifications 1517 // TODO: more of this 1518 (ADDQ x (NEGQ y)) -> (SUBQ x y) 1519 (ADDL x (NEGL y)) -> (SUBL x y) 1520 (SUBQ x x) -> (MOVQconst [0]) 1521 (SUBL x x) -> (MOVLconst [0]) 1522 (ANDQ x x) -> x 1523 (ANDL x x) -> x 1524 (ORQ x x) -> x 1525 (ORL x x) -> x 1526 (XORQ x x) -> (MOVQconst [0]) 1527 (XORL x x) -> (MOVLconst [0]) 1528 (NEGQ (ADDQconst [c] (NEGQ x))) && c != -(1<<31) -> (ADDQconst [-c] x) 1529 1530 // checking AND against 0. 1531 (CMPQconst (ANDQ x y) [0]) -> (TESTQ x y) 1532 (CMPLconst (ANDL x y) [0]) -> (TESTL x y) 1533 (CMPWconst (ANDL x y) [0]) -> (TESTW x y) 1534 (CMPBconst (ANDL x y) [0]) -> (TESTB x y) 1535 (CMPQconst (ANDQconst [c] x) [0]) -> (TESTQconst [c] x) 1536 (CMPLconst (ANDLconst [c] x) [0]) -> (TESTLconst [c] x) 1537 (CMPWconst (ANDLconst [c] x) [0]) -> (TESTWconst [int64(int16(c))] x) 1538 (CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x) 1539 1540 // Convert TESTx to TESTxconst if possible. 1541 (TESTQ (MOVQconst [c]) x) && is32Bit(c) -> (TESTQconst [c] x) 1542 (TESTL (MOVLconst [c]) x) -> (TESTLconst [c] x) 1543 (TESTW (MOVLconst [c]) x) -> (TESTWconst [c] x) 1544 (TESTB (MOVLconst [c]) x) -> (TESTBconst [c] x) 1545 1546 // TEST %reg,%reg is shorter than CMP 1547 (CMPQconst x [0]) -> (TESTQ x x) 1548 (CMPLconst x [0]) -> (TESTL x x) 1549 (CMPWconst x [0]) -> (TESTW x x) 1550 (CMPBconst x [0]) -> (TESTB x x) 1551 1552 // Combining byte loads into larger (unaligned) loads. 1553 // There are many ways these combinations could occur. This is 1554 // designed to match the way encoding/binary.LittleEndian does it. 1555 1556 // Little-endian loads 1557 1558 (ORL x0:(MOVBload [i0] {s} p mem) 1559 sh:(SHLLconst [8] x1:(MOVBload [i1] {s} p mem))) 1560 && i1 == i0+1 1561 && x0.Uses == 1 1562 && x1.Uses == 1 1563 && sh.Uses == 1 1564 && mergePoint(b,x0,x1) != nil 1565 && clobber(x0) 1566 && clobber(x1) 1567 && clobber(sh) 1568 -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 1569 1570 (ORQ x0:(MOVBload [i0] {s} p mem) 1571 sh:(SHLQconst [8] x1:(MOVBload [i1] {s} p mem))) 1572 && i1 == i0+1 1573 && x0.Uses == 1 1574 && x1.Uses == 1 1575 && sh.Uses == 1 1576 && mergePoint(b,x0,x1) != nil 1577 && clobber(x0) 1578 && clobber(x1) 1579 && clobber(sh) 1580 -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 1581 1582 (ORL x0:(MOVWload [i0] {s} p mem) 1583 sh:(SHLLconst [16] x1:(MOVWload [i1] {s} p mem))) 1584 && i1 == i0+2 1585 && x0.Uses == 1 1586 && x1.Uses == 1 1587 && sh.Uses == 1 1588 && mergePoint(b,x0,x1) != nil 1589 && clobber(x0) 1590 && clobber(x1) 1591 && clobber(sh) 1592 -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem) 1593 1594 (ORQ x0:(MOVWload [i0] {s} p mem) 1595 sh:(SHLQconst [16] x1:(MOVWload [i1] {s} p mem))) 1596 && i1 == i0+2 1597 && x0.Uses == 1 1598 && x1.Uses == 1 1599 && sh.Uses == 1 1600 && mergePoint(b,x0,x1) != nil 1601 && clobber(x0) 1602 && clobber(x1) 1603 && clobber(sh) 1604 -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem) 1605 1606 (ORQ x0:(MOVLload [i0] {s} p mem) 1607 sh:(SHLQconst [32] x1:(MOVLload [i1] {s} p mem))) 1608 && i1 == i0+4 1609 && x0.Uses == 1 1610 && x1.Uses == 1 1611 && sh.Uses == 1 1612 && mergePoint(b,x0,x1) != nil 1613 && clobber(x0) 1614 && clobber(x1) 1615 && clobber(sh) 1616 -> @mergePoint(b,x0,x1) (MOVQload [i0] {s} p mem) 1617 1618 (ORL 1619 s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem)) 1620 or:(ORL 1621 s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem)) 1622 y)) 1623 && i1 == i0+1 1624 && j1 == j0+8 1625 && j0 % 16 == 0 1626 && x0.Uses == 1 1627 && x1.Uses == 1 1628 && s0.Uses == 1 1629 && s1.Uses == 1 1630 && or.Uses == 1 1631 && mergePoint(b,x0,x1) != nil 1632 && clobber(x0) 1633 && clobber(x1) 1634 && clobber(s0) 1635 && clobber(s1) 1636 && clobber(or) 1637 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y) 1638 1639 (ORQ 1640 s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem)) 1641 or:(ORQ 1642 s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem)) 1643 y)) 1644 && i1 == i0+1 1645 && j1 == j0+8 1646 && j0 % 16 == 0 1647 && x0.Uses == 1 1648 && x1.Uses == 1 1649 && s0.Uses == 1 1650 && s1.Uses == 1 1651 && or.Uses == 1 1652 && mergePoint(b,x0,x1) != nil 1653 && clobber(x0) 1654 && clobber(x1) 1655 && clobber(s0) 1656 && clobber(s1) 1657 && clobber(or) 1658 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y) 1659 1660 (ORQ 1661 s1:(SHLQconst [j1] x1:(MOVWload [i1] {s} p mem)) 1662 or:(ORQ 1663 s0:(SHLQconst [j0] x0:(MOVWload [i0] {s} p mem)) 1664 y)) 1665 && i1 == i0+2 1666 && j1 == j0+16 1667 && j0 % 32 == 0 1668 && x0.Uses == 1 1669 && x1.Uses == 1 1670 && s0.Uses == 1 1671 && s1.Uses == 1 1672 && or.Uses == 1 1673 && mergePoint(b,x0,x1) != nil 1674 && clobber(x0) 1675 && clobber(x1) 1676 && clobber(s0) 1677 && clobber(s1) 1678 && clobber(or) 1679 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLload [i0] {s} p mem)) y) 1680 1681 // Little-endian indexed loads 1682 1683 (ORL x0:(MOVBloadidx1 [i0] {s} p idx mem) 1684 sh:(SHLLconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem))) 1685 && i1 == i0+1 1686 && x0.Uses == 1 1687 && x1.Uses == 1 1688 && sh.Uses == 1 1689 && mergePoint(b,x0,x1) != nil 1690 && clobber(x0) 1691 && clobber(x1) 1692 && clobber(sh) 1693 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem) 1694 1695 (ORQ x0:(MOVBloadidx1 [i0] {s} p idx mem) 1696 sh:(SHLQconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem))) 1697 && i1 == i0+1 1698 && x0.Uses == 1 1699 && x1.Uses == 1 1700 && sh.Uses == 1 1701 && mergePoint(b,x0,x1) != nil 1702 && clobber(x0) 1703 && clobber(x1) 1704 && clobber(sh) 1705 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem) 1706 1707 (ORL x0:(MOVWloadidx1 [i0] {s} p idx mem) 1708 sh:(SHLLconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1709 && i1 == i0+2 1710 && x0.Uses == 1 1711 && x1.Uses == 1 1712 && sh.Uses == 1 1713 && mergePoint(b,x0,x1) != nil 1714 && clobber(x0) 1715 && clobber(x1) 1716 && clobber(sh) 1717 -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem) 1718 1719 (ORQ x0:(MOVWloadidx1 [i0] {s} p idx mem) 1720 sh:(SHLQconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 1721 && i1 == i0+2 1722 && x0.Uses == 1 1723 && x1.Uses == 1 1724 && sh.Uses == 1 1725 && mergePoint(b,x0,x1) != nil 1726 && clobber(x0) 1727 && clobber(x1) 1728 && clobber(sh) 1729 -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem) 1730 1731 (ORQ x0:(MOVLloadidx1 [i0] {s} p idx mem) 1732 sh:(SHLQconst [32] x1:(MOVLloadidx1 [i1] {s} p idx mem))) 1733 && i1 == i0+4 1734 && x0.Uses == 1 1735 && x1.Uses == 1 1736 && sh.Uses == 1 1737 && mergePoint(b,x0,x1) != nil 1738 && clobber(x0) 1739 && clobber(x1) 1740 && clobber(sh) 1741 -> @mergePoint(b,x0,x1) (MOVQloadidx1 [i0] {s} p idx mem) 1742 1743 (ORL 1744 s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1745 or:(ORL 1746 s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1747 y)) 1748 && i1 == i0+1 1749 && j1 == j0+8 1750 && j0 % 16 == 0 1751 && x0.Uses == 1 1752 && x1.Uses == 1 1753 && s0.Uses == 1 1754 && s1.Uses == 1 1755 && or.Uses == 1 1756 && mergePoint(b,x0,x1) != nil 1757 && clobber(x0) 1758 && clobber(x1) 1759 && clobber(s0) 1760 && clobber(s1) 1761 && clobber(or) 1762 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y) 1763 1764 (ORQ 1765 s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 1766 or:(ORQ 1767 s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 1768 y)) 1769 && i1 == i0+1 1770 && j1 == j0+8 1771 && j0 % 16 == 0 1772 && x0.Uses == 1 1773 && x1.Uses == 1 1774 && s0.Uses == 1 1775 && s1.Uses == 1 1776 && or.Uses == 1 1777 && mergePoint(b,x0,x1) != nil 1778 && clobber(x0) 1779 && clobber(x1) 1780 && clobber(s0) 1781 && clobber(s1) 1782 && clobber(or) 1783 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y) 1784 1785 (ORQ 1786 s1:(SHLQconst [j1] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1787 or:(ORQ 1788 s0:(SHLQconst [j0] x0:(MOVWloadidx1 [i0] {s} p idx mem)) 1789 y)) 1790 && i1 == i0+2 1791 && j1 == j0+16 1792 && j0 % 32 == 0 1793 && x0.Uses == 1 1794 && x1.Uses == 1 1795 && s0.Uses == 1 1796 && s1.Uses == 1 1797 && or.Uses == 1 1798 && mergePoint(b,x0,x1) != nil 1799 && clobber(x0) 1800 && clobber(x1) 1801 && clobber(s0) 1802 && clobber(s1) 1803 && clobber(or) 1804 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLloadidx1 [i0] {s} p idx mem)) y) 1805 1806 // Big-endian loads 1807 1808 (ORL 1809 x1:(MOVBload [i1] {s} p mem) 1810 sh:(SHLLconst [8] x0:(MOVBload [i0] {s} p mem))) 1811 && i1 == i0+1 1812 && x0.Uses == 1 1813 && x1.Uses == 1 1814 && sh.Uses == 1 1815 && mergePoint(b,x0,x1) != nil 1816 && clobber(x0) 1817 && clobber(x1) 1818 && clobber(sh) 1819 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem)) 1820 1821 (ORQ 1822 x1:(MOVBload [i1] {s} p mem) 1823 sh:(SHLQconst [8] x0:(MOVBload [i0] {s} p mem))) 1824 && i1 == i0+1 1825 && x0.Uses == 1 1826 && x1.Uses == 1 1827 && sh.Uses == 1 1828 && mergePoint(b,x0,x1) != nil 1829 && clobber(x0) 1830 && clobber(x1) 1831 && clobber(sh) 1832 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem)) 1833 1834 (ORL 1835 r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)) 1836 sh:(SHLLconst [16] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))) 1837 && i1 == i0+2 1838 && x0.Uses == 1 1839 && x1.Uses == 1 1840 && r0.Uses == 1 1841 && r1.Uses == 1 1842 && sh.Uses == 1 1843 && mergePoint(b,x0,x1) != nil 1844 && clobber(x0) 1845 && clobber(x1) 1846 && clobber(r0) 1847 && clobber(r1) 1848 && clobber(sh) 1849 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem)) 1850 1851 (ORQ 1852 r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)) 1853 sh:(SHLQconst [16] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))) 1854 && i1 == i0+2 1855 && x0.Uses == 1 1856 && x1.Uses == 1 1857 && r0.Uses == 1 1858 && r1.Uses == 1 1859 && sh.Uses == 1 1860 && mergePoint(b,x0,x1) != nil 1861 && clobber(x0) 1862 && clobber(x1) 1863 && clobber(r0) 1864 && clobber(r1) 1865 && clobber(sh) 1866 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem)) 1867 1868 (ORQ 1869 r1:(BSWAPL x1:(MOVLload [i1] {s} p mem)) 1870 sh:(SHLQconst [32] r0:(BSWAPL x0:(MOVLload [i0] {s} p mem)))) 1871 && i1 == i0+4 1872 && x0.Uses == 1 1873 && x1.Uses == 1 1874 && r0.Uses == 1 1875 && r1.Uses == 1 1876 && sh.Uses == 1 1877 && mergePoint(b,x0,x1) != nil 1878 && clobber(x0) 1879 && clobber(x1) 1880 && clobber(r0) 1881 && clobber(r1) 1882 && clobber(sh) 1883 -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQload [i0] {s} p mem)) 1884 1885 (ORL 1886 s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem)) 1887 or:(ORL 1888 s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem)) 1889 y)) 1890 && i1 == i0+1 1891 && j1 == j0-8 1892 && j1 % 16 == 0 1893 && x0.Uses == 1 1894 && x1.Uses == 1 1895 && s0.Uses == 1 1896 && s1.Uses == 1 1897 && or.Uses == 1 1898 && mergePoint(b,x0,x1) != nil 1899 && clobber(x0) 1900 && clobber(x1) 1901 && clobber(s0) 1902 && clobber(s1) 1903 && clobber(or) 1904 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWload [i0] {s} p mem))) y) 1905 1906 (ORQ 1907 s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem)) 1908 or:(ORQ 1909 s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem)) 1910 y)) 1911 && i1 == i0+1 1912 && j1 == j0-8 1913 && j1 % 16 == 0 1914 && x0.Uses == 1 1915 && x1.Uses == 1 1916 && s0.Uses == 1 1917 && s1.Uses == 1 1918 && or.Uses == 1 1919 && mergePoint(b,x0,x1) != nil 1920 && clobber(x0) 1921 && clobber(x1) 1922 && clobber(s0) 1923 && clobber(s1) 1924 && clobber(or) 1925 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWload [i0] {s} p mem))) y) 1926 1927 (ORQ 1928 s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem))) 1929 or:(ORQ 1930 s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem))) 1931 y)) 1932 && i1 == i0+2 1933 && j1 == j0-16 1934 && j1 % 32 == 0 1935 && x0.Uses == 1 1936 && x1.Uses == 1 1937 && r0.Uses == 1 1938 && r1.Uses == 1 1939 && s0.Uses == 1 1940 && s1.Uses == 1 1941 && or.Uses == 1 1942 && mergePoint(b,x0,x1) != nil 1943 && clobber(x0) 1944 && clobber(x1) 1945 && clobber(r0) 1946 && clobber(r1) 1947 && clobber(s0) 1948 && clobber(s1) 1949 && clobber(or) 1950 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <typ.UInt32> (MOVLload [i0] {s} p mem))) y) 1951 1952 // Big-endian indexed loads 1953 1954 (ORL 1955 x1:(MOVBloadidx1 [i1] {s} p idx mem) 1956 sh:(SHLLconst [8] x0:(MOVBloadidx1 [i0] {s} p idx mem))) 1957 && i1 == i0+1 1958 && x0.Uses == 1 1959 && x1.Uses == 1 1960 && sh.Uses == 1 1961 && mergePoint(b,x0,x1) != nil 1962 && clobber(x0) 1963 && clobber(x1) 1964 && clobber(sh) 1965 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem)) 1966 1967 (ORQ 1968 x1:(MOVBloadidx1 [i1] {s} p idx mem) 1969 sh:(SHLQconst [8] x0:(MOVBloadidx1 [i0] {s} p idx mem))) 1970 && i1 == i0+1 1971 && x0.Uses == 1 1972 && x1.Uses == 1 1973 && sh.Uses == 1 1974 && mergePoint(b,x0,x1) != nil 1975 && clobber(x0) 1976 && clobber(x1) 1977 && clobber(sh) 1978 -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem)) 1979 1980 (ORL 1981 r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1982 sh:(SHLLconst [16] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))) 1983 && i1 == i0+2 1984 && x0.Uses == 1 1985 && x1.Uses == 1 1986 && r0.Uses == 1 1987 && r1.Uses == 1 1988 && sh.Uses == 1 1989 && mergePoint(b,x0,x1) != nil 1990 && clobber(x0) 1991 && clobber(x1) 1992 && clobber(r0) 1993 && clobber(r1) 1994 && clobber(sh) 1995 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem)) 1996 1997 (ORQ 1998 r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)) 1999 sh:(SHLQconst [16] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))) 2000 && i1 == i0+2 2001 && x0.Uses == 1 2002 && x1.Uses == 1 2003 && r0.Uses == 1 2004 && r1.Uses == 1 2005 && sh.Uses == 1 2006 && mergePoint(b,x0,x1) != nil 2007 && clobber(x0) 2008 && clobber(x1) 2009 && clobber(r0) 2010 && clobber(r1) 2011 && clobber(sh) 2012 -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem)) 2013 2014 (ORQ 2015 r1:(BSWAPL x1:(MOVLloadidx1 [i1] {s} p idx mem)) 2016 sh:(SHLQconst [32] r0:(BSWAPL x0:(MOVLloadidx1 [i0] {s} p idx mem)))) 2017 && i1 == i0+4 2018 && x0.Uses == 1 2019 && x1.Uses == 1 2020 && r0.Uses == 1 2021 && r1.Uses == 1 2022 && sh.Uses == 1 2023 && mergePoint(b,x0,x1) != nil 2024 && clobber(x0) 2025 && clobber(x1) 2026 && clobber(r0) 2027 && clobber(r1) 2028 && clobber(sh) 2029 -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQloadidx1 [i0] {s} p idx mem)) 2030 2031 (ORL 2032 s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 2033 or:(ORL 2034 s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 2035 y)) 2036 && i1 == i0+1 2037 && j1 == j0-8 2038 && j1 % 16 == 0 2039 && x0.Uses == 1 2040 && x1.Uses == 1 2041 && s0.Uses == 1 2042 && s1.Uses == 1 2043 && or.Uses == 1 2044 && mergePoint(b,x0,x1) != nil 2045 && clobber(x0) 2046 && clobber(x1) 2047 && clobber(s0) 2048 && clobber(s1) 2049 && clobber(or) 2050 -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y) 2051 2052 (ORQ 2053 s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem)) 2054 or:(ORQ 2055 s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem)) 2056 y)) 2057 && i1 == i0+1 2058 && j1 == j0-8 2059 && j1 % 16 == 0 2060 && x0.Uses == 1 2061 && x1.Uses == 1 2062 && s0.Uses == 1 2063 && s1.Uses == 1 2064 && or.Uses == 1 2065 && mergePoint(b,x0,x1) != nil 2066 && clobber(x0) 2067 && clobber(x1) 2068 && clobber(s0) 2069 && clobber(s1) 2070 && clobber(or) 2071 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y) 2072 2073 (ORQ 2074 s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem))) 2075 or:(ORQ 2076 s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem))) 2077 y)) 2078 && i1 == i0+2 2079 && j1 == j0-16 2080 && j1 % 32 == 0 2081 && x0.Uses == 1 2082 && x1.Uses == 1 2083 && r0.Uses == 1 2084 && r1.Uses == 1 2085 && s0.Uses == 1 2086 && s1.Uses == 1 2087 && or.Uses == 1 2088 && mergePoint(b,x0,x1) != nil 2089 && clobber(x0) 2090 && clobber(x1) 2091 && clobber(r0) 2092 && clobber(r1) 2093 && clobber(s0) 2094 && clobber(s1) 2095 && clobber(or) 2096 -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <typ.UInt32> (MOVLloadidx1 [i0] {s} p idx mem))) y) 2097 2098 // Combine 2 byte stores + shift into rolw 8 + word store 2099 (MOVBstore [i] {s} p w 2100 x0:(MOVBstore [i-1] {s} p (SHRWconst [8] w) mem)) 2101 && x0.Uses == 1 2102 && clobber(x0) 2103 -> (MOVWstore [i-1] {s} p (ROLWconst <w.Type> [8] w) mem) 2104 2105 (MOVBstoreidx1 [i] {s} p idx w 2106 x0:(MOVBstoreidx1 [i-1] {s} p idx (SHRWconst [8] w) mem)) 2107 && x0.Uses == 1 2108 && clobber(x0) 2109 -> (MOVWstoreidx1 [i-1] {s} p idx (ROLWconst <w.Type> [8] w) mem) 2110 2111 // Combine stores + shifts into bswap and larger (unaligned) stores 2112 (MOVBstore [i] {s} p w 2113 x2:(MOVBstore [i-1] {s} p (SHRLconst [8] w) 2114 x1:(MOVBstore [i-2] {s} p (SHRLconst [16] w) 2115 x0:(MOVBstore [i-3] {s} p (SHRLconst [24] w) mem)))) 2116 && x0.Uses == 1 2117 && x1.Uses == 1 2118 && x2.Uses == 1 2119 && clobber(x0) 2120 && clobber(x1) 2121 && clobber(x2) 2122 -> (MOVLstore [i-3] {s} p (BSWAPL <w.Type> w) mem) 2123 2124 (MOVBstoreidx1 [i] {s} p idx w 2125 x2:(MOVBstoreidx1 [i-1] {s} p idx (SHRLconst [8] w) 2126 x1:(MOVBstoreidx1 [i-2] {s} p idx (SHRLconst [16] w) 2127 x0:(MOVBstoreidx1 [i-3] {s} p idx (SHRLconst [24] w) mem)))) 2128 && x0.Uses == 1 2129 && x1.Uses == 1 2130 && x2.Uses == 1 2131 && clobber(x0) 2132 && clobber(x1) 2133 && clobber(x2) 2134 -> (MOVLstoreidx1 [i-3] {s} p idx (BSWAPL <w.Type> w) mem) 2135 2136 (MOVBstore [i] {s} p w 2137 x6:(MOVBstore [i-1] {s} p (SHRQconst [8] w) 2138 x5:(MOVBstore [i-2] {s} p (SHRQconst [16] w) 2139 x4:(MOVBstore [i-3] {s} p (SHRQconst [24] w) 2140 x3:(MOVBstore [i-4] {s} p (SHRQconst [32] w) 2141 x2:(MOVBstore [i-5] {s} p (SHRQconst [40] w) 2142 x1:(MOVBstore [i-6] {s} p (SHRQconst [48] w) 2143 x0:(MOVBstore [i-7] {s} p (SHRQconst [56] w) mem)))))))) 2144 && x0.Uses == 1 2145 && x1.Uses == 1 2146 && x2.Uses == 1 2147 && x3.Uses == 1 2148 && x4.Uses == 1 2149 && x5.Uses == 1 2150 && x6.Uses == 1 2151 && clobber(x0) 2152 && clobber(x1) 2153 && clobber(x2) 2154 && clobber(x3) 2155 && clobber(x4) 2156 && clobber(x5) 2157 && clobber(x6) 2158 -> (MOVQstore [i-7] {s} p (BSWAPQ <w.Type> w) mem) 2159 2160 (MOVBstoreidx1 [i] {s} p idx w 2161 x6:(MOVBstoreidx1 [i-1] {s} p idx (SHRQconst [8] w) 2162 x5:(MOVBstoreidx1 [i-2] {s} p idx (SHRQconst [16] w) 2163 x4:(MOVBstoreidx1 [i-3] {s} p idx (SHRQconst [24] w) 2164 x3:(MOVBstoreidx1 [i-4] {s} p idx (SHRQconst [32] w) 2165 x2:(MOVBstoreidx1 [i-5] {s} p idx (SHRQconst [40] w) 2166 x1:(MOVBstoreidx1 [i-6] {s} p idx (SHRQconst [48] w) 2167 x0:(MOVBstoreidx1 [i-7] {s} p idx (SHRQconst [56] w) mem)))))))) 2168 && x0.Uses == 1 2169 && x1.Uses == 1 2170 && x2.Uses == 1 2171 && x3.Uses == 1 2172 && x4.Uses == 1 2173 && x5.Uses == 1 2174 && x6.Uses == 1 2175 && clobber(x0) 2176 && clobber(x1) 2177 && clobber(x2) 2178 && clobber(x3) 2179 && clobber(x4) 2180 && clobber(x5) 2181 && clobber(x6) 2182 -> (MOVQstoreidx1 [i-7] {s} p idx (BSWAPQ <w.Type> w) mem) 2183 2184 // Combine constant stores into larger (unaligned) stores. 2185 (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem)) 2186 && x.Uses == 1 2187 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 2188 && clobber(x) 2189 -> (MOVWstoreconst [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p mem) 2190 (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem)) 2191 && x.Uses == 1 2192 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2193 && clobber(x) 2194 -> (MOVLstoreconst [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p mem) 2195 (MOVLstoreconst [c] {s} p x:(MOVLstoreconst [a] {s} p mem)) 2196 && x.Uses == 1 2197 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2198 && clobber(x) 2199 -> (MOVQstore [ValAndOff(a).Off()] {s} p (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2200 2201 (MOVBstoreconstidx1 [c] {s} p i x:(MOVBstoreconstidx1 [a] {s} p i mem)) 2202 && x.Uses == 1 2203 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 2204 && clobber(x) 2205 -> (MOVWstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p i mem) 2206 (MOVWstoreconstidx1 [c] {s} p i x:(MOVWstoreconstidx1 [a] {s} p i mem)) 2207 && x.Uses == 1 2208 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2209 && clobber(x) 2210 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p i mem) 2211 (MOVLstoreconstidx1 [c] {s} p i x:(MOVLstoreconstidx1 [a] {s} p i mem)) 2212 && x.Uses == 1 2213 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2214 && clobber(x) 2215 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p i (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2216 2217 (MOVWstoreconstidx2 [c] {s} p i x:(MOVWstoreconstidx2 [a] {s} p i mem)) 2218 && x.Uses == 1 2219 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 2220 && clobber(x) 2221 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p (SHLQconst <i.Type> [1] i) mem) 2222 (MOVLstoreconstidx4 [c] {s} p i x:(MOVLstoreconstidx4 [a] {s} p i mem)) 2223 && x.Uses == 1 2224 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 2225 && clobber(x) 2226 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p (SHLQconst <i.Type> [2] i) (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 2227 2228 // Combine stores into larger (unaligned) stores. 2229 (MOVBstore [i] {s} p (SHRQconst [8] w) x:(MOVBstore [i-1] {s} p w mem)) 2230 && x.Uses == 1 2231 && clobber(x) 2232 -> (MOVWstore [i-1] {s} p w mem) 2233 (MOVBstore [i] {s} p (SHRQconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SHRQconst [j-8] w) mem)) 2234 && x.Uses == 1 2235 && clobber(x) 2236 -> (MOVWstore [i-1] {s} p w0 mem) 2237 (MOVWstore [i] {s} p (SHRQconst [16] w) x:(MOVWstore [i-2] {s} p w mem)) 2238 && x.Uses == 1 2239 && clobber(x) 2240 -> (MOVLstore [i-2] {s} p w mem) 2241 (MOVWstore [i] {s} p (SHRQconst [j] w) x:(MOVWstore [i-2] {s} p w0:(SHRQconst [j-16] w) mem)) 2242 && x.Uses == 1 2243 && clobber(x) 2244 -> (MOVLstore [i-2] {s} p w0 mem) 2245 (MOVLstore [i] {s} p (SHRQconst [32] w) x:(MOVLstore [i-4] {s} p w mem)) 2246 && x.Uses == 1 2247 && clobber(x) 2248 -> (MOVQstore [i-4] {s} p w mem) 2249 (MOVLstore [i] {s} p (SHRQconst [j] w) x:(MOVLstore [i-4] {s} p w0:(SHRQconst [j-32] w) mem)) 2250 && x.Uses == 1 2251 && clobber(x) 2252 -> (MOVQstore [i-4] {s} p w0 mem) 2253 2254 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [8] w) x:(MOVBstoreidx1 [i-1] {s} p idx w mem)) 2255 && x.Uses == 1 2256 && clobber(x) 2257 -> (MOVWstoreidx1 [i-1] {s} p idx w mem) 2258 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVBstoreidx1 [i-1] {s} p idx w0:(SHRQconst [j-8] w) mem)) 2259 && x.Uses == 1 2260 && clobber(x) 2261 -> (MOVWstoreidx1 [i-1] {s} p idx w0 mem) 2262 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx1 [i-2] {s} p idx w mem)) 2263 && x.Uses == 1 2264 && clobber(x) 2265 -> (MOVLstoreidx1 [i-2] {s} p idx w mem) 2266 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx1 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 2267 && x.Uses == 1 2268 && clobber(x) 2269 -> (MOVLstoreidx1 [i-2] {s} p idx w0 mem) 2270 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx1 [i-4] {s} p idx w mem)) 2271 && x.Uses == 1 2272 && clobber(x) 2273 -> (MOVQstoreidx1 [i-4] {s} p idx w mem) 2274 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx1 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 2275 && x.Uses == 1 2276 && clobber(x) 2277 -> (MOVQstoreidx1 [i-4] {s} p idx w0 mem) 2278 2279 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx2 [i-2] {s} p idx w mem)) 2280 && x.Uses == 1 2281 && clobber(x) 2282 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w mem) 2283 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx2 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 2284 && x.Uses == 1 2285 && clobber(x) 2286 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w0 mem) 2287 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx4 [i-4] {s} p idx w mem)) 2288 && x.Uses == 1 2289 && clobber(x) 2290 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w mem) 2291 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx4 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 2292 && x.Uses == 1 2293 && clobber(x) 2294 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w0 mem) 2295 2296 // amd64p32 rules 2297 // same as the rules above, but with 32 instead of 64 bit pointer arithmetic. 2298 // LEAQ,ADDQ -> LEAL,ADDL 2299 (ADDLconst [c] (LEAL [d] {s} x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 2300 (LEAL [c] {s} (ADDLconst [d] x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 2301 2302 (MOVQload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2303 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2304 (MOVLload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2305 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2306 (MOVWload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2307 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2308 (MOVBload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 2309 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 2310 2311 (MOVQstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2312 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2313 (MOVLstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2314 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2315 (MOVWstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2316 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2317 (MOVBstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 2318 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 2319 2320 (MOVQstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2321 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2322 (MOVLstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2323 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2324 (MOVWstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2325 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2326 (MOVBstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 2327 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 2328 2329 (MOVQload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 2330 (MOVLload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 2331 (MOVWload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 2332 (MOVBload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 2333 (MOVQstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 2334 (MOVLstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 2335 (MOVWstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 2336 (MOVBstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 2337 (MOVQstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2338 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2339 (MOVLstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2340 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2341 (MOVWstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2342 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2343 (MOVBstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 2344 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 2345 2346 // Merge load and op 2347 // TODO: add indexed variants? 2348 (ADDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDQmem x [off] {sym} ptr mem) 2349 (ADDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDLmem x [off] {sym} ptr mem) 2350 (SUBQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBQmem x [off] {sym} ptr mem) 2351 (SUBL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBLmem x [off] {sym} ptr mem) 2352 (ANDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDQmem x [off] {sym} ptr mem) 2353 (ANDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDLmem x [off] {sym} ptr mem) 2354 (ORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORQmem x [off] {sym} ptr mem) 2355 (ORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORLmem x [off] {sym} ptr mem) 2356 (XORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORQmem x [off] {sym} ptr mem) 2357 (XORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORLmem x [off] {sym} ptr mem) 2358 (ADDSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSDmem x [off] {sym} ptr mem) 2359 (ADDSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSSmem x [off] {sym} ptr mem) 2360 (SUBSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSDmem x [off] {sym} ptr mem) 2361 (SUBSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSSmem x [off] {sym} ptr mem) 2362 (MULSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSDmem x [off] {sym} ptr mem) 2363 (MULSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSSmem x [off] {sym} ptr mem) 2364 2365 // Merge ADDQconst and LEAQ into atomic loads. 2366 (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2367 (MOVQatomicload [off1+off2] {sym} ptr mem) 2368 (MOVLatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2369 (MOVLatomicload [off1+off2] {sym} ptr mem) 2370 (MOVQatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 2371 (MOVQatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 2372 (MOVLatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 2373 (MOVLatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 2374 2375 // Merge ADDQconst and LEAQ into atomic stores. 2376 (XCHGQ [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2377 (XCHGQ [off1+off2] {sym} val ptr mem) 2378 (XCHGQ [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 2379 (XCHGQ [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 2380 (XCHGL [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2381 (XCHGL [off1+off2] {sym} val ptr mem) 2382 (XCHGL [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 2383 (XCHGL [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 2384 2385 // Merge ADDQconst into atomic adds. 2386 // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions. 2387 (XADDQlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2388 (XADDQlock [off1+off2] {sym} val ptr mem) 2389 (XADDLlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 2390 (XADDLlock [off1+off2] {sym} val ptr mem) 2391 2392 // Merge ADDQconst into atomic compare and swaps. 2393 // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions. 2394 (CMPXCHGQlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) -> 2395 (CMPXCHGQlock [off1+off2] {sym} ptr old new_ mem) 2396 (CMPXCHGLlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) -> 2397 (CMPXCHGLlock [off1+off2] {sym} ptr old new_ mem) 2398 2399 // We don't need the conditional move if we know the arg of BSF is not zero. 2400 (CMOVQEQ x _ (Select1 (BSFQ (ORQconst [c] _)))) && c != 0 -> x 2401 // Extension is unnecessary for trailing zeros. 2402 (BSFQ (ORQconst <t> [1<<8] (MOVBQZX x))) -> (BSFQ (ORQconst <t> [1<<8] x)) 2403 (BSFQ (ORQconst <t> [1<<16] (MOVWQZX x))) -> (BSFQ (ORQconst <t> [1<<16] x)) 2404 2405 // Redundant sign/zero extensions 2406 (MOVLQSX x:(MOVLQSX _)) -> x 2407 (MOVLQSX x:(MOVWQSX _)) -> x 2408 (MOVLQSX x:(MOVBQSX _)) -> x 2409 (MOVWQSX x:(MOVWQSX _)) -> x 2410 (MOVWQSX x:(MOVBQSX _)) -> x 2411 (MOVBQSX x:(MOVBQSX _)) -> x 2412 (MOVLQZX x:(MOVLQZX _)) -> x 2413 (MOVLQZX x:(MOVWQZX _)) -> x 2414 (MOVLQZX x:(MOVBQZX _)) -> x 2415 (MOVWQZX x:(MOVWQZX _)) -> x 2416 (MOVWQZX x:(MOVBQZX _)) -> x 2417 (MOVBQZX x:(MOVBQZX _)) -> x