github.com/sbinet/go@v0.0.0-20160827155028-54d7de7dd62b/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 (Hmul16 x y) -> (HMULW x y) 48 (Hmul16u x y) -> (HMULWU x y) 49 (Hmul8 x y) -> (HMULB x y) 50 (Hmul8u x y) -> (HMULBU x y) 51 52 (Avg64u x y) -> (AVGQU x y) 53 54 (Mod64 x y) -> (Select1 (DIVQ x y)) 55 (Mod64u x y) -> (Select1 (DIVQU x y)) 56 (Mod32 x y) -> (Select1 (DIVL x y)) 57 (Mod32u x y) -> (Select1 (DIVLU x y)) 58 (Mod16 x y) -> (Select1 (DIVW x y)) 59 (Mod16u x y) -> (Select1 (DIVWU x y)) 60 (Mod8 x y) -> (Select1 (DIVW (SignExt8to16 x) (SignExt8to16 y))) 61 (Mod8u x y) -> (Select1 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y))) 62 63 (And64 x y) -> (ANDQ x y) 64 (And32 x y) -> (ANDL x y) 65 (And16 x y) -> (ANDL x y) 66 (And8 x y) -> (ANDL x y) 67 68 (Or64 x y) -> (ORQ x y) 69 (Or32 x y) -> (ORL x y) 70 (Or16 x y) -> (ORL x y) 71 (Or8 x y) -> (ORL x y) 72 73 (Xor64 x y) -> (XORQ x y) 74 (Xor32 x y) -> (XORL x y) 75 (Xor16 x y) -> (XORL x y) 76 (Xor8 x y) -> (XORL x y) 77 78 (Neg64 x) -> (NEGQ x) 79 (Neg32 x) -> (NEGL x) 80 (Neg16 x) -> (NEGL x) 81 (Neg8 x) -> (NEGL x) 82 (Neg32F x) -> (PXOR x (MOVSSconst <config.Frontend().TypeFloat32()> [f2i(math.Copysign(0, -1))])) 83 (Neg64F x) -> (PXOR x (MOVSDconst <config.Frontend().TypeFloat64()> [f2i(math.Copysign(0, -1))])) 84 85 (Com64 x) -> (NOTQ x) 86 (Com32 x) -> (NOTL x) 87 (Com16 x) -> (NOTL x) 88 (Com8 x) -> (NOTL x) 89 90 // Lowering boolean ops 91 (AndB x y) -> (ANDL x y) 92 (OrB x y) -> (ORL x y) 93 (Not x) -> (XORLconst [1] x) 94 95 // Lowering pointer arithmetic 96 (OffPtr [off] ptr) && config.PtrSize == 8 && is32Bit(off) -> (ADDQconst [off] ptr) 97 (OffPtr [off] ptr) && config.PtrSize == 8 -> (ADDQ (MOVQconst [off]) ptr) 98 (OffPtr [off] ptr) && config.PtrSize == 4 -> (ADDLconst [off] ptr) 99 100 // Lowering other arithmetic 101 (Ctz64 <t> x) -> (CMOVQEQ (Select0 <t> (BSFQ x)) (MOVQconst <t> [64]) (Select1 <TypeFlags> (BSFQ x))) 102 (Ctz32 <t> x) -> (CMOVLEQ (Select0 <t> (BSFL x)) (MOVLconst <t> [32]) (Select1 <TypeFlags> (BSFL x))) 103 104 (Bswap64 x) -> (BSWAPQ x) 105 (Bswap32 x) -> (BSWAPL x) 106 107 (Sqrt x) -> (SQRTSD x) 108 109 // Lowering extension 110 // Note: we always extend to 64 bits even though some ops don't need that many result bits. 111 (SignExt8to16 x) -> (MOVBQSX x) 112 (SignExt8to32 x) -> (MOVBQSX x) 113 (SignExt8to64 x) -> (MOVBQSX x) 114 (SignExt16to32 x) -> (MOVWQSX x) 115 (SignExt16to64 x) -> (MOVWQSX x) 116 (SignExt32to64 x) -> (MOVLQSX x) 117 118 (ZeroExt8to16 x) -> (MOVBQZX x) 119 (ZeroExt8to32 x) -> (MOVBQZX x) 120 (ZeroExt8to64 x) -> (MOVBQZX x) 121 (ZeroExt16to32 x) -> (MOVWQZX x) 122 (ZeroExt16to64 x) -> (MOVWQZX x) 123 (ZeroExt32to64 x) -> (MOVLQZX x) 124 125 // Lowering truncation 126 // Because we ignore high parts of registers, truncates are just copies. 127 (Trunc16to8 x) -> x 128 (Trunc32to8 x) -> x 129 (Trunc32to16 x) -> x 130 (Trunc64to8 x) -> x 131 (Trunc64to16 x) -> x 132 (Trunc64to32 x) -> x 133 134 // Lowering float <-> int 135 (Cvt32to32F x) -> (CVTSL2SS x) 136 (Cvt32to64F x) -> (CVTSL2SD x) 137 (Cvt64to32F x) -> (CVTSQ2SS x) 138 (Cvt64to64F x) -> (CVTSQ2SD x) 139 140 (Cvt32Fto32 x) -> (CVTTSS2SL x) 141 (Cvt32Fto64 x) -> (CVTTSS2SQ x) 142 (Cvt64Fto32 x) -> (CVTTSD2SL x) 143 (Cvt64Fto64 x) -> (CVTTSD2SQ x) 144 145 (Cvt32Fto64F x) -> (CVTSS2SD x) 146 (Cvt64Fto32F x) -> (CVTSD2SS x) 147 148 // Lowering shifts 149 // Unsigned shifts need to return 0 if shift amount is >= width of shifted value. 150 // result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff) 151 (Lsh64x64 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPQconst y [64]))) 152 (Lsh64x32 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPLconst y [64]))) 153 (Lsh64x16 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPWconst y [64]))) 154 (Lsh64x8 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPBconst y [64]))) 155 156 (Lsh32x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 157 (Lsh32x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 158 (Lsh32x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 159 (Lsh32x8 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 160 161 (Lsh16x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 162 (Lsh16x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 163 (Lsh16x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 164 (Lsh16x8 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 165 166 (Lsh8x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 167 (Lsh8x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 168 (Lsh8x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 169 (Lsh8x8 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 170 171 (Lrot64 <t> x [c]) -> (ROLQconst <t> [c&63] x) 172 (Lrot32 <t> x [c]) -> (ROLLconst <t> [c&31] x) 173 (Lrot16 <t> x [c]) -> (ROLWconst <t> [c&15] x) 174 (Lrot8 <t> x [c]) -> (ROLBconst <t> [c&7] x) 175 176 (Rsh64Ux64 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPQconst y [64]))) 177 (Rsh64Ux32 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPLconst y [64]))) 178 (Rsh64Ux16 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPWconst y [64]))) 179 (Rsh64Ux8 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPBconst y [64]))) 180 181 (Rsh32Ux64 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32]))) 182 (Rsh32Ux32 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32]))) 183 (Rsh32Ux16 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32]))) 184 (Rsh32Ux8 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32]))) 185 186 (Rsh16Ux64 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPQconst y [16]))) 187 (Rsh16Ux32 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPLconst y [16]))) 188 (Rsh16Ux16 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPWconst y [16]))) 189 (Rsh16Ux8 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPBconst y [16]))) 190 191 (Rsh8Ux64 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPQconst y [8]))) 192 (Rsh8Ux32 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPLconst y [8]))) 193 (Rsh8Ux16 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPWconst y [8]))) 194 (Rsh8Ux8 <t> x y) -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPBconst y [8]))) 195 196 // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value. 197 // We implement this by setting the shift value to -1 (all ones) if the shift value is >= width. 198 (Rsh64x64 <t> x y) -> (SARQ <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [64]))))) 199 (Rsh64x32 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [64]))))) 200 (Rsh64x16 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [64]))))) 201 (Rsh64x8 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [64]))))) 202 203 (Rsh32x64 <t> x y) -> (SARL <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [32]))))) 204 (Rsh32x32 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [32]))))) 205 (Rsh32x16 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [32]))))) 206 (Rsh32x8 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [32]))))) 207 208 (Rsh16x64 <t> x y) -> (SARW <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [16]))))) 209 (Rsh16x32 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [16]))))) 210 (Rsh16x16 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [16]))))) 211 (Rsh16x8 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [16]))))) 212 213 (Rsh8x64 <t> x y) -> (SARB <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [8]))))) 214 (Rsh8x32 <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [8]))))) 215 (Rsh8x16 <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [8]))))) 216 (Rsh8x8 <t> x y) -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [8]))))) 217 218 // Lowering comparisons 219 (Less64 x y) -> (SETL (CMPQ x y)) 220 (Less32 x y) -> (SETL (CMPL x y)) 221 (Less16 x y) -> (SETL (CMPW x y)) 222 (Less8 x y) -> (SETL (CMPB x y)) 223 (Less64U x y) -> (SETB (CMPQ x y)) 224 (Less32U x y) -> (SETB (CMPL x y)) 225 (Less16U x y) -> (SETB (CMPW x y)) 226 (Less8U x y) -> (SETB (CMPB x y)) 227 // Use SETGF with reversed operands to dodge NaN case 228 (Less64F x y) -> (SETGF (UCOMISD y x)) 229 (Less32F x y) -> (SETGF (UCOMISS y x)) 230 231 (Leq64 x y) -> (SETLE (CMPQ x y)) 232 (Leq32 x y) -> (SETLE (CMPL x y)) 233 (Leq16 x y) -> (SETLE (CMPW x y)) 234 (Leq8 x y) -> (SETLE (CMPB x y)) 235 (Leq64U x y) -> (SETBE (CMPQ x y)) 236 (Leq32U x y) -> (SETBE (CMPL x y)) 237 (Leq16U x y) -> (SETBE (CMPW x y)) 238 (Leq8U x y) -> (SETBE (CMPB x y)) 239 // Use SETGEF with reversed operands to dodge NaN case 240 (Leq64F x y) -> (SETGEF (UCOMISD y x)) 241 (Leq32F x y) -> (SETGEF (UCOMISS y x)) 242 243 (Greater64 x y) -> (SETG (CMPQ x y)) 244 (Greater32 x y) -> (SETG (CMPL x y)) 245 (Greater16 x y) -> (SETG (CMPW x y)) 246 (Greater8 x y) -> (SETG (CMPB x y)) 247 (Greater64U x y) -> (SETA (CMPQ x y)) 248 (Greater32U x y) -> (SETA (CMPL x y)) 249 (Greater16U x y) -> (SETA (CMPW x y)) 250 (Greater8U x y) -> (SETA (CMPB x y)) 251 // Note Go assembler gets UCOMISx operand order wrong, but it is right here 252 // Bug is accommodated at generation of assembly language. 253 (Greater64F x y) -> (SETGF (UCOMISD x y)) 254 (Greater32F x y) -> (SETGF (UCOMISS x y)) 255 256 (Geq64 x y) -> (SETGE (CMPQ x y)) 257 (Geq32 x y) -> (SETGE (CMPL x y)) 258 (Geq16 x y) -> (SETGE (CMPW x y)) 259 (Geq8 x y) -> (SETGE (CMPB x y)) 260 (Geq64U x y) -> (SETAE (CMPQ x y)) 261 (Geq32U x y) -> (SETAE (CMPL x y)) 262 (Geq16U x y) -> (SETAE (CMPW x y)) 263 (Geq8U x y) -> (SETAE (CMPB x y)) 264 // Note Go assembler gets UCOMISx operand order wrong, but it is right here 265 // Bug is accommodated at generation of assembly language. 266 (Geq64F x y) -> (SETGEF (UCOMISD x y)) 267 (Geq32F x y) -> (SETGEF (UCOMISS x y)) 268 269 (Eq64 x y) -> (SETEQ (CMPQ x y)) 270 (Eq32 x y) -> (SETEQ (CMPL x y)) 271 (Eq16 x y) -> (SETEQ (CMPW x y)) 272 (Eq8 x y) -> (SETEQ (CMPB x y)) 273 (EqB x y) -> (SETEQ (CMPB x y)) 274 (EqPtr x y) && config.PtrSize == 8 -> (SETEQ (CMPQ x y)) 275 (EqPtr x y) && config.PtrSize == 4 -> (SETEQ (CMPL x y)) 276 (Eq64F x y) -> (SETEQF (UCOMISD x y)) 277 (Eq32F x y) -> (SETEQF (UCOMISS x y)) 278 279 (Neq64 x y) -> (SETNE (CMPQ x y)) 280 (Neq32 x y) -> (SETNE (CMPL x y)) 281 (Neq16 x y) -> (SETNE (CMPW x y)) 282 (Neq8 x y) -> (SETNE (CMPB x y)) 283 (NeqB x y) -> (SETNE (CMPB x y)) 284 (NeqPtr x y) && config.PtrSize == 8 -> (SETNE (CMPQ x y)) 285 (NeqPtr x y) && config.PtrSize == 4 -> (SETNE (CMPL x y)) 286 (Neq64F x y) -> (SETNEF (UCOMISD x y)) 287 (Neq32F x y) -> (SETNEF (UCOMISS x y)) 288 289 (Int64Hi x) -> (SHRQconst [32] x) // needed for amd64p32 290 291 // Lowering loads 292 (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t) && config.PtrSize == 8) -> (MOVQload ptr mem) 293 (Load <t> ptr mem) && (is32BitInt(t) || isPtr(t) && config.PtrSize == 4) -> (MOVLload ptr mem) 294 (Load <t> ptr mem) && is16BitInt(t) -> (MOVWload ptr mem) 295 (Load <t> ptr mem) && (t.IsBoolean() || is8BitInt(t)) -> (MOVBload ptr mem) 296 (Load <t> ptr mem) && is32BitFloat(t) -> (MOVSSload ptr mem) 297 (Load <t> ptr mem) && is64BitFloat(t) -> (MOVSDload ptr mem) 298 299 // Lowering stores 300 // These more-specific FP versions of Store pattern should come first. 301 (Store [8] ptr val mem) && is64BitFloat(val.Type) -> (MOVSDstore ptr val mem) 302 (Store [4] ptr val mem) && is32BitFloat(val.Type) -> (MOVSSstore ptr val mem) 303 304 (Store [8] ptr val mem) -> (MOVQstore ptr val mem) 305 (Store [4] ptr val mem) -> (MOVLstore ptr val mem) 306 (Store [2] ptr val mem) -> (MOVWstore ptr val mem) 307 (Store [1] ptr val mem) -> (MOVBstore ptr val mem) 308 309 // Lowering moves 310 (Move [s] _ _ mem) && SizeAndAlign(s).Size() == 0 -> mem 311 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 1 -> (MOVBstore dst (MOVBload src mem) mem) 312 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 2 -> (MOVWstore dst (MOVWload src mem) mem) 313 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 4 -> (MOVLstore dst (MOVLload src mem) mem) 314 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 8 -> (MOVQstore dst (MOVQload src mem) mem) 315 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 16 -> (MOVOstore dst (MOVOload src mem) mem) 316 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 3 -> 317 (MOVBstore [2] dst (MOVBload [2] src mem) 318 (MOVWstore dst (MOVWload src mem) mem)) 319 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 5 -> 320 (MOVBstore [4] dst (MOVBload [4] src mem) 321 (MOVLstore dst (MOVLload src mem) mem)) 322 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 6 -> 323 (MOVWstore [4] dst (MOVWload [4] src mem) 324 (MOVLstore dst (MOVLload src mem) mem)) 325 (Move [s] dst src mem) && SizeAndAlign(s).Size() == 7 -> 326 (MOVLstore [3] dst (MOVLload [3] src mem) 327 (MOVLstore dst (MOVLload src mem) mem)) 328 (Move [s] dst src mem) && SizeAndAlign(s).Size() > 8 && SizeAndAlign(s).Size() < 16 -> 329 (MOVQstore [SizeAndAlign(s).Size()-8] dst (MOVQload [SizeAndAlign(s).Size()-8] src mem) 330 (MOVQstore dst (MOVQload src mem) mem)) 331 332 // Adjust moves to be a multiple of 16 bytes. 333 (Move [s] dst src mem) 334 && SizeAndAlign(s).Size() > 16 && SizeAndAlign(s).Size()%16 != 0 && SizeAndAlign(s).Size()%16 <= 8 -> 335 (Move [SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%16] 336 (OffPtr <dst.Type> dst [SizeAndAlign(s).Size()%16]) 337 (OffPtr <src.Type> src [SizeAndAlign(s).Size()%16]) 338 (MOVQstore dst (MOVQload src mem) mem)) 339 (Move [s] dst src mem) 340 && SizeAndAlign(s).Size() > 16 && SizeAndAlign(s).Size()%16 != 0 && SizeAndAlign(s).Size()%16 > 8 -> 341 (Move [SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%16] 342 (OffPtr <dst.Type> dst [SizeAndAlign(s).Size()%16]) 343 (OffPtr <src.Type> src [SizeAndAlign(s).Size()%16]) 344 (MOVOstore dst (MOVOload src mem) mem)) 345 346 // Medium copying uses a duff device. 347 (Move [s] dst src mem) 348 && SizeAndAlign(s).Size() >= 32 && SizeAndAlign(s).Size() <= 16*64 && SizeAndAlign(s).Size()%16 == 0 349 && !config.noDuffDevice -> 350 (DUFFCOPY [14*(64-SizeAndAlign(s).Size()/16)] dst src mem) 351 // 14 and 64 are magic constants. 14 is the number of bytes to encode: 352 // MOVUPS (SI), X0 353 // ADDQ $16, SI 354 // MOVUPS X0, (DI) 355 // ADDQ $16, DI 356 // and 64 is the number of such blocks. See src/runtime/duff_amd64.s:duffcopy. 357 358 // Large copying uses REP MOVSQ. 359 (Move [s] dst src mem) && (SizeAndAlign(s).Size() > 16*64 || config.noDuffDevice) && SizeAndAlign(s).Size()%8 == 0 -> 360 (REPMOVSQ dst src (MOVQconst [SizeAndAlign(s).Size()/8]) mem) 361 362 // Lowering Zero instructions 363 (Zero [s] _ mem) && SizeAndAlign(s).Size() == 0 -> mem 364 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 1 -> (MOVBstoreconst [0] destptr mem) 365 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 2 -> (MOVWstoreconst [0] destptr mem) 366 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 4 -> (MOVLstoreconst [0] destptr mem) 367 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 8 -> (MOVQstoreconst [0] destptr mem) 368 369 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 3 -> 370 (MOVBstoreconst [makeValAndOff(0,2)] destptr 371 (MOVWstoreconst [0] destptr mem)) 372 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 5 -> 373 (MOVBstoreconst [makeValAndOff(0,4)] destptr 374 (MOVLstoreconst [0] destptr mem)) 375 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 6 -> 376 (MOVWstoreconst [makeValAndOff(0,4)] destptr 377 (MOVLstoreconst [0] destptr mem)) 378 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 7 -> 379 (MOVLstoreconst [makeValAndOff(0,3)] destptr 380 (MOVLstoreconst [0] destptr mem)) 381 382 // Strip off any fractional word zeroing. 383 (Zero [s] destptr mem) && SizeAndAlign(s).Size()%8 != 0 && SizeAndAlign(s).Size() > 8 -> 384 (Zero [SizeAndAlign(s).Size()-SizeAndAlign(s).Size()%8] (OffPtr <destptr.Type> destptr [SizeAndAlign(s).Size()%8]) 385 (MOVQstoreconst [0] destptr mem)) 386 387 // Zero small numbers of words directly. 388 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 16 -> 389 (MOVQstoreconst [makeValAndOff(0,8)] destptr 390 (MOVQstoreconst [0] destptr mem)) 391 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 24 -> 392 (MOVQstoreconst [makeValAndOff(0,16)] destptr 393 (MOVQstoreconst [makeValAndOff(0,8)] destptr 394 (MOVQstoreconst [0] destptr mem))) 395 (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 32 -> 396 (MOVQstoreconst [makeValAndOff(0,24)] destptr 397 (MOVQstoreconst [makeValAndOff(0,16)] destptr 398 (MOVQstoreconst [makeValAndOff(0,8)] destptr 399 (MOVQstoreconst [0] destptr mem)))) 400 401 // Medium zeroing uses a duff device. 402 (Zero [s] destptr mem) 403 && SizeAndAlign(s).Size() <= 1024 && SizeAndAlign(s).Size()%8 == 0 && SizeAndAlign(s).Size()%16 != 0 404 && !config.noDuffDevice -> 405 (Zero [SizeAndAlign(s).Size()-8] (OffPtr <destptr.Type> [8] destptr) (MOVQstore destptr (MOVQconst [0]) mem)) 406 (Zero [s] destptr mem) 407 && SizeAndAlign(s).Size() <= 1024 && SizeAndAlign(s).Size()%16 == 0 && !config.noDuffDevice -> 408 (DUFFZERO [SizeAndAlign(s).Size()] destptr (MOVOconst [0]) mem) 409 410 // Large zeroing uses REP STOSQ. 411 (Zero [s] destptr mem) 412 && (SizeAndAlign(s).Size() > 1024 || (config.noDuffDevice && SizeAndAlign(s).Size() > 32)) 413 && SizeAndAlign(s).Size()%8 == 0 -> 414 (REPSTOSQ destptr (MOVQconst [SizeAndAlign(s).Size()/8]) (MOVQconst [0]) mem) 415 416 // Lowering constants 417 (Const8 [val]) -> (MOVLconst [val]) 418 (Const16 [val]) -> (MOVLconst [val]) 419 (Const32 [val]) -> (MOVLconst [val]) 420 (Const64 [val]) -> (MOVQconst [val]) 421 (Const32F [val]) -> (MOVSSconst [val]) 422 (Const64F [val]) -> (MOVSDconst [val]) 423 (ConstNil) && config.PtrSize == 8 -> (MOVQconst [0]) 424 (ConstNil) && config.PtrSize == 4 -> (MOVLconst [0]) 425 (ConstBool [b]) -> (MOVLconst [b]) 426 427 // Lowering calls 428 (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem) 429 (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem) 430 (DeferCall [argwid] mem) -> (CALLdefer [argwid] mem) 431 (GoCall [argwid] mem) -> (CALLgo [argwid] mem) 432 (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem) 433 434 // Miscellaneous 435 (Convert <t> x mem) && config.PtrSize == 8 -> (MOVQconvert <t> x mem) 436 (Convert <t> x mem) && config.PtrSize == 4 -> (MOVLconvert <t> x mem) 437 (IsNonNil p) && config.PtrSize == 8 -> (SETNE (TESTQ p p)) 438 (IsNonNil p) && config.PtrSize == 4 -> (SETNE (TESTL p p)) 439 (IsInBounds idx len) -> (SETB (CMPQ idx len)) 440 (IsSliceInBounds idx len) -> (SETBE (CMPQ idx len)) 441 (NilCheck ptr mem) -> (LoweredNilCheck ptr mem) 442 (GetG mem) -> (LoweredGetG mem) 443 (GetClosurePtr) -> (LoweredGetClosurePtr) 444 (Addr {sym} base) && config.PtrSize == 8 -> (LEAQ {sym} base) 445 (Addr {sym} base) && config.PtrSize == 4 -> (LEAL {sym} base) 446 447 // block rewrites 448 (If (SETL cmp) yes no) -> (LT cmp yes no) 449 (If (SETLE cmp) yes no) -> (LE cmp yes no) 450 (If (SETG cmp) yes no) -> (GT cmp yes no) 451 (If (SETGE cmp) yes no) -> (GE cmp yes no) 452 (If (SETEQ cmp) yes no) -> (EQ cmp yes no) 453 (If (SETNE cmp) yes no) -> (NE cmp yes no) 454 (If (SETB cmp) yes no) -> (ULT cmp yes no) 455 (If (SETBE cmp) yes no) -> (ULE cmp yes no) 456 (If (SETA cmp) yes no) -> (UGT cmp yes no) 457 (If (SETAE cmp) yes no) -> (UGE cmp yes no) 458 459 // Special case for floating point - LF/LEF not generated 460 (If (SETGF cmp) yes no) -> (UGT cmp yes no) 461 (If (SETGEF cmp) yes no) -> (UGE cmp yes no) 462 (If (SETEQF cmp) yes no) -> (EQF cmp yes no) 463 (If (SETNEF cmp) yes no) -> (NEF cmp yes no) 464 465 (If cond yes no) -> (NE (TESTB cond cond) yes no) 466 467 // Atomic loads. Other than preserving their ordering with respect to other loads, nothing special here. 468 (AtomicLoad32 ptr mem) -> (MOVLatomicload ptr mem) 469 (AtomicLoad64 ptr mem) -> (MOVQatomicload ptr mem) 470 (AtomicLoadPtr ptr mem) && config.PtrSize == 8 -> (MOVQatomicload ptr mem) 471 (AtomicLoadPtr ptr mem) && config.PtrSize == 4 -> (MOVLatomicload ptr mem) 472 473 // Atomic stores. We use XCHG to prevent the hardware reordering a subsequent load. 474 // TODO: most runtime uses of atomic stores don't need that property. Use normal stores for those? 475 (AtomicStore32 ptr val mem) -> (Select1 (XCHGL <MakeTuple(config.Frontend().TypeUInt32(),TypeMem)> val ptr mem)) 476 (AtomicStore64 ptr val mem) -> (Select1 (XCHGQ <MakeTuple(config.Frontend().TypeUInt64(),TypeMem)> val ptr mem)) 477 (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 8 -> (Select1 (XCHGQ <MakeTuple(config.Frontend().TypeBytePtr(),TypeMem)> val ptr mem)) 478 (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 4 -> (Select1 (XCHGL <MakeTuple(config.Frontend().TypeBytePtr(),TypeMem)> val ptr mem)) 479 480 // *************************** 481 // Above: lowering rules 482 // Below: optimizations 483 // *************************** 484 // TODO: Should the optimizations be a separate pass? 485 486 // Fold boolean tests into blocks 487 (NE (TESTB (SETL cmp) (SETL cmp)) yes no) -> (LT cmp yes no) 488 (NE (TESTB (SETLE cmp) (SETLE cmp)) yes no) -> (LE cmp yes no) 489 (NE (TESTB (SETG cmp) (SETG cmp)) yes no) -> (GT cmp yes no) 490 (NE (TESTB (SETGE cmp) (SETGE cmp)) yes no) -> (GE cmp yes no) 491 (NE (TESTB (SETEQ cmp) (SETEQ cmp)) yes no) -> (EQ cmp yes no) 492 (NE (TESTB (SETNE cmp) (SETNE cmp)) yes no) -> (NE cmp yes no) 493 (NE (TESTB (SETB cmp) (SETB cmp)) yes no) -> (ULT cmp yes no) 494 (NE (TESTB (SETBE cmp) (SETBE cmp)) yes no) -> (ULE cmp yes no) 495 (NE (TESTB (SETA cmp) (SETA cmp)) yes no) -> (UGT cmp yes no) 496 (NE (TESTB (SETAE cmp) (SETAE cmp)) yes no) -> (UGE cmp yes no) 497 498 // Special case for floating point - LF/LEF not generated 499 (NE (TESTB (SETGF cmp) (SETGF cmp)) yes no) -> (UGT cmp yes no) 500 (NE (TESTB (SETGEF cmp) (SETGEF cmp)) yes no) -> (UGE cmp yes no) 501 (NE (TESTB (SETEQF cmp) (SETEQF cmp)) yes no) -> (EQF cmp yes no) 502 (NE (TESTB (SETNEF cmp) (SETNEF cmp)) yes no) -> (NEF cmp yes no) 503 504 // Disabled because it interferes with the pattern match above and makes worse code. 505 // (SETNEF x) -> (ORQ (SETNE <config.Frontend().TypeInt8()> x) (SETNAN <config.Frontend().TypeInt8()> x)) 506 // (SETEQF x) -> (ANDQ (SETEQ <config.Frontend().TypeInt8()> x) (SETORD <config.Frontend().TypeInt8()> x)) 507 508 // fold constants into instructions 509 (ADDQ x (MOVQconst [c])) && is32Bit(c) -> (ADDQconst [c] x) 510 (ADDQ (MOVQconst [c]) x) && is32Bit(c) -> (ADDQconst [c] x) 511 (ADDL x (MOVLconst [c])) -> (ADDLconst [c] x) 512 (ADDL (MOVLconst [c]) x) -> (ADDLconst [c] x) 513 514 (SUBQ x (MOVQconst [c])) && is32Bit(c) -> (SUBQconst x [c]) 515 (SUBQ (MOVQconst [c]) x) && is32Bit(c) -> (NEGQ (SUBQconst <v.Type> x [c])) 516 (SUBL x (MOVLconst [c])) -> (SUBLconst x [c]) 517 (SUBL (MOVLconst [c]) x) -> (NEGL (SUBLconst <v.Type> x [c])) 518 519 (MULQ x (MOVQconst [c])) && is32Bit(c) -> (MULQconst [c] x) 520 (MULQ (MOVQconst [c]) x) && is32Bit(c) -> (MULQconst [c] x) 521 (MULL x (MOVLconst [c])) -> (MULLconst [c] x) 522 (MULL (MOVLconst [c]) x) -> (MULLconst [c] x) 523 524 (ANDQ x (MOVQconst [c])) && is32Bit(c) -> (ANDQconst [c] x) 525 (ANDQ (MOVQconst [c]) x) && is32Bit(c) -> (ANDQconst [c] x) 526 (ANDL x (MOVLconst [c])) -> (ANDLconst [c] x) 527 (ANDL (MOVLconst [c]) x) -> (ANDLconst [c] x) 528 529 (ANDLconst [c] (ANDLconst [d] x)) -> (ANDLconst [c & d] x) 530 (ANDQconst [c] (ANDQconst [d] x)) -> (ANDQconst [c & d] x) 531 532 (XORLconst [c] (XORLconst [d] x)) -> (XORLconst [c ^ d] x) 533 (XORQconst [c] (XORQconst [d] x)) -> (XORQconst [c ^ d] x) 534 535 (MULLconst [c] (MULLconst [d] x)) -> (MULLconst [int64(int32(c * d))] x) 536 (MULQconst [c] (MULQconst [d] x)) && is32Bit(c*d) -> (MULQconst [c * d] x) 537 538 (ORQ x (MOVQconst [c])) && is32Bit(c) -> (ORQconst [c] x) 539 (ORQ (MOVQconst [c]) x) && is32Bit(c) -> (ORQconst [c] x) 540 (ORL x (MOVLconst [c])) -> (ORLconst [c] x) 541 (ORL (MOVLconst [c]) x) -> (ORLconst [c] x) 542 543 (XORQ x (MOVQconst [c])) && is32Bit(c) -> (XORQconst [c] x) 544 (XORQ (MOVQconst [c]) x) && is32Bit(c) -> (XORQconst [c] x) 545 (XORL x (MOVLconst [c])) -> (XORLconst [c] x) 546 (XORL (MOVLconst [c]) x) -> (XORLconst [c] x) 547 548 (SHLQ x (MOVQconst [c])) -> (SHLQconst [c&63] x) 549 (SHLQ x (MOVLconst [c])) -> (SHLQconst [c&63] x) 550 551 (SHLL x (MOVQconst [c])) -> (SHLLconst [c&31] x) 552 (SHLL x (MOVLconst [c])) -> (SHLLconst [c&31] x) 553 554 (SHRQ x (MOVQconst [c])) -> (SHRQconst [c&63] x) 555 (SHRQ x (MOVLconst [c])) -> (SHRQconst [c&63] x) 556 557 (SHRL x (MOVQconst [c])) -> (SHRLconst [c&31] x) 558 (SHRL x (MOVLconst [c])) -> (SHRLconst [c&31] x) 559 560 (SHRW x (MOVQconst [c])) -> (SHRWconst [c&31] x) 561 (SHRW x (MOVLconst [c])) -> (SHRWconst [c&31] x) 562 563 (SHRB x (MOVQconst [c])) -> (SHRBconst [c&31] x) 564 (SHRB x (MOVLconst [c])) -> (SHRBconst [c&31] x) 565 566 (SARQ x (MOVQconst [c])) -> (SARQconst [c&63] x) 567 (SARQ x (MOVLconst [c])) -> (SARQconst [c&63] x) 568 569 (SARL x (MOVQconst [c])) -> (SARLconst [c&31] x) 570 (SARL x (MOVLconst [c])) -> (SARLconst [c&31] x) 571 572 (SARW x (MOVQconst [c])) -> (SARWconst [c&31] x) 573 (SARW x (MOVLconst [c])) -> (SARWconst [c&31] x) 574 575 (SARB x (MOVQconst [c])) -> (SARBconst [c&31] x) 576 (SARB x (MOVLconst [c])) -> (SARBconst [c&31] x) 577 578 (SARL x (ANDLconst [31] y)) -> (SARL x y) 579 (SARQ x (ANDQconst [63] y)) -> (SARQ x y) 580 581 (SHLL x (ANDLconst [31] y)) -> (SHLL x y) 582 (SHLQ x (ANDQconst [63] y)) -> (SHLQ x y) 583 584 (SHRL x (ANDLconst [31] y)) -> (SHRL x y) 585 (SHRQ x (ANDQconst [63] y)) -> (SHRQ x y) 586 587 (ROLQconst [c] (ROLQconst [d] x)) -> (ROLQconst [(c+d)&63] x) 588 (ROLLconst [c] (ROLLconst [d] x)) -> (ROLLconst [(c+d)&31] x) 589 (ROLWconst [c] (ROLWconst [d] x)) -> (ROLWconst [(c+d)&15] x) 590 (ROLBconst [c] (ROLBconst [d] x)) -> (ROLBconst [(c+d)& 7] x) 591 592 (ROLQconst [0] x) -> x 593 (ROLLconst [0] x) -> x 594 (ROLWconst [0] x) -> x 595 (ROLBconst [0] x) -> x 596 597 // Note: the word and byte shifts keep the low 5 bits (not the low 4 or 3 bits) 598 // because the x86 instructions are defined to use all 5 bits of the shift even 599 // for the small shifts. I don't think we'll ever generate a weird shift (e.g. 600 // (SHRW x (MOVLconst [24])), but just in case. 601 602 (CMPQ x (MOVQconst [c])) && is32Bit(c) -> (CMPQconst x [c]) 603 (CMPQ (MOVQconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPQconst x [c])) 604 (CMPL x (MOVLconst [c])) -> (CMPLconst x [c]) 605 (CMPL (MOVLconst [c]) x) -> (InvertFlags (CMPLconst x [c])) 606 (CMPW x (MOVLconst [c])) -> (CMPWconst x [int64(int16(c))]) 607 (CMPW (MOVLconst [c]) x) -> (InvertFlags (CMPWconst x [int64(int16(c))])) 608 (CMPB x (MOVLconst [c])) -> (CMPBconst x [int64(int8(c))]) 609 (CMPB (MOVLconst [c]) x) -> (InvertFlags (CMPBconst x [int64(int8(c))])) 610 611 // Using MOVBQZX instead of ANDQ is cheaper. 612 (ANDQconst [0xFF] x) -> (MOVBQZX x) 613 (ANDQconst [0xFFFF] x) -> (MOVWQZX x) 614 (ANDQconst [0xFFFFFFFF] x) -> (MOVLQZX x) 615 616 // strength reduction 617 // Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf: 618 // 1 - addq, shlq, leaq, negq 619 // 3 - imulq 620 // This limits the rewrites to two instructions. 621 // TODO: 27, 81 622 (MULQconst [-1] x) -> (NEGQ x) 623 (MULQconst [0] _) -> (MOVQconst [0]) 624 (MULQconst [1] x) -> x 625 (MULQconst [3] x) -> (LEAQ2 x x) 626 (MULQconst [5] x) -> (LEAQ4 x x) 627 (MULQconst [7] x) -> (LEAQ8 (NEGQ <v.Type> x) x) 628 (MULQconst [9] x) -> (LEAQ8 x x) 629 (MULQconst [11] x) -> (LEAQ2 x (LEAQ4 <v.Type> x x)) 630 (MULQconst [13] x) -> (LEAQ4 x (LEAQ2 <v.Type> x x)) 631 (MULQconst [21] x) -> (LEAQ4 x (LEAQ4 <v.Type> x x)) 632 (MULQconst [25] x) -> (LEAQ8 x (LEAQ2 <v.Type> x x)) 633 (MULQconst [37] x) -> (LEAQ4 x (LEAQ8 <v.Type> x x)) 634 (MULQconst [41] x) -> (LEAQ8 x (LEAQ4 <v.Type> x x)) 635 (MULQconst [73] x) -> (LEAQ8 x (LEAQ8 <v.Type> x x)) 636 637 (MULQconst [c] x) && isPowerOfTwo(c) -> (SHLQconst [log2(c)] x) 638 (MULQconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUBQ (SHLQconst <v.Type> [log2(c+1)] x) x) 639 (MULQconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (LEAQ1 (SHLQconst <v.Type> [log2(c-1)] x) x) 640 (MULQconst [c] x) && isPowerOfTwo(c-2) && c >= 34 -> (LEAQ2 (SHLQconst <v.Type> [log2(c-2)] x) x) 641 (MULQconst [c] x) && isPowerOfTwo(c-4) && c >= 68 -> (LEAQ4 (SHLQconst <v.Type> [log2(c-4)] x) x) 642 (MULQconst [c] x) && isPowerOfTwo(c-8) && c >= 136 -> (LEAQ8 (SHLQconst <v.Type> [log2(c-8)] x) x) 643 (MULQconst [c] x) && c%3 == 0 && isPowerOfTwo(c/3)-> (SHLQconst [log2(c/3)] (LEAQ2 <v.Type> x x)) 644 (MULQconst [c] x) && c%5 == 0 && isPowerOfTwo(c/5)-> (SHLQconst [log2(c/5)] (LEAQ4 <v.Type> x x)) 645 (MULQconst [c] x) && c%9 == 0 && isPowerOfTwo(c/9)-> (SHLQconst [log2(c/9)] (LEAQ8 <v.Type> x x)) 646 647 // combine add/shift into LEAQ 648 (ADDQ x (SHLQconst [3] y)) -> (LEAQ8 x y) 649 (ADDQ x (SHLQconst [2] y)) -> (LEAQ4 x y) 650 (ADDQ x (SHLQconst [1] y)) -> (LEAQ2 x y) 651 (ADDQ x (ADDQ y y)) -> (LEAQ2 x y) 652 (ADDQ x (ADDQ x y)) -> (LEAQ2 y x) 653 (ADDQ x (ADDQ y x)) -> (LEAQ2 y x) 654 655 // combine ADDQ/ADDQconst into LEAQ1 656 (ADDQconst [c] (ADDQ x y)) -> (LEAQ1 [c] x y) 657 (ADDQ (ADDQconst [c] x) y) -> (LEAQ1 [c] x y) 658 (ADDQ x (ADDQconst [c] y)) -> (LEAQ1 [c] x y) 659 660 // fold ADDQ into LEAQ 661 (ADDQconst [c] (LEAQ [d] {s} x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 662 (LEAQ [c] {s} (ADDQconst [d] x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x) 663 (LEAQ [c] {s} (ADDQ x y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 664 (ADDQ x (LEAQ [c] {s} y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 665 (ADDQ (LEAQ [c] {s} x) y) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y) 666 667 // fold ADDQconst into LEAQx 668 (ADDQconst [c] (LEAQ1 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ1 [c+d] {s} x y) 669 (ADDQconst [c] (LEAQ2 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ2 [c+d] {s} x y) 670 (ADDQconst [c] (LEAQ4 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ4 [c+d] {s} x y) 671 (ADDQconst [c] (LEAQ8 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ8 [c+d] {s} x y) 672 (LEAQ1 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ1 [c+d] {s} x y) 673 (LEAQ1 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+d) && y.Op != OpSB -> (LEAQ1 [c+d] {s} x y) 674 (LEAQ2 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ2 [c+d] {s} x y) 675 (LEAQ2 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+2*d) && y.Op != OpSB -> (LEAQ2 [c+2*d] {s} x y) 676 (LEAQ4 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ4 [c+d] {s} x y) 677 (LEAQ4 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+4*d) && y.Op != OpSB -> (LEAQ4 [c+4*d] {s} x y) 678 (LEAQ8 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d) && x.Op != OpSB -> (LEAQ8 [c+d] {s} x y) 679 (LEAQ8 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+8*d) && y.Op != OpSB -> (LEAQ8 [c+8*d] {s} x y) 680 681 // fold shifts into LEAQx 682 (LEAQ1 [c] {s} x (SHLQconst [1] y)) -> (LEAQ2 [c] {s} x y) 683 (LEAQ1 [c] {s} (SHLQconst [1] x) y) -> (LEAQ2 [c] {s} y x) 684 (LEAQ1 [c] {s} x (SHLQconst [2] y)) -> (LEAQ4 [c] {s} x y) 685 (LEAQ1 [c] {s} (SHLQconst [2] x) y) -> (LEAQ4 [c] {s} y x) 686 (LEAQ1 [c] {s} x (SHLQconst [3] y)) -> (LEAQ8 [c] {s} x y) 687 (LEAQ1 [c] {s} (SHLQconst [3] x) y) -> (LEAQ8 [c] {s} y x) 688 689 (LEAQ2 [c] {s} x (SHLQconst [1] y)) -> (LEAQ4 [c] {s} x y) 690 (LEAQ2 [c] {s} x (SHLQconst [2] y)) -> (LEAQ8 [c] {s} x y) 691 (LEAQ4 [c] {s} x (SHLQconst [1] y)) -> (LEAQ8 [c] {s} x y) 692 693 // reverse ordering of compare instruction 694 (SETL (InvertFlags x)) -> (SETG x) 695 (SETG (InvertFlags x)) -> (SETL x) 696 (SETB (InvertFlags x)) -> (SETA x) 697 (SETA (InvertFlags x)) -> (SETB x) 698 (SETLE (InvertFlags x)) -> (SETGE x) 699 (SETGE (InvertFlags x)) -> (SETLE x) 700 (SETBE (InvertFlags x)) -> (SETAE x) 701 (SETAE (InvertFlags x)) -> (SETBE x) 702 (SETEQ (InvertFlags x)) -> (SETEQ x) 703 (SETNE (InvertFlags x)) -> (SETNE x) 704 705 // sign extended loads 706 // Note: The combined instruction must end up in the same block 707 // as the original load. If not, we end up making a value with 708 // memory type live in two different blocks, which can lead to 709 // multiple memory values alive simultaneously. 710 // Make sure we don't combine these ops if the load has another use. 711 // This prevents a single load from being split into multiple loads 712 // which then might return different values. See test/atomicload.go. 713 (MOVBQSX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem) 714 (MOVBQZX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 715 (MOVWQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem) 716 (MOVWQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 717 (MOVLQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem) 718 (MOVLQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem) 719 720 (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBloadidx1 <v.Type> [off] {sym} ptr idx mem) 721 (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx1 <v.Type> [off] {sym} ptr idx mem) 722 (MOVWQZX x:(MOVWloadidx2 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx2 <v.Type> [off] {sym} ptr idx mem) 723 (MOVLQZX x:(MOVLloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx1 <v.Type> [off] {sym} ptr idx mem) 724 (MOVLQZX x:(MOVLloadidx4 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx4 <v.Type> [off] {sym} ptr idx mem) 725 726 // replace load from same location as preceding store with copy 727 (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 728 (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 729 (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 730 (MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x 731 732 // Fold extensions and ANDs together. 733 (MOVBQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xff] x) 734 (MOVWQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xffff] x) 735 (MOVLQZX (ANDLconst [c] x)) -> (ANDLconst [c] x) 736 (MOVBQSX (ANDLconst [c] x)) && c & 0x80 == 0 -> (ANDLconst [c & 0x7f] x) 737 (MOVWQSX (ANDLconst [c] x)) && c & 0x8000 == 0 -> (ANDLconst [c & 0x7fff] x) 738 (MOVLQSX (ANDLconst [c] x)) && c & 0x80000000 == 0 -> (ANDLconst [c & 0x7fffffff] x) 739 740 // Don't extend before storing 741 (MOVLstore [off] {sym} ptr (MOVLQSX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 742 (MOVWstore [off] {sym} ptr (MOVWQSX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 743 (MOVBstore [off] {sym} ptr (MOVBQSX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 744 (MOVLstore [off] {sym} ptr (MOVLQZX x) mem) -> (MOVLstore [off] {sym} ptr x mem) 745 (MOVWstore [off] {sym} ptr (MOVWQZX x) mem) -> (MOVWstore [off] {sym} ptr x mem) 746 (MOVBstore [off] {sym} ptr (MOVBQZX x) mem) -> (MOVBstore [off] {sym} ptr x mem) 747 748 // fold constants into memory operations 749 // Note that this is not always a good idea because if not all the uses of 750 // the ADDQconst get eliminated, we still have to compute the ADDQconst and we now 751 // have potentially two live values (ptr and (ADDQconst [off] ptr)) instead of one. 752 // Nevertheless, let's do it! 753 (MOVQload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 754 (MOVLload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 755 (MOVWload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 756 (MOVBload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 757 (MOVSSload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSSload [off1+off2] {sym} ptr mem) 758 (MOVSDload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSDload [off1+off2] {sym} ptr mem) 759 (MOVOload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVOload [off1+off2] {sym} ptr mem) 760 761 (MOVQstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 762 (MOVLstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 763 (MOVWstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 764 (MOVBstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 765 (MOVSSstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSSstore [off1+off2] {sym} ptr val mem) 766 (MOVSDstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSDstore [off1+off2] {sym} ptr val mem) 767 (MOVOstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVOstore [off1+off2] {sym} ptr val mem) 768 769 // Fold constants into stores. 770 (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> 771 (MOVQstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 772 (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 773 (MOVLstoreconst [makeValAndOff(int64(int32(c)),off)] {sym} ptr mem) 774 (MOVWstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 775 (MOVWstoreconst [makeValAndOff(int64(int16(c)),off)] {sym} ptr mem) 776 (MOVBstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> 777 (MOVBstoreconst [makeValAndOff(int64(int8(c)),off)] {sym} ptr mem) 778 779 // Fold address offsets into constant stores. 780 (MOVQstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 781 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 782 (MOVLstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 783 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 784 (MOVWstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 785 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 786 (MOVBstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 787 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 788 789 // We need to fold LEAQ into the MOVx ops so that the live variable analysis knows 790 // what variables are being read/written by the ops. 791 (MOVQload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 792 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 793 (MOVLload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 794 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 795 (MOVWload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 796 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 797 (MOVBload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 798 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 799 (MOVSSload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 800 (MOVSSload [off1+off2] {mergeSym(sym1,sym2)} base mem) 801 (MOVSDload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 802 (MOVSDload [off1+off2] {mergeSym(sym1,sym2)} base mem) 803 (MOVOload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 804 (MOVOload [off1+off2] {mergeSym(sym1,sym2)} base mem) 805 806 (MOVBQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 807 (MOVBQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 808 (MOVWQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 809 (MOVWQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 810 (MOVLQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 811 (MOVLQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem) 812 813 (MOVQstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 814 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 815 (MOVLstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 816 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 817 (MOVWstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 818 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 819 (MOVBstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 820 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 821 (MOVSSstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 822 (MOVSSstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 823 (MOVSDstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 824 (MOVSDstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 825 (MOVOstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 826 (MOVOstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 827 828 (MOVQstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 829 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 830 (MOVLstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 831 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 832 (MOVWstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 833 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 834 (MOVBstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 835 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 836 837 // generating indexed loads and stores 838 (MOVBload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 839 (MOVBloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 840 (MOVWload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 841 (MOVWloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 842 (MOVWload [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 843 (MOVWloadidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 844 (MOVLload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 845 (MOVLloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 846 (MOVLload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 847 (MOVLloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 848 (MOVQload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 849 (MOVQloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 850 (MOVQload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 851 (MOVQloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 852 (MOVSSload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 853 (MOVSSloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 854 (MOVSSload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 855 (MOVSSloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 856 (MOVSDload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 857 (MOVSDloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 858 (MOVSDload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 859 (MOVSDloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem) 860 861 (MOVBstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 862 (MOVBstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 863 (MOVWstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 864 (MOVWstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 865 (MOVWstore [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 866 (MOVWstoreidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 867 (MOVLstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 868 (MOVLstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 869 (MOVLstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 870 (MOVLstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 871 (MOVQstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 872 (MOVQstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 873 (MOVQstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 874 (MOVQstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 875 (MOVSSstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 876 (MOVSSstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 877 (MOVSSstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 878 (MOVSSstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 879 (MOVSDstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 880 (MOVSDstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 881 (MOVSDstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 882 (MOVSDstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) 883 884 (MOVBload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVBloadidx1 [off] {sym} ptr idx mem) 885 (MOVWload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVWloadidx1 [off] {sym} ptr idx mem) 886 (MOVLload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVLloadidx1 [off] {sym} ptr idx mem) 887 (MOVQload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVQloadidx1 [off] {sym} ptr idx mem) 888 (MOVSSload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSSloadidx1 [off] {sym} ptr idx mem) 889 (MOVSDload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSDloadidx1 [off] {sym} ptr idx mem) 890 (MOVBstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVBstoreidx1 [off] {sym} ptr idx val mem) 891 (MOVWstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVWstoreidx1 [off] {sym} ptr idx val mem) 892 (MOVLstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVLstoreidx1 [off] {sym} ptr idx val mem) 893 (MOVQstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVQstoreidx1 [off] {sym} ptr idx val mem) 894 (MOVSSstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSSstoreidx1 [off] {sym} ptr idx val mem) 895 (MOVSDstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSDstoreidx1 [off] {sym} ptr idx val mem) 896 897 (MOVBstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 898 (MOVBstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 899 (MOVWstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 900 (MOVWstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 901 (MOVWstoreconst [x] {sym1} (LEAQ2 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 902 (MOVWstoreconstidx2 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 903 (MOVLstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 904 (MOVLstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 905 (MOVLstoreconst [x] {sym1} (LEAQ4 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 906 (MOVLstoreconstidx4 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 907 (MOVQstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 908 (MOVQstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 909 (MOVQstoreconst [x] {sym1} (LEAQ8 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) -> 910 (MOVQstoreconstidx8 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem) 911 912 (MOVBstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVBstoreconstidx1 [x] {sym} ptr idx mem) 913 (MOVWstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVWstoreconstidx1 [x] {sym} ptr idx mem) 914 (MOVLstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVLstoreconstidx1 [x] {sym} ptr idx mem) 915 (MOVQstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVQstoreconstidx1 [x] {sym} ptr idx mem) 916 917 // combine SHLQ into indexed loads and stores 918 (MOVWloadidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWloadidx2 [c] {sym} ptr idx mem) 919 (MOVLloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLloadidx4 [c] {sym} ptr idx mem) 920 (MOVQloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQloadidx8 [c] {sym} ptr idx mem) 921 (MOVWstoreidx1 [c] {sym} ptr (SHLQconst [1] idx) val mem) -> (MOVWstoreidx2 [c] {sym} ptr idx val mem) 922 (MOVLstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVLstoreidx4 [c] {sym} ptr idx val mem) 923 (MOVQstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVQstoreidx8 [c] {sym} ptr idx val mem) 924 (MOVWstoreconstidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWstoreconstidx2 [c] {sym} ptr idx mem) 925 (MOVLstoreconstidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLstoreconstidx4 [c] {sym} ptr idx mem) 926 (MOVQstoreconstidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQstoreconstidx8 [c] {sym} ptr idx mem) 927 928 // combine ADDQ into indexed loads and stores 929 (MOVBloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 930 (MOVWloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 931 (MOVWloadidx2 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx2 [c+d] {sym} ptr idx mem) 932 (MOVLloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 933 (MOVLloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx4 [c+d] {sym} ptr idx mem) 934 (MOVQloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 935 (MOVQloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx8 [c+d] {sym} ptr idx mem) 936 (MOVSSloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 937 (MOVSSloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx4 [c+d] {sym} ptr idx mem) 938 (MOVSDloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 939 (MOVSDloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx8 [c+d] {sym} ptr idx mem) 940 941 (MOVBstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 942 (MOVWstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 943 (MOVWstoreidx2 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx2 [c+d] {sym} ptr idx val mem) 944 (MOVLstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 945 (MOVLstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx4 [c+d] {sym} ptr idx val mem) 946 (MOVQstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 947 (MOVQstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx8 [c+d] {sym} ptr idx val mem) 948 (MOVSSstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 949 (MOVSSstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx4 [c+d] {sym} ptr idx val mem) 950 (MOVSDstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 951 (MOVSDstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx8 [c+d] {sym} ptr idx val mem) 952 953 (MOVBloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem) 954 (MOVWloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem) 955 (MOVWloadidx2 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx2 [c+2*d] {sym} ptr idx mem) 956 (MOVLloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem) 957 (MOVLloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx4 [c+4*d] {sym} ptr idx mem) 958 (MOVQloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem) 959 (MOVQloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx8 [c+8*d] {sym} ptr idx mem) 960 (MOVSSloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem) 961 (MOVSSloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx4 [c+4*d] {sym} ptr idx mem) 962 (MOVSDloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem) 963 (MOVSDloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx8 [c+8*d] {sym} ptr idx mem) 964 965 (MOVBstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem) 966 (MOVWstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem) 967 (MOVWstoreidx2 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx2 [c+2*d] {sym} ptr idx val mem) 968 (MOVLstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem) 969 (MOVLstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx4 [c+4*d] {sym} ptr idx val mem) 970 (MOVQstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem) 971 (MOVQstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx8 [c+8*d] {sym} ptr idx val mem) 972 (MOVSSstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem) 973 (MOVSSstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx4 [c+4*d] {sym} ptr idx val mem) 974 (MOVSDstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem) 975 (MOVSDstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx8 [c+8*d] {sym} ptr idx val mem) 976 977 (MOVBstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 978 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 979 (MOVWstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 980 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 981 (MOVWstoreconstidx2 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 982 (MOVWstoreconstidx2 [ValAndOff(x).add(c)] {sym} ptr idx mem) 983 (MOVLstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 984 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 985 (MOVLstoreconstidx4 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 986 (MOVLstoreconstidx4 [ValAndOff(x).add(c)] {sym} ptr idx mem) 987 (MOVQstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 988 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 989 (MOVQstoreconstidx8 [x] {sym} (ADDQconst [c] ptr) idx mem) -> 990 (MOVQstoreconstidx8 [ValAndOff(x).add(c)] {sym} ptr idx mem) 991 992 (MOVBstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 993 (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 994 (MOVWstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 995 (MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 996 (MOVWstoreconstidx2 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 997 (MOVWstoreconstidx2 [ValAndOff(x).add(2*c)] {sym} ptr idx mem) 998 (MOVLstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 999 (MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1000 (MOVLstoreconstidx4 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1001 (MOVLstoreconstidx4 [ValAndOff(x).add(4*c)] {sym} ptr idx mem) 1002 (MOVQstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1003 (MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) 1004 (MOVQstoreconstidx8 [x] {sym} ptr (ADDQconst [c] idx) mem) -> 1005 (MOVQstoreconstidx8 [ValAndOff(x).add(8*c)] {sym} ptr idx mem) 1006 1007 // fold LEAQs together 1008 (LEAQ [off1] {sym1} (LEAQ [off2] {sym2} x)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1009 (LEAQ [off1+off2] {mergeSym(sym1,sym2)} x) 1010 1011 // LEAQ into LEAQ1 1012 (LEAQ1 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1013 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1014 (LEAQ1 [off1] {sym1} x (LEAQ [off2] {sym2} y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && y.Op != OpSB -> 1015 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1016 1017 // LEAQ1 into LEAQ 1018 (LEAQ [off1] {sym1} (LEAQ1 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1019 (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y) 1020 1021 // LEAQ into LEAQ[248] 1022 (LEAQ2 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1023 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1024 (LEAQ4 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1025 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1026 (LEAQ8 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB -> 1027 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1028 1029 // LEAQ[248] into LEAQ 1030 (LEAQ [off1] {sym1} (LEAQ2 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1031 (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y) 1032 (LEAQ [off1] {sym1} (LEAQ4 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1033 (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y) 1034 (LEAQ [off1] {sym1} (LEAQ8 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1035 (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y) 1036 1037 // Absorb InvertFlags into branches. 1038 (LT (InvertFlags cmp) yes no) -> (GT cmp yes no) 1039 (GT (InvertFlags cmp) yes no) -> (LT cmp yes no) 1040 (LE (InvertFlags cmp) yes no) -> (GE cmp yes no) 1041 (GE (InvertFlags cmp) yes no) -> (LE cmp yes no) 1042 (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no) 1043 (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no) 1044 (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no) 1045 (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no) 1046 (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no) 1047 (NE (InvertFlags cmp) yes no) -> (NE cmp yes no) 1048 1049 // Constant comparisons. 1050 (CMPQconst (MOVQconst [x]) [y]) && x==y -> (FlagEQ) 1051 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)<uint64(y) -> (FlagLT_ULT) 1052 (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)>uint64(y) -> (FlagLT_UGT) 1053 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)<uint64(y) -> (FlagGT_ULT) 1054 (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)>uint64(y) -> (FlagGT_UGT) 1055 (CMPLconst (MOVLconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ) 1056 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT) 1057 (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT) 1058 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT) 1059 (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT) 1060 (CMPWconst (MOVLconst [x]) [y]) && int16(x)==int16(y) -> (FlagEQ) 1061 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)<uint16(y) -> (FlagLT_ULT) 1062 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)>uint16(y) -> (FlagLT_UGT) 1063 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)<uint16(y) -> (FlagGT_ULT) 1064 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)>uint16(y) -> (FlagGT_UGT) 1065 (CMPBconst (MOVLconst [x]) [y]) && int8(x)==int8(y) -> (FlagEQ) 1066 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)<uint8(y) -> (FlagLT_ULT) 1067 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)>uint8(y) -> (FlagLT_UGT) 1068 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)<uint8(y) -> (FlagGT_ULT) 1069 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)>uint8(y) -> (FlagGT_UGT) 1070 1071 // Other known comparisons. 1072 (CMPQconst (MOVBQZX _) [c]) && 0xFF < c -> (FlagLT_ULT) 1073 (CMPQconst (MOVWQZX _) [c]) && 0xFFFF < c -> (FlagLT_ULT) 1074 (CMPQconst (MOVLQZX _) [c]) && 0xFFFFFFFF < c -> (FlagLT_ULT) 1075 (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT_ULT) 1076 (CMPQconst (SHRQconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT) 1077 (CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT) 1078 (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT) 1079 (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT) 1080 (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT) 1081 // TODO: DIVxU also. 1082 1083 // Absorb flag constants into SBB ops. 1084 (SBBQcarrymask (FlagEQ)) -> (MOVQconst [0]) 1085 (SBBQcarrymask (FlagLT_ULT)) -> (MOVQconst [-1]) 1086 (SBBQcarrymask (FlagLT_UGT)) -> (MOVQconst [0]) 1087 (SBBQcarrymask (FlagGT_ULT)) -> (MOVQconst [-1]) 1088 (SBBQcarrymask (FlagGT_UGT)) -> (MOVQconst [0]) 1089 (SBBLcarrymask (FlagEQ)) -> (MOVLconst [0]) 1090 (SBBLcarrymask (FlagLT_ULT)) -> (MOVLconst [-1]) 1091 (SBBLcarrymask (FlagLT_UGT)) -> (MOVLconst [0]) 1092 (SBBLcarrymask (FlagGT_ULT)) -> (MOVLconst [-1]) 1093 (SBBLcarrymask (FlagGT_UGT)) -> (MOVLconst [0]) 1094 1095 // Absorb flag constants into branches. 1096 (EQ (FlagEQ) yes no) -> (First nil yes no) 1097 (EQ (FlagLT_ULT) yes no) -> (First nil no yes) 1098 (EQ (FlagLT_UGT) yes no) -> (First nil no yes) 1099 (EQ (FlagGT_ULT) yes no) -> (First nil no yes) 1100 (EQ (FlagGT_UGT) yes no) -> (First nil no yes) 1101 1102 (NE (FlagEQ) yes no) -> (First nil no yes) 1103 (NE (FlagLT_ULT) yes no) -> (First nil yes no) 1104 (NE (FlagLT_UGT) yes no) -> (First nil yes no) 1105 (NE (FlagGT_ULT) yes no) -> (First nil yes no) 1106 (NE (FlagGT_UGT) yes no) -> (First nil yes no) 1107 1108 (LT (FlagEQ) yes no) -> (First nil no yes) 1109 (LT (FlagLT_ULT) yes no) -> (First nil yes no) 1110 (LT (FlagLT_UGT) yes no) -> (First nil yes no) 1111 (LT (FlagGT_ULT) yes no) -> (First nil no yes) 1112 (LT (FlagGT_UGT) yes no) -> (First nil no yes) 1113 1114 (LE (FlagEQ) yes no) -> (First nil yes no) 1115 (LE (FlagLT_ULT) yes no) -> (First nil yes no) 1116 (LE (FlagLT_UGT) yes no) -> (First nil yes no) 1117 (LE (FlagGT_ULT) yes no) -> (First nil no yes) 1118 (LE (FlagGT_UGT) yes no) -> (First nil no yes) 1119 1120 (GT (FlagEQ) yes no) -> (First nil no yes) 1121 (GT (FlagLT_ULT) yes no) -> (First nil no yes) 1122 (GT (FlagLT_UGT) yes no) -> (First nil no yes) 1123 (GT (FlagGT_ULT) yes no) -> (First nil yes no) 1124 (GT (FlagGT_UGT) yes no) -> (First nil yes no) 1125 1126 (GE (FlagEQ) yes no) -> (First nil yes no) 1127 (GE (FlagLT_ULT) yes no) -> (First nil no yes) 1128 (GE (FlagLT_UGT) yes no) -> (First nil no yes) 1129 (GE (FlagGT_ULT) yes no) -> (First nil yes no) 1130 (GE (FlagGT_UGT) yes no) -> (First nil yes no) 1131 1132 (ULT (FlagEQ) yes no) -> (First nil no yes) 1133 (ULT (FlagLT_ULT) yes no) -> (First nil yes no) 1134 (ULT (FlagLT_UGT) yes no) -> (First nil no yes) 1135 (ULT (FlagGT_ULT) yes no) -> (First nil yes no) 1136 (ULT (FlagGT_UGT) yes no) -> (First nil no yes) 1137 1138 (ULE (FlagEQ) yes no) -> (First nil yes no) 1139 (ULE (FlagLT_ULT) yes no) -> (First nil yes no) 1140 (ULE (FlagLT_UGT) yes no) -> (First nil no yes) 1141 (ULE (FlagGT_ULT) yes no) -> (First nil yes no) 1142 (ULE (FlagGT_UGT) yes no) -> (First nil no yes) 1143 1144 (UGT (FlagEQ) yes no) -> (First nil no yes) 1145 (UGT (FlagLT_ULT) yes no) -> (First nil no yes) 1146 (UGT (FlagLT_UGT) yes no) -> (First nil yes no) 1147 (UGT (FlagGT_ULT) yes no) -> (First nil no yes) 1148 (UGT (FlagGT_UGT) yes no) -> (First nil yes no) 1149 1150 (UGE (FlagEQ) yes no) -> (First nil yes no) 1151 (UGE (FlagLT_ULT) yes no) -> (First nil no yes) 1152 (UGE (FlagLT_UGT) yes no) -> (First nil yes no) 1153 (UGE (FlagGT_ULT) yes no) -> (First nil no yes) 1154 (UGE (FlagGT_UGT) yes no) -> (First nil yes no) 1155 1156 // Absorb flag constants into SETxx ops. 1157 (SETEQ (FlagEQ)) -> (MOVLconst [1]) 1158 (SETEQ (FlagLT_ULT)) -> (MOVLconst [0]) 1159 (SETEQ (FlagLT_UGT)) -> (MOVLconst [0]) 1160 (SETEQ (FlagGT_ULT)) -> (MOVLconst [0]) 1161 (SETEQ (FlagGT_UGT)) -> (MOVLconst [0]) 1162 1163 (SETNE (FlagEQ)) -> (MOVLconst [0]) 1164 (SETNE (FlagLT_ULT)) -> (MOVLconst [1]) 1165 (SETNE (FlagLT_UGT)) -> (MOVLconst [1]) 1166 (SETNE (FlagGT_ULT)) -> (MOVLconst [1]) 1167 (SETNE (FlagGT_UGT)) -> (MOVLconst [1]) 1168 1169 (SETL (FlagEQ)) -> (MOVLconst [0]) 1170 (SETL (FlagLT_ULT)) -> (MOVLconst [1]) 1171 (SETL (FlagLT_UGT)) -> (MOVLconst [1]) 1172 (SETL (FlagGT_ULT)) -> (MOVLconst [0]) 1173 (SETL (FlagGT_UGT)) -> (MOVLconst [0]) 1174 1175 (SETLE (FlagEQ)) -> (MOVLconst [1]) 1176 (SETLE (FlagLT_ULT)) -> (MOVLconst [1]) 1177 (SETLE (FlagLT_UGT)) -> (MOVLconst [1]) 1178 (SETLE (FlagGT_ULT)) -> (MOVLconst [0]) 1179 (SETLE (FlagGT_UGT)) -> (MOVLconst [0]) 1180 1181 (SETG (FlagEQ)) -> (MOVLconst [0]) 1182 (SETG (FlagLT_ULT)) -> (MOVLconst [0]) 1183 (SETG (FlagLT_UGT)) -> (MOVLconst [0]) 1184 (SETG (FlagGT_ULT)) -> (MOVLconst [1]) 1185 (SETG (FlagGT_UGT)) -> (MOVLconst [1]) 1186 1187 (SETGE (FlagEQ)) -> (MOVLconst [1]) 1188 (SETGE (FlagLT_ULT)) -> (MOVLconst [0]) 1189 (SETGE (FlagLT_UGT)) -> (MOVLconst [0]) 1190 (SETGE (FlagGT_ULT)) -> (MOVLconst [1]) 1191 (SETGE (FlagGT_UGT)) -> (MOVLconst [1]) 1192 1193 (SETB (FlagEQ)) -> (MOVLconst [0]) 1194 (SETB (FlagLT_ULT)) -> (MOVLconst [1]) 1195 (SETB (FlagLT_UGT)) -> (MOVLconst [0]) 1196 (SETB (FlagGT_ULT)) -> (MOVLconst [1]) 1197 (SETB (FlagGT_UGT)) -> (MOVLconst [0]) 1198 1199 (SETBE (FlagEQ)) -> (MOVLconst [1]) 1200 (SETBE (FlagLT_ULT)) -> (MOVLconst [1]) 1201 (SETBE (FlagLT_UGT)) -> (MOVLconst [0]) 1202 (SETBE (FlagGT_ULT)) -> (MOVLconst [1]) 1203 (SETBE (FlagGT_UGT)) -> (MOVLconst [0]) 1204 1205 (SETA (FlagEQ)) -> (MOVLconst [0]) 1206 (SETA (FlagLT_ULT)) -> (MOVLconst [0]) 1207 (SETA (FlagLT_UGT)) -> (MOVLconst [1]) 1208 (SETA (FlagGT_ULT)) -> (MOVLconst [0]) 1209 (SETA (FlagGT_UGT)) -> (MOVLconst [1]) 1210 1211 (SETAE (FlagEQ)) -> (MOVLconst [1]) 1212 (SETAE (FlagLT_ULT)) -> (MOVLconst [0]) 1213 (SETAE (FlagLT_UGT)) -> (MOVLconst [1]) 1214 (SETAE (FlagGT_ULT)) -> (MOVLconst [0]) 1215 (SETAE (FlagGT_UGT)) -> (MOVLconst [1]) 1216 1217 // Remove redundant *const ops 1218 (ADDQconst [0] x) -> x 1219 (ADDLconst [c] x) && int32(c)==0 -> x 1220 (SUBQconst [0] x) -> x 1221 (SUBLconst [c] x) && int32(c) == 0 -> x 1222 (ANDQconst [0] _) -> (MOVQconst [0]) 1223 (ANDLconst [c] _) && int32(c)==0 -> (MOVLconst [0]) 1224 (ANDQconst [-1] x) -> x 1225 (ANDLconst [c] x) && int32(c)==-1 -> x 1226 (ORQconst [0] x) -> x 1227 (ORLconst [c] x) && int32(c)==0 -> x 1228 (ORQconst [-1] _) -> (MOVQconst [-1]) 1229 (ORLconst [c] _) && int32(c)==-1 -> (MOVLconst [-1]) 1230 (XORQconst [0] x) -> x 1231 (XORLconst [c] x) && int32(c)==0 -> x 1232 // TODO: since we got rid of the W/B versions, we might miss 1233 // things like (ANDLconst [0x100] x) which were formerly 1234 // (ANDBconst [0] x). Probably doesn't happen very often. 1235 // If we cared, we might do: 1236 // (ANDLconst <t> [c] x) && t.Size()==1 && int8(x)==0 -> (MOVLconst [0]) 1237 1238 // Convert constant subtracts to constant adds 1239 (SUBQconst [c] x) && c != -(1<<31) -> (ADDQconst [-c] x) 1240 (SUBLconst [c] x) -> (ADDLconst [int64(int32(-c))] x) 1241 1242 // generic constant folding 1243 // TODO: more of this 1244 (ADDQconst [c] (MOVQconst [d])) -> (MOVQconst [c+d]) 1245 (ADDLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c+d))]) 1246 (ADDQconst [c] (ADDQconst [d] x)) && is32Bit(c+d) -> (ADDQconst [c+d] x) 1247 (ADDLconst [c] (ADDLconst [d] x)) -> (ADDLconst [int64(int32(c+d))] x) 1248 (SUBQconst (MOVQconst [d]) [c]) -> (MOVQconst [d-c]) 1249 (SUBQconst (SUBQconst x [d]) [c]) && is32Bit(-c-d) -> (ADDQconst [-c-d] x) 1250 (SARQconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1251 (SARLconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1252 (SARWconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1253 (SARBconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)]) 1254 (NEGQ (MOVQconst [c])) -> (MOVQconst [-c]) 1255 (NEGL (MOVLconst [c])) -> (MOVLconst [int64(int32(-c))]) 1256 (MULQconst [c] (MOVQconst [d])) -> (MOVQconst [c*d]) 1257 (MULLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c*d))]) 1258 (ANDQconst [c] (MOVQconst [d])) -> (MOVQconst [c&d]) 1259 (ANDLconst [c] (MOVLconst [d])) -> (MOVLconst [c&d]) 1260 (ORQconst [c] (MOVQconst [d])) -> (MOVQconst [c|d]) 1261 (ORLconst [c] (MOVLconst [d])) -> (MOVLconst [c|d]) 1262 (XORQconst [c] (MOVQconst [d])) -> (MOVQconst [c^d]) 1263 (XORLconst [c] (MOVLconst [d])) -> (MOVLconst [c^d]) 1264 (NOTQ (MOVQconst [c])) -> (MOVQconst [^c]) 1265 (NOTL (MOVLconst [c])) -> (MOVLconst [^c]) 1266 1267 // generic simplifications 1268 // TODO: more of this 1269 (ADDQ x (NEGQ y)) -> (SUBQ x y) 1270 (ADDL x (NEGL y)) -> (SUBL x y) 1271 (SUBQ x x) -> (MOVQconst [0]) 1272 (SUBL x x) -> (MOVLconst [0]) 1273 (ANDQ x x) -> x 1274 (ANDL x x) -> x 1275 (ORQ x x) -> x 1276 (ORL x x) -> x 1277 (XORQ x x) -> (MOVQconst [0]) 1278 (XORL x x) -> (MOVLconst [0]) 1279 1280 // checking AND against 0. 1281 (CMPQconst (ANDQ x y) [0]) -> (TESTQ x y) 1282 (CMPLconst (ANDL x y) [0]) -> (TESTL x y) 1283 (CMPWconst (ANDL x y) [0]) -> (TESTW x y) 1284 (CMPBconst (ANDL x y) [0]) -> (TESTB x y) 1285 (CMPQconst (ANDQconst [c] x) [0]) -> (TESTQconst [c] x) 1286 (CMPLconst (ANDLconst [c] x) [0]) -> (TESTLconst [c] x) 1287 (CMPWconst (ANDLconst [c] x) [0]) -> (TESTWconst [int64(int16(c))] x) 1288 (CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x) 1289 1290 // TEST %reg,%reg is shorter than CMP 1291 (CMPQconst x [0]) -> (TESTQ x x) 1292 (CMPLconst x [0]) -> (TESTL x x) 1293 (CMPWconst x [0]) -> (TESTW x x) 1294 (CMPBconst x [0]) -> (TESTB x x) 1295 1296 // Combining byte loads into larger (unaligned) loads. 1297 // There are many ways these combinations could occur. This is 1298 // designed to match the way encoding/binary.LittleEndian does it. 1299 (ORL x0:(MOVBload [i] {s} p mem) 1300 s0:(SHLLconst [8] x1:(MOVBload [i+1] {s} p mem))) 1301 && x0.Uses == 1 1302 && x1.Uses == 1 1303 && s0.Uses == 1 1304 && mergePoint(b,x0,x1) != nil 1305 && clobber(x0) 1306 && clobber(x1) 1307 && clobber(s0) 1308 -> @mergePoint(b,x0,x1) (MOVWload [i] {s} p mem) 1309 1310 (ORL o0:(ORL o1:(ORL 1311 x0:(MOVBload [i] {s} p mem) 1312 s0:(SHLLconst [8] x1:(MOVBload [i+1] {s} p mem))) 1313 s1:(SHLLconst [16] x2:(MOVBload [i+2] {s} p mem))) 1314 s2:(SHLLconst [24] x3:(MOVBload [i+3] {s} p mem))) 1315 && x0.Uses == 1 1316 && x1.Uses == 1 1317 && x2.Uses == 1 1318 && x3.Uses == 1 1319 && s0.Uses == 1 1320 && s1.Uses == 1 1321 && s2.Uses == 1 1322 && o0.Uses == 1 1323 && o1.Uses == 1 1324 && mergePoint(b,x0,x1,x2,x3) != nil 1325 && clobber(x0) 1326 && clobber(x1) 1327 && clobber(x2) 1328 && clobber(x3) 1329 && clobber(s0) 1330 && clobber(s1) 1331 && clobber(s2) 1332 && clobber(o0) 1333 && clobber(o1) 1334 -> @mergePoint(b,x0,x1,x2,x3) (MOVLload [i] {s} p mem) 1335 1336 (ORQ o0:(ORQ o1:(ORQ o2:(ORQ o3:(ORQ o4:(ORQ o5:(ORQ 1337 x0:(MOVBload [i] {s} p mem) 1338 s0:(SHLQconst [8] x1:(MOVBload [i+1] {s} p mem))) 1339 s1:(SHLQconst [16] x2:(MOVBload [i+2] {s} p mem))) 1340 s2:(SHLQconst [24] x3:(MOVBload [i+3] {s} p mem))) 1341 s3:(SHLQconst [32] x4:(MOVBload [i+4] {s} p mem))) 1342 s4:(SHLQconst [40] x5:(MOVBload [i+5] {s} p mem))) 1343 s5:(SHLQconst [48] x6:(MOVBload [i+6] {s} p mem))) 1344 s6:(SHLQconst [56] x7:(MOVBload [i+7] {s} p mem))) 1345 && x0.Uses == 1 1346 && x1.Uses == 1 1347 && x2.Uses == 1 1348 && x3.Uses == 1 1349 && x4.Uses == 1 1350 && x5.Uses == 1 1351 && x6.Uses == 1 1352 && x7.Uses == 1 1353 && s0.Uses == 1 1354 && s1.Uses == 1 1355 && s2.Uses == 1 1356 && s3.Uses == 1 1357 && s4.Uses == 1 1358 && s5.Uses == 1 1359 && s6.Uses == 1 1360 && o0.Uses == 1 1361 && o1.Uses == 1 1362 && o2.Uses == 1 1363 && o3.Uses == 1 1364 && o4.Uses == 1 1365 && o5.Uses == 1 1366 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil 1367 && clobber(x0) 1368 && clobber(x1) 1369 && clobber(x2) 1370 && clobber(x3) 1371 && clobber(x4) 1372 && clobber(x5) 1373 && clobber(x6) 1374 && clobber(x7) 1375 && clobber(s0) 1376 && clobber(s1) 1377 && clobber(s2) 1378 && clobber(s3) 1379 && clobber(s4) 1380 && clobber(s5) 1381 && clobber(s6) 1382 && clobber(o0) 1383 && clobber(o1) 1384 && clobber(o2) 1385 && clobber(o3) 1386 && clobber(o4) 1387 && clobber(o5) 1388 -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVQload [i] {s} p mem) 1389 1390 (ORL x0:(MOVBloadidx1 [i] {s} p idx mem) 1391 s0:(SHLLconst [8] x1:(MOVBloadidx1 [i+1] {s} p idx mem))) 1392 && x0.Uses == 1 1393 && x1.Uses == 1 1394 && s0.Uses == 1 1395 && mergePoint(b,x0,x1) != nil 1396 && clobber(x0) 1397 && clobber(x1) 1398 && clobber(s0) 1399 -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i] {s} p idx mem) 1400 1401 (ORL o0:(ORL o1:(ORL 1402 x0:(MOVBloadidx1 [i] {s} p idx mem) 1403 s0:(SHLLconst [8] x1:(MOVBloadidx1 [i+1] {s} p idx mem))) 1404 s1:(SHLLconst [16] x2:(MOVBloadidx1 [i+2] {s} p idx mem))) 1405 s2:(SHLLconst [24] x3:(MOVBloadidx1 [i+3] {s} p idx mem))) 1406 && x0.Uses == 1 1407 && x1.Uses == 1 1408 && x2.Uses == 1 1409 && x3.Uses == 1 1410 && s0.Uses == 1 1411 && s1.Uses == 1 1412 && s2.Uses == 1 1413 && o0.Uses == 1 1414 && o1.Uses == 1 1415 && mergePoint(b,x0,x1,x2,x3) != nil 1416 && clobber(x0) 1417 && clobber(x1) 1418 && clobber(x2) 1419 && clobber(x3) 1420 && clobber(s0) 1421 && clobber(s1) 1422 && clobber(s2) 1423 && clobber(o0) 1424 && clobber(o1) 1425 -> @mergePoint(b,x0,x1,x2,x3) (MOVLloadidx1 <v.Type> [i] {s} p idx mem) 1426 1427 (ORQ o0:(ORQ o1:(ORQ o2:(ORQ o3:(ORQ o4:(ORQ o5:(ORQ 1428 x0:(MOVBloadidx1 [i] {s} p idx mem) 1429 s0:(SHLQconst [8] x1:(MOVBloadidx1 [i+1] {s} p idx mem))) 1430 s1:(SHLQconst [16] x2:(MOVBloadidx1 [i+2] {s} p idx mem))) 1431 s2:(SHLQconst [24] x3:(MOVBloadidx1 [i+3] {s} p idx mem))) 1432 s3:(SHLQconst [32] x4:(MOVBloadidx1 [i+4] {s} p idx mem))) 1433 s4:(SHLQconst [40] x5:(MOVBloadidx1 [i+5] {s} p idx mem))) 1434 s5:(SHLQconst [48] x6:(MOVBloadidx1 [i+6] {s} p idx mem))) 1435 s6:(SHLQconst [56] x7:(MOVBloadidx1 [i+7] {s} p idx mem))) 1436 && x0.Uses == 1 1437 && x1.Uses == 1 1438 && x2.Uses == 1 1439 && x3.Uses == 1 1440 && x4.Uses == 1 1441 && x5.Uses == 1 1442 && x6.Uses == 1 1443 && x7.Uses == 1 1444 && s0.Uses == 1 1445 && s1.Uses == 1 1446 && s2.Uses == 1 1447 && s3.Uses == 1 1448 && s4.Uses == 1 1449 && s5.Uses == 1 1450 && s6.Uses == 1 1451 && o0.Uses == 1 1452 && o1.Uses == 1 1453 && o2.Uses == 1 1454 && o3.Uses == 1 1455 && o4.Uses == 1 1456 && o5.Uses == 1 1457 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil 1458 && clobber(x0) 1459 && clobber(x1) 1460 && clobber(x2) 1461 && clobber(x3) 1462 && clobber(x4) 1463 && clobber(x5) 1464 && clobber(x6) 1465 && clobber(x7) 1466 && clobber(s0) 1467 && clobber(s1) 1468 && clobber(s2) 1469 && clobber(s3) 1470 && clobber(s4) 1471 && clobber(s5) 1472 && clobber(s6) 1473 && clobber(o0) 1474 && clobber(o1) 1475 && clobber(o2) 1476 && clobber(o3) 1477 && clobber(o4) 1478 && clobber(o5) 1479 -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVQloadidx1 <v.Type> [i] {s} p idx mem) 1480 1481 // Combine constant stores into larger (unaligned) stores. 1482 (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem)) 1483 && x.Uses == 1 1484 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 1485 && clobber(x) 1486 -> (MOVWstoreconst [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p mem) 1487 (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem)) 1488 && x.Uses == 1 1489 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 1490 && clobber(x) 1491 -> (MOVLstoreconst [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p mem) 1492 (MOVLstoreconst [c] {s} p x:(MOVLstoreconst [a] {s} p mem)) 1493 && x.Uses == 1 1494 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 1495 && clobber(x) 1496 -> (MOVQstore [ValAndOff(a).Off()] {s} p (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 1497 1498 (MOVBstoreconstidx1 [c] {s} p i x:(MOVBstoreconstidx1 [a] {s} p i mem)) 1499 && x.Uses == 1 1500 && ValAndOff(a).Off() + 1 == ValAndOff(c).Off() 1501 && clobber(x) 1502 -> (MOVWstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p i mem) 1503 (MOVWstoreconstidx1 [c] {s} p i x:(MOVWstoreconstidx1 [a] {s} p i mem)) 1504 && x.Uses == 1 1505 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 1506 && clobber(x) 1507 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p i mem) 1508 (MOVLstoreconstidx1 [c] {s} p i x:(MOVLstoreconstidx1 [a] {s} p i mem)) 1509 && x.Uses == 1 1510 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 1511 && clobber(x) 1512 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p i (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 1513 1514 (MOVWstoreconstidx2 [c] {s} p i x:(MOVWstoreconstidx2 [a] {s} p i mem)) 1515 && x.Uses == 1 1516 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 1517 && clobber(x) 1518 -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p (SHLQconst <i.Type> [1] i) mem) 1519 (MOVLstoreconstidx4 [c] {s} p i x:(MOVLstoreconstidx4 [a] {s} p i mem)) 1520 && x.Uses == 1 1521 && ValAndOff(a).Off() + 4 == ValAndOff(c).Off() 1522 && clobber(x) 1523 -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p (SHLQconst <i.Type> [2] i) (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem) 1524 1525 // Combine stores into larger (unaligned) stores. 1526 (MOVBstore [i] {s} p (SHRQconst [8] w) x:(MOVBstore [i-1] {s} p w mem)) 1527 && x.Uses == 1 1528 && clobber(x) 1529 -> (MOVWstore [i-1] {s} p w mem) 1530 (MOVBstore [i] {s} p (SHRQconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SHRQconst [j-8] w) mem)) 1531 && x.Uses == 1 1532 && clobber(x) 1533 -> (MOVWstore [i-1] {s} p w0 mem) 1534 (MOVWstore [i] {s} p (SHRQconst [16] w) x:(MOVWstore [i-2] {s} p w mem)) 1535 && x.Uses == 1 1536 && clobber(x) 1537 -> (MOVLstore [i-2] {s} p w mem) 1538 (MOVWstore [i] {s} p (SHRQconst [j] w) x:(MOVWstore [i-2] {s} p w0:(SHRQconst [j-16] w) mem)) 1539 && x.Uses == 1 1540 && clobber(x) 1541 -> (MOVLstore [i-2] {s} p w0 mem) 1542 (MOVLstore [i] {s} p (SHRQconst [32] w) x:(MOVLstore [i-4] {s} p w mem)) 1543 && x.Uses == 1 1544 && clobber(x) 1545 -> (MOVQstore [i-4] {s} p w mem) 1546 (MOVLstore [i] {s} p (SHRQconst [j] w) x:(MOVLstore [i-4] {s} p w0:(SHRQconst [j-32] w) mem)) 1547 && x.Uses == 1 1548 && clobber(x) 1549 -> (MOVQstore [i-4] {s} p w0 mem) 1550 1551 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [8] w) x:(MOVBstoreidx1 [i-1] {s} p idx w mem)) 1552 && x.Uses == 1 1553 && clobber(x) 1554 -> (MOVWstoreidx1 [i-1] {s} p idx w mem) 1555 (MOVBstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVBstoreidx1 [i-1] {s} p idx w0:(SHRQconst [j-8] w) mem)) 1556 && x.Uses == 1 1557 && clobber(x) 1558 -> (MOVWstoreidx1 [i-1] {s} p idx w0 mem) 1559 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx1 [i-2] {s} p idx w mem)) 1560 && x.Uses == 1 1561 && clobber(x) 1562 -> (MOVLstoreidx1 [i-2] {s} p idx w mem) 1563 (MOVWstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx1 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 1564 && x.Uses == 1 1565 && clobber(x) 1566 -> (MOVLstoreidx1 [i-2] {s} p idx w0 mem) 1567 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx1 [i-4] {s} p idx w mem)) 1568 && x.Uses == 1 1569 && clobber(x) 1570 -> (MOVQstoreidx1 [i-4] {s} p idx w mem) 1571 (MOVLstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx1 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 1572 && x.Uses == 1 1573 && clobber(x) 1574 -> (MOVQstoreidx1 [i-4] {s} p idx w0 mem) 1575 1576 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx2 [i-2] {s} p idx w mem)) 1577 && x.Uses == 1 1578 && clobber(x) 1579 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w mem) 1580 (MOVWstoreidx2 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx2 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem)) 1581 && x.Uses == 1 1582 && clobber(x) 1583 -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w0 mem) 1584 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx4 [i-4] {s} p idx w mem)) 1585 && x.Uses == 1 1586 && clobber(x) 1587 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w mem) 1588 (MOVLstoreidx4 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx4 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem)) 1589 && x.Uses == 1 1590 && clobber(x) 1591 -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w0 mem) 1592 1593 // amd64p32 rules 1594 // same as the rules above, but with 32 instead of 64 bit pointer arithmetic. 1595 // LEAQ,ADDQ -> LEAL,ADDL 1596 (ADDLconst [c] (LEAL [d] {s} x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 1597 (LEAL [c] {s} (ADDLconst [d] x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x) 1598 1599 (MOVQload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 1600 (MOVQload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1601 (MOVLload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 1602 (MOVLload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1603 (MOVWload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 1604 (MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1605 (MOVBload [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) -> 1606 (MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem) 1607 1608 (MOVQstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 1609 (MOVQstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1610 (MOVLstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 1611 (MOVLstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1612 (MOVWstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 1613 (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1614 (MOVBstore [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) -> 1615 (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} base val mem) 1616 1617 (MOVQstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1618 (MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1619 (MOVLstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1620 (MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1621 (MOVWstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1622 (MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1623 (MOVBstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) -> 1624 (MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem) 1625 1626 (MOVQload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload [off1+off2] {sym} ptr mem) 1627 (MOVLload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload [off1+off2] {sym} ptr mem) 1628 (MOVWload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload [off1+off2] {sym} ptr mem) 1629 (MOVBload [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload [off1+off2] {sym} ptr mem) 1630 (MOVQstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore [off1+off2] {sym} ptr val mem) 1631 (MOVLstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore [off1+off2] {sym} ptr val mem) 1632 (MOVWstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore [off1+off2] {sym} ptr val mem) 1633 (MOVBstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore [off1+off2] {sym} ptr val mem) 1634 (MOVQstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1635 (MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1636 (MOVLstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1637 (MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1638 (MOVWstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1639 (MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1640 (MOVBstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) -> 1641 (MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem) 1642 1643 // Merge ADDQconst and LEAQ into atomic loads. 1644 (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 1645 (MOVQatomicload [off1+off2] {sym} ptr mem) 1646 (MOVLatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 1647 (MOVLatomicload [off1+off2] {sym} ptr mem) 1648 (MOVQatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1649 (MOVQatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 1650 (MOVLatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> 1651 (MOVLatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) 1652 1653 // Merge ADDQconst and LEAQ into atomic stores. 1654 (XCHGQ [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 1655 (XCHGQ [off1+off2] {sym} val ptr mem) 1656 (XCHGQ [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 1657 (XCHGQ [off1+off2] {mergeSym(sym1,sym2)} val ptr mem) 1658 (XCHGL [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> 1659 (XCHGL [off1+off2] {sym} val ptr mem) 1660 (XCHGL [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB -> 1661 (XCHGL [off1+off2] {mergeSym(sym1,sym2)} val ptr mem)