github.com/bir3/gocompiler@v0.3.205/src/cmd/compile/internal/ssa/_gen/386.rules (about) 1 // Copyright 2016 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 (Add(Ptr|32|16|8) ...) => (ADDL ...) 7 (Add(32|64)F ...) => (ADDS(S|D) ...) 8 (Add32carry ...) => (ADDLcarry ...) 9 (Add32withcarry ...) => (ADCL ...) 10 11 (Sub(Ptr|32|16|8) ...) => (SUBL ...) 12 (Sub(32|64)F ...) => (SUBS(S|D) ...) 13 (Sub32carry ...) => (SUBLcarry ...) 14 (Sub32withcarry ...) => (SBBL ...) 15 16 (Mul(32|16|8) ...) => (MULL ...) 17 (Mul(32|64)F ...) => (MULS(S|D) ...) 18 (Mul32uhilo ...) => (MULLQU ...) 19 20 (Select0 (Mul32uover x y)) => (Select0 <typ.UInt32> (MULLU x y)) 21 (Select1 (Mul32uover x y)) => (SETO (Select1 <types.TypeFlags> (MULLU x y))) 22 23 (Avg32u ...) => (AVGLU ...) 24 25 (Div(32|64)F ...) => (DIVS(S|D) ...) 26 (Div(32|32u|16|16u) ...) => (DIV(L|LU|W|WU) ...) 27 (Div8 x y) => (DIVW (SignExt8to16 x) (SignExt8to16 y)) 28 (Div8u x y) => (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y)) 29 30 (Hmul(32|32u) ...) => (HMUL(L|LU) ...) 31 32 (Mod(32|32u|16|16u) ...) => (MOD(L|LU|W|WU) ...) 33 (Mod8 x y) => (MODW (SignExt8to16 x) (SignExt8to16 y)) 34 (Mod8u x y) => (MODWU (ZeroExt8to16 x) (ZeroExt8to16 y)) 35 36 (And(32|16|8) ...) => (ANDL ...) 37 (Or(32|16|8) ...) => (ORL ...) 38 (Xor(32|16|8) ...) => (XORL ...) 39 40 (Neg(32|16|8) ...) => (NEGL ...) 41 (Neg32F x) => (PXOR x (MOVSSconst <typ.Float32> [float32(math.Copysign(0, -1))])) 42 (Neg64F x) => (PXOR x (MOVSDconst <typ.Float64> [math.Copysign(0, -1)])) 43 44 (Com(32|16|8) ...) => (NOTL ...) 45 46 // Lowering boolean ops 47 (AndB ...) => (ANDL ...) 48 (OrB ...) => (ORL ...) 49 (Not x) => (XORLconst [1] x) 50 51 // Lowering pointer arithmetic 52 (OffPtr [off] ptr) => (ADDLconst [int32(off)] ptr) 53 54 (Bswap32 ...) => (BSWAPL ...) 55 56 (Sqrt ...) => (SQRTSD ...) 57 (Sqrt32 ...) => (SQRTSS ...) 58 59 (Ctz16 x) => (BSFL (ORLconst <typ.UInt32> [0x10000] x)) 60 (Ctz16NonZero ...) => (BSFL ...) 61 62 // Lowering extension 63 (SignExt8to16 ...) => (MOVBLSX ...) 64 (SignExt8to32 ...) => (MOVBLSX ...) 65 (SignExt16to32 ...) => (MOVWLSX ...) 66 67 (ZeroExt8to16 ...) => (MOVBLZX ...) 68 (ZeroExt8to32 ...) => (MOVBLZX ...) 69 (ZeroExt16to32 ...) => (MOVWLZX ...) 70 71 (Signmask x) => (SARLconst x [31]) 72 (Zeromask <t> x) => (XORLconst [-1] (SBBLcarrymask <t> (CMPLconst x [1]))) 73 (Slicemask <t> x) => (SARLconst (NEGL <t> x) [31]) 74 75 // Lowering truncation 76 // Because we ignore high parts of registers, truncates are just copies. 77 (Trunc16to8 ...) => (Copy ...) 78 (Trunc32to8 ...) => (Copy ...) 79 (Trunc32to16 ...) => (Copy ...) 80 81 // Lowering float-int conversions 82 (Cvt32to32F ...) => (CVTSL2SS ...) 83 (Cvt32to64F ...) => (CVTSL2SD ...) 84 85 (Cvt32Fto32 ...) => (CVTTSS2SL ...) 86 (Cvt64Fto32 ...) => (CVTTSD2SL ...) 87 88 (Cvt32Fto64F ...) => (CVTSS2SD ...) 89 (Cvt64Fto32F ...) => (CVTSD2SS ...) 90 91 (Round32F ...) => (Copy ...) 92 (Round64F ...) => (Copy ...) 93 94 (CvtBoolToUint8 ...) => (Copy ...) 95 96 // Lowering shifts 97 // Unsigned shifts need to return 0 if shift amount is >= width of shifted value. 98 // result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff) 99 (Lsh32x(32|16|8) <t> x y) && !shiftIsBounded(v) => (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) 100 (Lsh16x(32|16|8) <t> x y) && !shiftIsBounded(v) => (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) 101 (Lsh8x(32|16|8) <t> x y) && !shiftIsBounded(v) => (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) 102 103 (Lsh32x(32|16|8) <t> x y) && shiftIsBounded(v) => (SHLL <t> x y) 104 (Lsh16x(32|16|8) <t> x y) && shiftIsBounded(v) => (SHLL <t> x y) 105 (Lsh8x(32|16|8) <t> x y) && shiftIsBounded(v) => (SHLL <t> x y) 106 107 (Rsh32Ux(32|16|8) <t> x y) && !shiftIsBounded(v) => (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [32]))) 108 (Rsh16Ux(32|16|8) <t> x y) && !shiftIsBounded(v) => (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [16]))) 109 (Rsh8Ux(32|16|8) <t> x y) && !shiftIsBounded(v) => (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMP(L|W|B)const y [8]))) 110 111 (Rsh32Ux(32|16|8) <t> x y) && shiftIsBounded(v) => (SHRL <t> x y) 112 (Rsh16Ux(32|16|8) <t> x y) && shiftIsBounded(v) => (SHRW <t> x y) 113 (Rsh8Ux(32|16|8) <t> x y) && shiftIsBounded(v) => (SHRB <t> x y) 114 115 // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value. 116 // We implement this by setting the shift value to -1 (all ones) if the shift value is >= width. 117 118 (Rsh32x(32|16|8) <t> x y) && !shiftIsBounded(v) => (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [32]))))) 119 (Rsh16x(32|16|8) <t> x y) && !shiftIsBounded(v) => (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [16]))))) 120 (Rsh8x(32|16|8) <t> x y) && !shiftIsBounded(v) => (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMP(L|W|B)const y [8]))))) 121 122 (Rsh32x(32|16|8) <t> x y) && shiftIsBounded(v) => (SARL x y) 123 (Rsh16x(32|16|8) <t> x y) && shiftIsBounded(v) => (SARW x y) 124 (Rsh8x(32|16|8) <t> x y) && shiftIsBounded(v) => (SARB x y) 125 126 // constant shifts 127 // generic opt rewrites all constant shifts to shift by Const64 128 (Lsh32x64 x (Const64 [c])) && uint64(c) < 32 => (SHLLconst x [int32(c)]) 129 (Rsh32x64 x (Const64 [c])) && uint64(c) < 32 => (SARLconst x [int32(c)]) 130 (Rsh32Ux64 x (Const64 [c])) && uint64(c) < 32 => (SHRLconst x [int32(c)]) 131 (Lsh16x64 x (Const64 [c])) && uint64(c) < 16 => (SHLLconst x [int32(c)]) 132 (Rsh16x64 x (Const64 [c])) && uint64(c) < 16 => (SARWconst x [int16(c)]) 133 (Rsh16Ux64 x (Const64 [c])) && uint64(c) < 16 => (SHRWconst x [int16(c)]) 134 (Lsh8x64 x (Const64 [c])) && uint64(c) < 8 => (SHLLconst x [int32(c)]) 135 (Rsh8x64 x (Const64 [c])) && uint64(c) < 8 => (SARBconst x [int8(c)]) 136 (Rsh8Ux64 x (Const64 [c])) && uint64(c) < 8 => (SHRBconst x [int8(c)]) 137 138 // large constant shifts 139 (Lsh32x64 _ (Const64 [c])) && uint64(c) >= 32 => (Const32 [0]) 140 (Rsh32Ux64 _ (Const64 [c])) && uint64(c) >= 32 => (Const32 [0]) 141 (Lsh16x64 _ (Const64 [c])) && uint64(c) >= 16 => (Const16 [0]) 142 (Rsh16Ux64 _ (Const64 [c])) && uint64(c) >= 16 => (Const16 [0]) 143 (Lsh8x64 _ (Const64 [c])) && uint64(c) >= 8 => (Const8 [0]) 144 (Rsh8Ux64 _ (Const64 [c])) && uint64(c) >= 8 => (Const8 [0]) 145 146 // large constant signed right shift, we leave the sign bit 147 (Rsh32x64 x (Const64 [c])) && uint64(c) >= 32 => (SARLconst x [31]) 148 (Rsh16x64 x (Const64 [c])) && uint64(c) >= 16 => (SARWconst x [15]) 149 (Rsh8x64 x (Const64 [c])) && uint64(c) >= 8 => (SARBconst x [7]) 150 151 // rotates 152 (RotateLeft32 ...) => (ROLL ...) 153 (RotateLeft16 ...) => (ROLW ...) 154 (RotateLeft8 ...) => (ROLB ...) 155 // constant rotates 156 (ROLL x (MOVLconst [c])) => (ROLLconst [c&31] x) 157 (ROLW x (MOVLconst [c])) => (ROLWconst [int16(c&15)] x) 158 (ROLB x (MOVLconst [c])) => (ROLBconst [int8(c&7)] x) 159 160 // Lowering comparisons 161 (Less32 x y) => (SETL (CMPL x y)) 162 (Less16 x y) => (SETL (CMPW x y)) 163 (Less8 x y) => (SETL (CMPB x y)) 164 (Less32U x y) => (SETB (CMPL x y)) 165 (Less16U x y) => (SETB (CMPW x y)) 166 (Less8U x y) => (SETB (CMPB x y)) 167 // Use SETGF with reversed operands to dodge NaN case 168 (Less64F x y) => (SETGF (UCOMISD y x)) 169 (Less32F x y) => (SETGF (UCOMISS y x)) 170 171 (Leq32 x y) => (SETLE (CMPL x y)) 172 (Leq16 x y) => (SETLE (CMPW x y)) 173 (Leq8 x y) => (SETLE (CMPB x y)) 174 (Leq32U x y) => (SETBE (CMPL x y)) 175 (Leq16U x y) => (SETBE (CMPW x y)) 176 (Leq8U x y) => (SETBE (CMPB x y)) 177 // Use SETGEF with reversed operands to dodge NaN case 178 (Leq64F x y) => (SETGEF (UCOMISD y x)) 179 (Leq32F x y) => (SETGEF (UCOMISS y x)) 180 181 (Eq32 x y) => (SETEQ (CMPL x y)) 182 (Eq16 x y) => (SETEQ (CMPW x y)) 183 (Eq8 x y) => (SETEQ (CMPB x y)) 184 (EqB x y) => (SETEQ (CMPB x y)) 185 (EqPtr x y) => (SETEQ (CMPL x y)) 186 (Eq64F x y) => (SETEQF (UCOMISD x y)) 187 (Eq32F x y) => (SETEQF (UCOMISS x y)) 188 189 (Neq32 x y) => (SETNE (CMPL x y)) 190 (Neq16 x y) => (SETNE (CMPW x y)) 191 (Neq8 x y) => (SETNE (CMPB x y)) 192 (NeqB x y) => (SETNE (CMPB x y)) 193 (NeqPtr x y) => (SETNE (CMPL x y)) 194 (Neq64F x y) => (SETNEF (UCOMISD x y)) 195 (Neq32F x y) => (SETNEF (UCOMISS x y)) 196 197 // Lowering loads 198 (Load <t> ptr mem) && (is32BitInt(t) || isPtr(t)) => (MOVLload ptr mem) 199 (Load <t> ptr mem) && is16BitInt(t) => (MOVWload ptr mem) 200 (Load <t> ptr mem) && (t.IsBoolean() || is8BitInt(t)) => (MOVBload ptr mem) 201 (Load <t> ptr mem) && is32BitFloat(t) => (MOVSSload ptr mem) 202 (Load <t> ptr mem) && is64BitFloat(t) => (MOVSDload ptr mem) 203 204 // Lowering stores 205 // These more-specific FP versions of Store pattern should come first. 206 (Store {t} ptr val mem) && t.Size() == 8 && is64BitFloat(val.Type) => (MOVSDstore ptr val mem) 207 (Store {t} ptr val mem) && t.Size() == 4 && is32BitFloat(val.Type) => (MOVSSstore ptr val mem) 208 209 (Store {t} ptr val mem) && t.Size() == 4 => (MOVLstore ptr val mem) 210 (Store {t} ptr val mem) && t.Size() == 2 => (MOVWstore ptr val mem) 211 (Store {t} ptr val mem) && t.Size() == 1 => (MOVBstore ptr val mem) 212 213 // Lowering moves 214 (Move [0] _ _ mem) => mem 215 (Move [1] dst src mem) => (MOVBstore dst (MOVBload src mem) mem) 216 (Move [2] dst src mem) => (MOVWstore dst (MOVWload src mem) mem) 217 (Move [4] dst src mem) => (MOVLstore dst (MOVLload src mem) mem) 218 (Move [3] dst src mem) => 219 (MOVBstore [2] dst (MOVBload [2] src mem) 220 (MOVWstore dst (MOVWload src mem) mem)) 221 (Move [5] dst src mem) => 222 (MOVBstore [4] dst (MOVBload [4] src mem) 223 (MOVLstore dst (MOVLload src mem) mem)) 224 (Move [6] dst src mem) => 225 (MOVWstore [4] dst (MOVWload [4] src mem) 226 (MOVLstore dst (MOVLload src mem) mem)) 227 (Move [7] dst src mem) => 228 (MOVLstore [3] dst (MOVLload [3] src mem) 229 (MOVLstore dst (MOVLload src mem) mem)) 230 (Move [8] dst src mem) => 231 (MOVLstore [4] dst (MOVLload [4] src mem) 232 (MOVLstore dst (MOVLload src mem) mem)) 233 234 // Adjust moves to be a multiple of 4 bytes. 235 (Move [s] dst src mem) 236 && s > 8 && s%4 != 0 => 237 (Move [s-s%4] 238 (ADDLconst <dst.Type> dst [int32(s%4)]) 239 (ADDLconst <src.Type> src [int32(s%4)]) 240 (MOVLstore dst (MOVLload src mem) mem)) 241 242 // Medium copying uses a duff device. 243 (Move [s] dst src mem) 244 && s > 8 && s <= 4*128 && s%4 == 0 245 && !config.noDuffDevice && logLargeCopy(v, s) => 246 (DUFFCOPY [10*(128-s/4)] dst src mem) 247 // 10 and 128 are magic constants. 10 is the number of bytes to encode: 248 // MOVL (SI), CX 249 // ADDL $4, SI 250 // MOVL CX, (DI) 251 // ADDL $4, DI 252 // and 128 is the number of such blocks. See src/runtime/duff_386.s:duffcopy. 253 254 // Large copying uses REP MOVSL. 255 (Move [s] dst src mem) && (s > 4*128 || config.noDuffDevice) && s%4 == 0 && logLargeCopy(v, s) => 256 (REPMOVSL dst src (MOVLconst [int32(s/4)]) mem) 257 258 // Lowering Zero instructions 259 (Zero [0] _ mem) => mem 260 (Zero [1] destptr mem) => (MOVBstoreconst [0] destptr mem) 261 (Zero [2] destptr mem) => (MOVWstoreconst [0] destptr mem) 262 (Zero [4] destptr mem) => (MOVLstoreconst [0] destptr mem) 263 264 (Zero [3] destptr mem) => 265 (MOVBstoreconst [makeValAndOff(0,2)] destptr 266 (MOVWstoreconst [makeValAndOff(0,0)] destptr mem)) 267 (Zero [5] destptr mem) => 268 (MOVBstoreconst [makeValAndOff(0,4)] destptr 269 (MOVLstoreconst [makeValAndOff(0,0)] destptr mem)) 270 (Zero [6] destptr mem) => 271 (MOVWstoreconst [makeValAndOff(0,4)] destptr 272 (MOVLstoreconst [makeValAndOff(0,0)] destptr mem)) 273 (Zero [7] destptr mem) => 274 (MOVLstoreconst [makeValAndOff(0,3)] destptr 275 (MOVLstoreconst [makeValAndOff(0,0)] destptr mem)) 276 277 // Strip off any fractional word zeroing. 278 (Zero [s] destptr mem) && s%4 != 0 && s > 4 => 279 (Zero [s-s%4] (ADDLconst destptr [int32(s%4)]) 280 (MOVLstoreconst [0] destptr mem)) 281 282 // Zero small numbers of words directly. 283 (Zero [8] destptr mem) => 284 (MOVLstoreconst [makeValAndOff(0,4)] destptr 285 (MOVLstoreconst [makeValAndOff(0,0)] destptr mem)) 286 (Zero [12] destptr mem) => 287 (MOVLstoreconst [makeValAndOff(0,8)] destptr 288 (MOVLstoreconst [makeValAndOff(0,4)] destptr 289 (MOVLstoreconst [makeValAndOff(0,0)] destptr mem))) 290 (Zero [16] destptr mem) => 291 (MOVLstoreconst [makeValAndOff(0,12)] destptr 292 (MOVLstoreconst [makeValAndOff(0,8)] destptr 293 (MOVLstoreconst [makeValAndOff(0,4)] destptr 294 (MOVLstoreconst [makeValAndOff(0,0)] destptr mem)))) 295 296 // Medium zeroing uses a duff device. 297 (Zero [s] destptr mem) 298 && s > 16 && s <= 4*128 && s%4 == 0 299 && !config.noDuffDevice => 300 (DUFFZERO [1*(128-s/4)] destptr (MOVLconst [0]) mem) 301 // 1 and 128 are magic constants. 1 is the number of bytes to encode STOSL. 302 // 128 is the number of STOSL instructions in duffzero. 303 // See src/runtime/duff_386.s:duffzero. 304 305 // Large zeroing uses REP STOSQ. 306 (Zero [s] destptr mem) 307 && (s > 4*128 || (config.noDuffDevice && s > 16)) 308 && s%4 == 0 => 309 (REPSTOSL destptr (MOVLconst [int32(s/4)]) (MOVLconst [0]) mem) 310 311 312 // Lowering constants 313 (Const8 [c]) => (MOVLconst [int32(c)]) 314 (Const16 [c]) => (MOVLconst [int32(c)]) 315 (Const32 ...) => (MOVLconst ...) 316 (Const(32|64)F ...) => (MOVS(S|D)const ...) 317 (ConstNil) => (MOVLconst [0]) 318 (ConstBool [c]) => (MOVLconst [b2i32(c)]) 319 320 // Lowering calls 321 (StaticCall ...) => (CALLstatic ...) 322 (ClosureCall ...) => (CALLclosure ...) 323 (InterCall ...) => (CALLinter ...) 324 (TailCall ...) => (CALLtail ...) 325 326 // Miscellaneous 327 (IsNonNil p) => (SETNE (TESTL p p)) 328 (IsInBounds idx len) => (SETB (CMPL idx len)) 329 (IsSliceInBounds idx len) => (SETBE (CMPL idx len)) 330 (NilCheck ...) => (LoweredNilCheck ...) 331 (GetG ...) => (LoweredGetG ...) 332 (GetClosurePtr ...) => (LoweredGetClosurePtr ...) 333 (GetCallerPC ...) => (LoweredGetCallerPC ...) 334 (GetCallerSP ...) => (LoweredGetCallerSP ...) 335 (Addr {sym} base) => (LEAL {sym} base) 336 (LocalAddr {sym} base _) => (LEAL {sym} base) 337 338 // block rewrites 339 (If (SETL cmp) yes no) => (LT cmp yes no) 340 (If (SETLE cmp) yes no) => (LE cmp yes no) 341 (If (SETG cmp) yes no) => (GT cmp yes no) 342 (If (SETGE cmp) yes no) => (GE cmp yes no) 343 (If (SETEQ cmp) yes no) => (EQ cmp yes no) 344 (If (SETNE cmp) yes no) => (NE cmp yes no) 345 (If (SETB cmp) yes no) => (ULT cmp yes no) 346 (If (SETBE cmp) yes no) => (ULE cmp yes no) 347 (If (SETA cmp) yes no) => (UGT cmp yes no) 348 (If (SETAE cmp) yes no) => (UGE cmp yes no) 349 (If (SETO cmp) yes no) => (OS cmp yes no) 350 351 // Special case for floating point - LF/LEF not generated 352 (If (SETGF cmp) yes no) => (UGT cmp yes no) 353 (If (SETGEF cmp) yes no) => (UGE cmp yes no) 354 (If (SETEQF cmp) yes no) => (EQF cmp yes no) 355 (If (SETNEF cmp) yes no) => (NEF cmp yes no) 356 357 (If cond yes no) => (NE (TESTB cond cond) yes no) 358 359 // Write barrier. 360 (WB ...) => (LoweredWB ...) 361 362 (PanicBounds [kind] x y mem) && boundsABI(kind) == 0 => (LoweredPanicBoundsA [kind] x y mem) 363 (PanicBounds [kind] x y mem) && boundsABI(kind) == 1 => (LoweredPanicBoundsB [kind] x y mem) 364 (PanicBounds [kind] x y mem) && boundsABI(kind) == 2 => (LoweredPanicBoundsC [kind] x y mem) 365 366 (PanicExtend [kind] hi lo y mem) && boundsABI(kind) == 0 => (LoweredPanicExtendA [kind] hi lo y mem) 367 (PanicExtend [kind] hi lo y mem) && boundsABI(kind) == 1 => (LoweredPanicExtendB [kind] hi lo y mem) 368 (PanicExtend [kind] hi lo y mem) && boundsABI(kind) == 2 => (LoweredPanicExtendC [kind] hi lo y mem) 369 370 // *************************** 371 // Above: lowering rules 372 // Below: optimizations 373 // *************************** 374 // TODO: Should the optimizations be a separate pass? 375 376 // Fold boolean tests into blocks 377 (NE (TESTB (SETL cmp) (SETL cmp)) yes no) => (LT cmp yes no) 378 (NE (TESTB (SETLE cmp) (SETLE cmp)) yes no) => (LE cmp yes no) 379 (NE (TESTB (SETG cmp) (SETG cmp)) yes no) => (GT cmp yes no) 380 (NE (TESTB (SETGE cmp) (SETGE cmp)) yes no) => (GE cmp yes no) 381 (NE (TESTB (SETEQ cmp) (SETEQ cmp)) yes no) => (EQ cmp yes no) 382 (NE (TESTB (SETNE cmp) (SETNE cmp)) yes no) => (NE cmp yes no) 383 (NE (TESTB (SETB cmp) (SETB cmp)) yes no) => (ULT cmp yes no) 384 (NE (TESTB (SETBE cmp) (SETBE cmp)) yes no) => (ULE cmp yes no) 385 (NE (TESTB (SETA cmp) (SETA cmp)) yes no) => (UGT cmp yes no) 386 (NE (TESTB (SETAE cmp) (SETAE cmp)) yes no) => (UGE cmp yes no) 387 (NE (TESTB (SETO cmp) (SETO cmp)) yes no) => (OS cmp yes no) 388 389 // Special case for floating point - LF/LEF not generated 390 (NE (TESTB (SETGF cmp) (SETGF cmp)) yes no) => (UGT cmp yes no) 391 (NE (TESTB (SETGEF cmp) (SETGEF cmp)) yes no) => (UGE cmp yes no) 392 (NE (TESTB (SETEQF cmp) (SETEQF cmp)) yes no) => (EQF cmp yes no) 393 (NE (TESTB (SETNEF cmp) (SETNEF cmp)) yes no) => (NEF cmp yes no) 394 395 // fold constants into instructions 396 (ADDL x (MOVLconst [c])) => (ADDLconst [c] x) 397 (ADDLcarry x (MOVLconst [c])) => (ADDLconstcarry [c] x) 398 (ADCL x (MOVLconst [c]) f) => (ADCLconst [c] x f) 399 400 (SUBL x (MOVLconst [c])) => (SUBLconst x [c]) 401 (SUBL (MOVLconst [c]) x) => (NEGL (SUBLconst <v.Type> x [c])) 402 (SUBLcarry x (MOVLconst [c])) => (SUBLconstcarry [c] x) 403 (SBBL x (MOVLconst [c]) f) => (SBBLconst [c] x f) 404 405 (MULL x (MOVLconst [c])) => (MULLconst [c] x) 406 (ANDL x (MOVLconst [c])) => (ANDLconst [c] x) 407 408 (ANDLconst [c] (ANDLconst [d] x)) => (ANDLconst [c & d] x) 409 (XORLconst [c] (XORLconst [d] x)) => (XORLconst [c ^ d] x) 410 (MULLconst [c] (MULLconst [d] x)) => (MULLconst [c * d] x) 411 412 (ORL x (MOVLconst [c])) => (ORLconst [c] x) 413 (XORL x (MOVLconst [c])) => (XORLconst [c] x) 414 415 (SHLL x (MOVLconst [c])) => (SHLLconst [c&31] x) 416 (SHRL x (MOVLconst [c])) => (SHRLconst [c&31] x) 417 (SHRW x (MOVLconst [c])) && c&31 < 16 => (SHRWconst [int16(c&31)] x) 418 (SHRW _ (MOVLconst [c])) && c&31 >= 16 => (MOVLconst [0]) 419 (SHRB x (MOVLconst [c])) && c&31 < 8 => (SHRBconst [int8(c&31)] x) 420 (SHRB _ (MOVLconst [c])) && c&31 >= 8 => (MOVLconst [0]) 421 422 (SARL x (MOVLconst [c])) => (SARLconst [c&31] x) 423 (SARW x (MOVLconst [c])) => (SARWconst [int16(min(int64(c&31),15))] x) 424 (SARB x (MOVLconst [c])) => (SARBconst [int8(min(int64(c&31),7))] x) 425 426 (SARL x (ANDLconst [31] y)) => (SARL x y) 427 (SHLL x (ANDLconst [31] y)) => (SHLL x y) 428 (SHRL x (ANDLconst [31] y)) => (SHRL x y) 429 430 // Constant shift simplifications 431 432 (SHLLconst x [0]) => x 433 (SHRLconst x [0]) => x 434 (SARLconst x [0]) => x 435 436 (SHRWconst x [0]) => x 437 (SARWconst x [0]) => x 438 439 (SHRBconst x [0]) => x 440 (SARBconst x [0]) => x 441 442 (ROLLconst [0] x) => x 443 (ROLWconst [0] x) => x 444 (ROLBconst [0] x) => x 445 446 // Note: the word and byte shifts keep the low 5 bits (not the low 4 or 3 bits) 447 // because the x86 instructions are defined to use all 5 bits of the shift even 448 // for the small shifts. I don't think we'll ever generate a weird shift (e.g. 449 // (SHRW x (MOVLconst [24])), but just in case. 450 451 (CMPL x (MOVLconst [c])) => (CMPLconst x [c]) 452 (CMPL (MOVLconst [c]) x) => (InvertFlags (CMPLconst x [c])) 453 (CMPW x (MOVLconst [c])) => (CMPWconst x [int16(c)]) 454 (CMPW (MOVLconst [c]) x) => (InvertFlags (CMPWconst x [int16(c)])) 455 (CMPB x (MOVLconst [c])) => (CMPBconst x [int8(c)]) 456 (CMPB (MOVLconst [c]) x) => (InvertFlags (CMPBconst x [int8(c)])) 457 458 // Canonicalize the order of arguments to comparisons - helps with CSE. 459 (CMP(L|W|B) x y) && canonLessThan(x,y) => (InvertFlags (CMP(L|W|B) y x)) 460 461 // strength reduction 462 // Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf: 463 // 1 - addl, shll, leal, negl, subl 464 // 3 - imull 465 // This limits the rewrites to two instructions. 466 // Note that negl always operates in-place, 467 // which can require a register-register move 468 // to preserve the original value, 469 // so it must be used with care. 470 (MULLconst [-9] x) => (NEGL (LEAL8 <v.Type> x x)) 471 (MULLconst [-5] x) => (NEGL (LEAL4 <v.Type> x x)) 472 (MULLconst [-3] x) => (NEGL (LEAL2 <v.Type> x x)) 473 (MULLconst [-1] x) => (NEGL x) 474 (MULLconst [0] _) => (MOVLconst [0]) 475 (MULLconst [1] x) => x 476 (MULLconst [3] x) => (LEAL2 x x) 477 (MULLconst [5] x) => (LEAL4 x x) 478 (MULLconst [7] x) => (LEAL2 x (LEAL2 <v.Type> x x)) 479 (MULLconst [9] x) => (LEAL8 x x) 480 (MULLconst [11] x) => (LEAL2 x (LEAL4 <v.Type> x x)) 481 (MULLconst [13] x) => (LEAL4 x (LEAL2 <v.Type> x x)) 482 (MULLconst [19] x) => (LEAL2 x (LEAL8 <v.Type> x x)) 483 (MULLconst [21] x) => (LEAL4 x (LEAL4 <v.Type> x x)) 484 (MULLconst [25] x) => (LEAL8 x (LEAL2 <v.Type> x x)) 485 (MULLconst [27] x) => (LEAL8 (LEAL2 <v.Type> x x) (LEAL2 <v.Type> x x)) 486 (MULLconst [37] x) => (LEAL4 x (LEAL8 <v.Type> x x)) 487 (MULLconst [41] x) => (LEAL8 x (LEAL4 <v.Type> x x)) 488 (MULLconst [45] x) => (LEAL8 (LEAL4 <v.Type> x x) (LEAL4 <v.Type> x x)) 489 (MULLconst [73] x) => (LEAL8 x (LEAL8 <v.Type> x x)) 490 (MULLconst [81] x) => (LEAL8 (LEAL8 <v.Type> x x) (LEAL8 <v.Type> x x)) 491 492 (MULLconst [c] x) && isPowerOfTwo32(c+1) && c >= 15 => (SUBL (SHLLconst <v.Type> [int32(log32(c+1))] x) x) 493 (MULLconst [c] x) && isPowerOfTwo32(c-1) && c >= 17 => (LEAL1 (SHLLconst <v.Type> [int32(log32(c-1))] x) x) 494 (MULLconst [c] x) && isPowerOfTwo32(c-2) && c >= 34 => (LEAL2 (SHLLconst <v.Type> [int32(log32(c-2))] x) x) 495 (MULLconst [c] x) && isPowerOfTwo32(c-4) && c >= 68 => (LEAL4 (SHLLconst <v.Type> [int32(log32(c-4))] x) x) 496 (MULLconst [c] x) && isPowerOfTwo32(c-8) && c >= 136 => (LEAL8 (SHLLconst <v.Type> [int32(log32(c-8))] x) x) 497 (MULLconst [c] x) && c%3 == 0 && isPowerOfTwo32(c/3) => (SHLLconst [int32(log32(c/3))] (LEAL2 <v.Type> x x)) 498 (MULLconst [c] x) && c%5 == 0 && isPowerOfTwo32(c/5) => (SHLLconst [int32(log32(c/5))] (LEAL4 <v.Type> x x)) 499 (MULLconst [c] x) && c%9 == 0 && isPowerOfTwo32(c/9) => (SHLLconst [int32(log32(c/9))] (LEAL8 <v.Type> x x)) 500 501 // combine add/shift into LEAL 502 (ADDL x (SHLLconst [3] y)) => (LEAL8 x y) 503 (ADDL x (SHLLconst [2] y)) => (LEAL4 x y) 504 (ADDL x (SHLLconst [1] y)) => (LEAL2 x y) 505 (ADDL x (ADDL y y)) => (LEAL2 x y) 506 (ADDL x (ADDL x y)) => (LEAL2 y x) 507 508 // combine ADDL/ADDLconst into LEAL1 509 (ADDLconst [c] (ADDL x y)) => (LEAL1 [c] x y) 510 (ADDL (ADDLconst [c] x) y) => (LEAL1 [c] x y) 511 512 // fold ADDL into LEAL 513 (ADDLconst [c] (LEAL [d] {s} x)) && is32Bit(int64(c)+int64(d)) => (LEAL [c+d] {s} x) 514 (LEAL [c] {s} (ADDLconst [d] x)) && is32Bit(int64(c)+int64(d)) => (LEAL [c+d] {s} x) 515 (ADDLconst [c] x:(SP)) => (LEAL [c] x) // so it is rematerializeable 516 (LEAL [c] {s} (ADDL x y)) && x.Op != OpSB && y.Op != OpSB => (LEAL1 [c] {s} x y) 517 (ADDL x (LEAL [c] {s} y)) && x.Op != OpSB && y.Op != OpSB => (LEAL1 [c] {s} x y) 518 519 // fold ADDLconst into LEALx 520 (ADDLconst [c] (LEAL1 [d] {s} x y)) && is32Bit(int64(c)+int64(d)) => (LEAL1 [c+d] {s} x y) 521 (ADDLconst [c] (LEAL2 [d] {s} x y)) && is32Bit(int64(c)+int64(d)) => (LEAL2 [c+d] {s} x y) 522 (ADDLconst [c] (LEAL4 [d] {s} x y)) && is32Bit(int64(c)+int64(d)) => (LEAL4 [c+d] {s} x y) 523 (ADDLconst [c] (LEAL8 [d] {s} x y)) && is32Bit(int64(c)+int64(d)) => (LEAL8 [c+d] {s} x y) 524 (LEAL1 [c] {s} (ADDLconst [d] x) y) && is32Bit(int64(c)+int64(d)) && x.Op != OpSB => (LEAL1 [c+d] {s} x y) 525 (LEAL2 [c] {s} (ADDLconst [d] x) y) && is32Bit(int64(c)+int64(d)) && x.Op != OpSB => (LEAL2 [c+d] {s} x y) 526 (LEAL2 [c] {s} x (ADDLconst [d] y)) && is32Bit(int64(c)+2*int64(d)) && y.Op != OpSB => (LEAL2 [c+2*d] {s} x y) 527 (LEAL4 [c] {s} (ADDLconst [d] x) y) && is32Bit(int64(c)+int64(d)) && x.Op != OpSB => (LEAL4 [c+d] {s} x y) 528 (LEAL4 [c] {s} x (ADDLconst [d] y)) && is32Bit(int64(c)+4*int64(d)) && y.Op != OpSB => (LEAL4 [c+4*d] {s} x y) 529 (LEAL8 [c] {s} (ADDLconst [d] x) y) && is32Bit(int64(c)+int64(d)) && x.Op != OpSB => (LEAL8 [c+d] {s} x y) 530 (LEAL8 [c] {s} x (ADDLconst [d] y)) && is32Bit(int64(c)+8*int64(d)) && y.Op != OpSB => (LEAL8 [c+8*d] {s} x y) 531 532 // fold shifts into LEALx 533 (LEAL1 [c] {s} x (SHLLconst [1] y)) => (LEAL2 [c] {s} x y) 534 (LEAL1 [c] {s} x (SHLLconst [2] y)) => (LEAL4 [c] {s} x y) 535 (LEAL1 [c] {s} x (SHLLconst [3] y)) => (LEAL8 [c] {s} x y) 536 (LEAL2 [c] {s} x (SHLLconst [1] y)) => (LEAL4 [c] {s} x y) 537 (LEAL2 [c] {s} x (SHLLconst [2] y)) => (LEAL8 [c] {s} x y) 538 (LEAL4 [c] {s} x (SHLLconst [1] y)) => (LEAL8 [c] {s} x y) 539 540 // reverse ordering of compare instruction 541 (SETL (InvertFlags x)) => (SETG x) 542 (SETG (InvertFlags x)) => (SETL x) 543 (SETB (InvertFlags x)) => (SETA x) 544 (SETA (InvertFlags x)) => (SETB x) 545 (SETLE (InvertFlags x)) => (SETGE x) 546 (SETGE (InvertFlags x)) => (SETLE x) 547 (SETBE (InvertFlags x)) => (SETAE x) 548 (SETAE (InvertFlags x)) => (SETBE x) 549 (SETEQ (InvertFlags x)) => (SETEQ x) 550 (SETNE (InvertFlags x)) => (SETNE x) 551 552 // sign extended loads 553 // Note: The combined instruction must end up in the same block 554 // as the original load. If not, we end up making a value with 555 // memory type live in two different blocks, which can lead to 556 // multiple memory values alive simultaneously. 557 // Make sure we don't combine these ops if the load has another use. 558 // This prevents a single load from being split into multiple loads 559 // which then might return different values. See test/atomicload.go. 560 (MOVBLSX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) => @x.Block (MOVBLSXload <v.Type> [off] {sym} ptr mem) 561 (MOVBLZX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) => @x.Block (MOVBload <v.Type> [off] {sym} ptr mem) 562 (MOVWLSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) => @x.Block (MOVWLSXload <v.Type> [off] {sym} ptr mem) 563 (MOVWLZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) => @x.Block (MOVWload <v.Type> [off] {sym} ptr mem) 564 565 // replace load from same location as preceding store with zero/sign extension (or copy in case of full width) 566 (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) => (MOVBLZX x) 567 (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) => (MOVWLZX x) 568 (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) => x 569 (MOVBLSXload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) => (MOVBLSX x) 570 (MOVWLSXload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) => (MOVWLSX x) 571 572 // Fold extensions and ANDs together. 573 (MOVBLZX (ANDLconst [c] x)) => (ANDLconst [c & 0xff] x) 574 (MOVWLZX (ANDLconst [c] x)) => (ANDLconst [c & 0xffff] x) 575 (MOVBLSX (ANDLconst [c] x)) && c & 0x80 == 0 => (ANDLconst [c & 0x7f] x) 576 (MOVWLSX (ANDLconst [c] x)) && c & 0x8000 == 0 => (ANDLconst [c & 0x7fff] x) 577 578 // Don't extend before storing 579 (MOVWstore [off] {sym} ptr (MOVWL(S|Z)X x) mem) => (MOVWstore [off] {sym} ptr x mem) 580 (MOVBstore [off] {sym} ptr (MOVBL(S|Z)X x) mem) => (MOVBstore [off] {sym} ptr x mem) 581 582 // fold constants into memory operations 583 // Note that this is not always a good idea because if not all the uses of 584 // the ADDLconst get eliminated, we still have to compute the ADDLconst and we now 585 // have potentially two live values (ptr and (ADDLconst [off] ptr)) instead of one. 586 // Nevertheless, let's do it! 587 (MOV(L|W|B|SS|SD)load [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(int64(off1)+int64(off2)) => 588 (MOV(L|W|B|SS|SD)load [off1+off2] {sym} ptr mem) 589 (MOV(L|W|B|SS|SD)store [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(int64(off1)+int64(off2)) => 590 (MOV(L|W|B|SS|SD)store [off1+off2] {sym} ptr val mem) 591 592 ((ADD|SUB|MUL|AND|OR|XOR)Lload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(int64(off1)+int64(off2)) => 593 ((ADD|SUB|MUL|AND|OR|XOR)Lload [off1+off2] {sym} val base mem) 594 ((ADD|SUB|MUL|DIV)SSload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(int64(off1)+int64(off2)) => 595 ((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem) 596 ((ADD|SUB|MUL|DIV)SDload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(int64(off1)+int64(off2)) => 597 ((ADD|SUB|MUL|DIV)SDload [off1+off2] {sym} val base mem) 598 ((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym} (ADDLconst [off2] base) val mem) && is32Bit(int64(off1)+int64(off2)) => 599 ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {sym} base val mem) 600 ((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym} (ADDLconst [off2] base) mem) && valoff1.canAdd32(off2) => 601 ((ADD|AND|OR|XOR)Lconstmodify [valoff1.addOffset32(off2)] {sym} base mem) 602 603 // Fold constants into stores. 604 (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) => 605 (MOVLstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 606 (MOVWstore [off] {sym} ptr (MOVLconst [c]) mem) => 607 (MOVWstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 608 (MOVBstore [off] {sym} ptr (MOVLconst [c]) mem) => 609 (MOVBstoreconst [makeValAndOff(c,off)] {sym} ptr mem) 610 611 // Fold address offsets into constant stores. 612 (MOV(L|W|B)storeconst [sc] {s} (ADDLconst [off] ptr) mem) && sc.canAdd32(off) => 613 (MOV(L|W|B)storeconst [sc.addOffset32(off)] {s} ptr mem) 614 615 // We need to fold LEAL into the MOVx ops so that the live variable analysis knows 616 // what variables are being read/written by the ops. 617 // Note: we turn off this merging for operations on globals when building 618 // position-independent code (when Flag_shared is set). 619 // PIC needs a spare register to load the PC into. Having the LEAL be 620 // a separate instruction gives us that register. Having the LEAL be 621 // a separate instruction also allows it to be CSEd (which is good because 622 // it compiles to a thunk call). 623 (MOV(L|W|B|SS|SD|BLSX|WLSX)load [off1] {sym1} (LEAL [off2] {sym2} base) mem) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) 624 && (base.Op != OpSB || !config.ctxt.Flag_shared) => 625 (MOV(L|W|B|SS|SD|BLSX|WLSX)load [off1+off2] {mergeSym(sym1,sym2)} base mem) 626 627 (MOV(L|W|B|SS|SD)store [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) 628 && (base.Op != OpSB || !config.ctxt.Flag_shared) => 629 (MOV(L|W|B|SS|SD)store [off1+off2] {mergeSym(sym1,sym2)} base val mem) 630 631 (MOV(L|W|B)storeconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && sc.canAdd32(off) 632 && (ptr.Op != OpSB || !config.ctxt.Flag_shared) => 633 (MOV(L|W|B)storeconst [sc.addOffset32(off)] {mergeSym(sym1, sym2)} ptr mem) 634 635 ((ADD|SUB|MUL|AND|OR|XOR)Lload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) 636 && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) => 637 ((ADD|SUB|MUL|AND|OR|XOR)Lload [off1+off2] {mergeSym(sym1,sym2)} val base mem) 638 ((ADD|SUB|MUL|DIV)SSload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) 639 && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) => 640 ((ADD|SUB|MUL|DIV)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) 641 ((ADD|SUB|MUL|DIV)SDload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) 642 && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) => 643 ((ADD|SUB|MUL|DIV)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) 644 ((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym1} (LEAL [off2] {sym2} base) val mem) 645 && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) => 646 ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) 647 ((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym1} (LEAL [off2] {sym2} base) mem) 648 && valoff1.canAdd32(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) => 649 ((ADD|AND|OR|XOR)Lconstmodify [valoff1.addOffset32(off2)] {mergeSym(sym1,sym2)} base mem) 650 651 // Merge load/store to op 652 ((ADD|AND|OR|XOR|SUB|MUL)L x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoadClobber(v, l, x) && clobber(l) => ((ADD|AND|OR|XOR|SUB|MUL)Lload x [off] {sym} ptr mem) 653 ((ADD|SUB|MUL|DIV)SD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoadClobber(v, l, x) && clobber(l) => ((ADD|SUB|MUL|DIV)SDload x [off] {sym} ptr mem) 654 ((ADD|SUB|MUL|DIV)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoadClobber(v, l, x) && clobber(l) => ((ADD|SUB|MUL|DIV)SSload x [off] {sym} ptr mem) 655 (MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) => ((ADD|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) 656 (MOVLstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)L l:(MOVLload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y, l) => 657 ((ADD|SUB|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) 658 (MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lconst [c] l:(MOVLload [off] {sym} ptr mem)) mem) 659 && y.Uses==1 && l.Uses==1 && clobber(y, l) => 660 ((ADD|AND|OR|XOR)Lconstmodify [makeValAndOff(c,off)] {sym} ptr mem) 661 662 // fold LEALs together 663 (LEAL [off1] {sym1} (LEAL [off2] {sym2} x)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 664 (LEAL [off1+off2] {mergeSym(sym1,sym2)} x) 665 666 // LEAL into LEAL1 667 (LEAL1 [off1] {sym1} (LEAL [off2] {sym2} x) y) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && x.Op != OpSB => 668 (LEAL1 [off1+off2] {mergeSym(sym1,sym2)} x y) 669 670 // LEAL1 into LEAL 671 (LEAL [off1] {sym1} (LEAL1 [off2] {sym2} x y)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 672 (LEAL1 [off1+off2] {mergeSym(sym1,sym2)} x y) 673 674 // LEAL into LEAL[248] 675 (LEAL2 [off1] {sym1} (LEAL [off2] {sym2} x) y) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && x.Op != OpSB => 676 (LEAL2 [off1+off2] {mergeSym(sym1,sym2)} x y) 677 (LEAL4 [off1] {sym1} (LEAL [off2] {sym2} x) y) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && x.Op != OpSB => 678 (LEAL4 [off1+off2] {mergeSym(sym1,sym2)} x y) 679 (LEAL8 [off1] {sym1} (LEAL [off2] {sym2} x) y) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) && x.Op != OpSB => 680 (LEAL8 [off1+off2] {mergeSym(sym1,sym2)} x y) 681 682 // LEAL[248] into LEAL 683 (LEAL [off1] {sym1} (LEAL2 [off2] {sym2} x y)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 684 (LEAL2 [off1+off2] {mergeSym(sym1,sym2)} x y) 685 (LEAL [off1] {sym1} (LEAL4 [off2] {sym2} x y)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 686 (LEAL4 [off1+off2] {mergeSym(sym1,sym2)} x y) 687 (LEAL [off1] {sym1} (LEAL8 [off2] {sym2} x y)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 688 (LEAL8 [off1+off2] {mergeSym(sym1,sym2)} x y) 689 690 // LEAL[1248] into LEAL[1248]. Only some such merges are possible. 691 (LEAL1 [off1] {sym1} x (LEAL1 [off2] {sym2} y y)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 692 (LEAL2 [off1+off2] {mergeSym(sym1, sym2)} x y) 693 (LEAL1 [off1] {sym1} x (LEAL1 [off2] {sym2} x y)) && is32Bit(int64(off1)+int64(off2)) && canMergeSym(sym1, sym2) => 694 (LEAL2 [off1+off2] {mergeSym(sym1, sym2)} y x) 695 (LEAL2 [off1] {sym} x (LEAL1 [off2] {nil} y y)) && is32Bit(int64(off1)+2*int64(off2)) => 696 (LEAL4 [off1+2*off2] {sym} x y) 697 (LEAL4 [off1] {sym} x (LEAL1 [off2] {nil} y y)) && is32Bit(int64(off1)+4*int64(off2)) => 698 (LEAL8 [off1+4*off2] {sym} x y) 699 700 // Absorb InvertFlags into branches. 701 (LT (InvertFlags cmp) yes no) => (GT cmp yes no) 702 (GT (InvertFlags cmp) yes no) => (LT cmp yes no) 703 (LE (InvertFlags cmp) yes no) => (GE cmp yes no) 704 (GE (InvertFlags cmp) yes no) => (LE cmp yes no) 705 (ULT (InvertFlags cmp) yes no) => (UGT cmp yes no) 706 (UGT (InvertFlags cmp) yes no) => (ULT cmp yes no) 707 (ULE (InvertFlags cmp) yes no) => (UGE cmp yes no) 708 (UGE (InvertFlags cmp) yes no) => (ULE cmp yes no) 709 (EQ (InvertFlags cmp) yes no) => (EQ cmp yes no) 710 (NE (InvertFlags cmp) yes no) => (NE cmp yes no) 711 712 // Constant comparisons. 713 (CMPLconst (MOVLconst [x]) [y]) && x==y => (FlagEQ) 714 (CMPLconst (MOVLconst [x]) [y]) && x<y && uint32(x)<uint32(y) => (FlagLT_ULT) 715 (CMPLconst (MOVLconst [x]) [y]) && x<y && uint32(x)>uint32(y) => (FlagLT_UGT) 716 (CMPLconst (MOVLconst [x]) [y]) && x>y && uint32(x)<uint32(y) => (FlagGT_ULT) 717 (CMPLconst (MOVLconst [x]) [y]) && x>y && uint32(x)>uint32(y) => (FlagGT_UGT) 718 719 (CMPWconst (MOVLconst [x]) [y]) && int16(x)==y => (FlagEQ) 720 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<y && uint16(x)<uint16(y) => (FlagLT_ULT) 721 (CMPWconst (MOVLconst [x]) [y]) && int16(x)<y && uint16(x)>uint16(y) => (FlagLT_UGT) 722 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>y && uint16(x)<uint16(y) => (FlagGT_ULT) 723 (CMPWconst (MOVLconst [x]) [y]) && int16(x)>y && uint16(x)>uint16(y) => (FlagGT_UGT) 724 725 (CMPBconst (MOVLconst [x]) [y]) && int8(x)==y => (FlagEQ) 726 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<y && uint8(x)<uint8(y) => (FlagLT_ULT) 727 (CMPBconst (MOVLconst [x]) [y]) && int8(x)<y && uint8(x)>uint8(y) => (FlagLT_UGT) 728 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>y && uint8(x)<uint8(y) => (FlagGT_ULT) 729 (CMPBconst (MOVLconst [x]) [y]) && int8(x)>y && uint8(x)>uint8(y) => (FlagGT_UGT) 730 731 // Other known comparisons. 732 (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) => (FlagLT_ULT) 733 (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= m && m < n => (FlagLT_ULT) 734 (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < n => (FlagLT_ULT) 735 (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < n => (FlagLT_ULT) 736 // TODO: DIVxU also. 737 738 // Absorb flag constants into SBB ops. 739 (SBBLcarrymask (FlagEQ)) => (MOVLconst [0]) 740 (SBBLcarrymask (FlagLT_ULT)) => (MOVLconst [-1]) 741 (SBBLcarrymask (FlagLT_UGT)) => (MOVLconst [0]) 742 (SBBLcarrymask (FlagGT_ULT)) => (MOVLconst [-1]) 743 (SBBLcarrymask (FlagGT_UGT)) => (MOVLconst [0]) 744 745 // Absorb flag constants into branches. 746 (EQ (FlagEQ) yes no) => (First yes no) 747 (EQ (FlagLT_ULT) yes no) => (First no yes) 748 (EQ (FlagLT_UGT) yes no) => (First no yes) 749 (EQ (FlagGT_ULT) yes no) => (First no yes) 750 (EQ (FlagGT_UGT) yes no) => (First no yes) 751 752 (NE (FlagEQ) yes no) => (First no yes) 753 (NE (FlagLT_ULT) yes no) => (First yes no) 754 (NE (FlagLT_UGT) yes no) => (First yes no) 755 (NE (FlagGT_ULT) yes no) => (First yes no) 756 (NE (FlagGT_UGT) yes no) => (First yes no) 757 758 (LT (FlagEQ) yes no) => (First no yes) 759 (LT (FlagLT_ULT) yes no) => (First yes no) 760 (LT (FlagLT_UGT) yes no) => (First yes no) 761 (LT (FlagGT_ULT) yes no) => (First no yes) 762 (LT (FlagGT_UGT) yes no) => (First no yes) 763 764 (LE (FlagEQ) yes no) => (First yes no) 765 (LE (FlagLT_ULT) yes no) => (First yes no) 766 (LE (FlagLT_UGT) yes no) => (First yes no) 767 (LE (FlagGT_ULT) yes no) => (First no yes) 768 (LE (FlagGT_UGT) yes no) => (First no yes) 769 770 (GT (FlagEQ) yes no) => (First no yes) 771 (GT (FlagLT_ULT) yes no) => (First no yes) 772 (GT (FlagLT_UGT) yes no) => (First no yes) 773 (GT (FlagGT_ULT) yes no) => (First yes no) 774 (GT (FlagGT_UGT) yes no) => (First yes no) 775 776 (GE (FlagEQ) yes no) => (First yes no) 777 (GE (FlagLT_ULT) yes no) => (First no yes) 778 (GE (FlagLT_UGT) yes no) => (First no yes) 779 (GE (FlagGT_ULT) yes no) => (First yes no) 780 (GE (FlagGT_UGT) yes no) => (First yes no) 781 782 (ULT (FlagEQ) yes no) => (First no yes) 783 (ULT (FlagLT_ULT) yes no) => (First yes no) 784 (ULT (FlagLT_UGT) yes no) => (First no yes) 785 (ULT (FlagGT_ULT) yes no) => (First yes no) 786 (ULT (FlagGT_UGT) yes no) => (First no yes) 787 788 (ULE (FlagEQ) yes no) => (First yes no) 789 (ULE (FlagLT_ULT) yes no) => (First yes no) 790 (ULE (FlagLT_UGT) yes no) => (First no yes) 791 (ULE (FlagGT_ULT) yes no) => (First yes no) 792 (ULE (FlagGT_UGT) yes no) => (First no yes) 793 794 (UGT (FlagEQ) yes no) => (First no yes) 795 (UGT (FlagLT_ULT) yes no) => (First no yes) 796 (UGT (FlagLT_UGT) yes no) => (First yes no) 797 (UGT (FlagGT_ULT) yes no) => (First no yes) 798 (UGT (FlagGT_UGT) yes no) => (First yes no) 799 800 (UGE (FlagEQ) yes no) => (First yes no) 801 (UGE (FlagLT_ULT) yes no) => (First no yes) 802 (UGE (FlagLT_UGT) yes no) => (First yes no) 803 (UGE (FlagGT_ULT) yes no) => (First no yes) 804 (UGE (FlagGT_UGT) yes no) => (First yes no) 805 806 // Absorb flag constants into SETxx ops. 807 (SETEQ (FlagEQ)) => (MOVLconst [1]) 808 (SETEQ (FlagLT_ULT)) => (MOVLconst [0]) 809 (SETEQ (FlagLT_UGT)) => (MOVLconst [0]) 810 (SETEQ (FlagGT_ULT)) => (MOVLconst [0]) 811 (SETEQ (FlagGT_UGT)) => (MOVLconst [0]) 812 813 (SETNE (FlagEQ)) => (MOVLconst [0]) 814 (SETNE (FlagLT_ULT)) => (MOVLconst [1]) 815 (SETNE (FlagLT_UGT)) => (MOVLconst [1]) 816 (SETNE (FlagGT_ULT)) => (MOVLconst [1]) 817 (SETNE (FlagGT_UGT)) => (MOVLconst [1]) 818 819 (SETL (FlagEQ)) => (MOVLconst [0]) 820 (SETL (FlagLT_ULT)) => (MOVLconst [1]) 821 (SETL (FlagLT_UGT)) => (MOVLconst [1]) 822 (SETL (FlagGT_ULT)) => (MOVLconst [0]) 823 (SETL (FlagGT_UGT)) => (MOVLconst [0]) 824 825 (SETLE (FlagEQ)) => (MOVLconst [1]) 826 (SETLE (FlagLT_ULT)) => (MOVLconst [1]) 827 (SETLE (FlagLT_UGT)) => (MOVLconst [1]) 828 (SETLE (FlagGT_ULT)) => (MOVLconst [0]) 829 (SETLE (FlagGT_UGT)) => (MOVLconst [0]) 830 831 (SETG (FlagEQ)) => (MOVLconst [0]) 832 (SETG (FlagLT_ULT)) => (MOVLconst [0]) 833 (SETG (FlagLT_UGT)) => (MOVLconst [0]) 834 (SETG (FlagGT_ULT)) => (MOVLconst [1]) 835 (SETG (FlagGT_UGT)) => (MOVLconst [1]) 836 837 (SETGE (FlagEQ)) => (MOVLconst [1]) 838 (SETGE (FlagLT_ULT)) => (MOVLconst [0]) 839 (SETGE (FlagLT_UGT)) => (MOVLconst [0]) 840 (SETGE (FlagGT_ULT)) => (MOVLconst [1]) 841 (SETGE (FlagGT_UGT)) => (MOVLconst [1]) 842 843 (SETB (FlagEQ)) => (MOVLconst [0]) 844 (SETB (FlagLT_ULT)) => (MOVLconst [1]) 845 (SETB (FlagLT_UGT)) => (MOVLconst [0]) 846 (SETB (FlagGT_ULT)) => (MOVLconst [1]) 847 (SETB (FlagGT_UGT)) => (MOVLconst [0]) 848 849 (SETBE (FlagEQ)) => (MOVLconst [1]) 850 (SETBE (FlagLT_ULT)) => (MOVLconst [1]) 851 (SETBE (FlagLT_UGT)) => (MOVLconst [0]) 852 (SETBE (FlagGT_ULT)) => (MOVLconst [1]) 853 (SETBE (FlagGT_UGT)) => (MOVLconst [0]) 854 855 (SETA (FlagEQ)) => (MOVLconst [0]) 856 (SETA (FlagLT_ULT)) => (MOVLconst [0]) 857 (SETA (FlagLT_UGT)) => (MOVLconst [1]) 858 (SETA (FlagGT_ULT)) => (MOVLconst [0]) 859 (SETA (FlagGT_UGT)) => (MOVLconst [1]) 860 861 (SETAE (FlagEQ)) => (MOVLconst [1]) 862 (SETAE (FlagLT_ULT)) => (MOVLconst [0]) 863 (SETAE (FlagLT_UGT)) => (MOVLconst [1]) 864 (SETAE (FlagGT_ULT)) => (MOVLconst [0]) 865 (SETAE (FlagGT_UGT)) => (MOVLconst [1]) 866 867 // Remove redundant *const ops 868 (ADDLconst [c] x) && c==0 => x 869 (SUBLconst [c] x) && c==0 => x 870 (ANDLconst [c] _) && c==0 => (MOVLconst [0]) 871 (ANDLconst [c] x) && c==-1 => x 872 (ORLconst [c] x) && c==0 => x 873 (ORLconst [c] _) && c==-1 => (MOVLconst [-1]) 874 (XORLconst [c] x) && c==0 => x 875 // TODO: since we got rid of the W/B versions, we might miss 876 // things like (ANDLconst [0x100] x) which were formerly 877 // (ANDBconst [0] x). Probably doesn't happen very often. 878 // If we cared, we might do: 879 // (ANDLconst <t> [c] x) && t.Size()==1 && int8(x)==0 => (MOVLconst [0]) 880 881 // Convert constant subtracts to constant adds 882 (SUBLconst [c] x) => (ADDLconst [-c] x) 883 884 // generic constant folding 885 // TODO: more of this 886 (ADDLconst [c] (MOVLconst [d])) => (MOVLconst [c+d]) 887 (ADDLconst [c] (ADDLconst [d] x)) => (ADDLconst [c+d] x) 888 (SARLconst [c] (MOVLconst [d])) => (MOVLconst [d>>uint64(c)]) 889 (SARWconst [c] (MOVLconst [d])) => (MOVLconst [d>>uint64(c)]) 890 (SARBconst [c] (MOVLconst [d])) => (MOVLconst [d>>uint64(c)]) 891 (NEGL (MOVLconst [c])) => (MOVLconst [-c]) 892 (MULLconst [c] (MOVLconst [d])) => (MOVLconst [c*d]) 893 (ANDLconst [c] (MOVLconst [d])) => (MOVLconst [c&d]) 894 (ORLconst [c] (MOVLconst [d])) => (MOVLconst [c|d]) 895 (XORLconst [c] (MOVLconst [d])) => (MOVLconst [c^d]) 896 (NOTL (MOVLconst [c])) => (MOVLconst [^c]) 897 898 // generic simplifications 899 // TODO: more of this 900 (ADDL x (NEGL y)) => (SUBL x y) 901 (SUBL x x) => (MOVLconst [0]) 902 (ANDL x x) => x 903 (ORL x x) => x 904 (XORL x x) => (MOVLconst [0]) 905 906 // checking AND against 0. 907 (CMP(L|W|B)const l:(ANDL x y) [0]) && l.Uses==1 => (TEST(L|W|B) x y) 908 (CMPLconst l:(ANDLconst [c] x) [0]) && l.Uses==1 => (TESTLconst [c] x) 909 (CMPWconst l:(ANDLconst [c] x) [0]) && l.Uses==1 => (TESTWconst [int16(c)] x) 910 (CMPBconst l:(ANDLconst [c] x) [0]) && l.Uses==1 => (TESTBconst [int8(c)] x) 911 912 // TEST %reg,%reg is shorter than CMP 913 (CMP(L|W|B)const x [0]) => (TEST(L|W|B) x x) 914 915 // Convert LEAL1 back to ADDL if we can 916 (LEAL1 [0] {nil} x y) => (ADDL x y) 917 918 // Combining byte loads into larger (unaligned) loads. 919 // There are many ways these combinations could occur. This is 920 // designed to match the way encoding/binary.LittleEndian does it. 921 (ORL x0:(MOVBload [i0] {s} p mem) 922 s0:(SHLLconst [8] x1:(MOVBload [i1] {s} p mem))) 923 && i1 == i0+1 924 && x0.Uses == 1 925 && x1.Uses == 1 926 && s0.Uses == 1 927 && mergePoint(b,x0,x1) != nil 928 && clobber(x0, x1, s0) 929 => @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem) 930 931 (ORL x0:(MOVBload [i] {s} p0 mem) 932 s0:(SHLLconst [8] x1:(MOVBload [i] {s} p1 mem))) 933 && x0.Uses == 1 934 && x1.Uses == 1 935 && s0.Uses == 1 936 && sequentialAddresses(p0, p1, 1) 937 && mergePoint(b,x0,x1) != nil 938 && clobber(x0, x1, s0) 939 => @mergePoint(b,x0,x1) (MOVWload [i] {s} p0 mem) 940 941 (ORL o0:(ORL 942 x0:(MOVWload [i0] {s} p mem) 943 s0:(SHLLconst [16] x1:(MOVBload [i2] {s} p mem))) 944 s1:(SHLLconst [24] x2:(MOVBload [i3] {s} p mem))) 945 && i2 == i0+2 946 && i3 == i0+3 947 && x0.Uses == 1 948 && x1.Uses == 1 949 && x2.Uses == 1 950 && s0.Uses == 1 951 && s1.Uses == 1 952 && o0.Uses == 1 953 && mergePoint(b,x0,x1,x2) != nil 954 && clobber(x0, x1, x2, s0, s1, o0) 955 => @mergePoint(b,x0,x1,x2) (MOVLload [i0] {s} p mem) 956 957 (ORL o0:(ORL 958 x0:(MOVWload [i] {s} p0 mem) 959 s0:(SHLLconst [16] x1:(MOVBload [i] {s} p1 mem))) 960 s1:(SHLLconst [24] x2:(MOVBload [i] {s} p2 mem))) 961 && x0.Uses == 1 962 && x1.Uses == 1 963 && x2.Uses == 1 964 && s0.Uses == 1 965 && s1.Uses == 1 966 && o0.Uses == 1 967 && sequentialAddresses(p0, p1, 2) 968 && sequentialAddresses(p1, p2, 1) 969 && mergePoint(b,x0,x1,x2) != nil 970 && clobber(x0, x1, x2, s0, s1, o0) 971 => @mergePoint(b,x0,x1,x2) (MOVLload [i] {s} p0 mem) 972 973 // Combine constant stores into larger (unaligned) stores. 974 (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem)) 975 && x.Uses == 1 976 && a.Off() + 1 == c.Off() 977 && clobber(x) 978 => (MOVWstoreconst [makeValAndOff(a.Val()&0xff | c.Val()<<8, a.Off())] {s} p mem) 979 (MOVBstoreconst [a] {s} p x:(MOVBstoreconst [c] {s} p mem)) 980 && x.Uses == 1 981 && a.Off() + 1 == c.Off() 982 && clobber(x) 983 => (MOVWstoreconst [makeValAndOff(a.Val()&0xff | c.Val()<<8, a.Off())] {s} p mem) 984 985 (MOVBstoreconst [c] {s} p1 x:(MOVBstoreconst [a] {s} p0 mem)) 986 && x.Uses == 1 987 && a.Off() == c.Off() 988 && sequentialAddresses(p0, p1, 1) 989 && clobber(x) 990 => (MOVWstoreconst [makeValAndOff(a.Val()&0xff | c.Val()<<8, a.Off())] {s} p0 mem) 991 (MOVBstoreconst [a] {s} p0 x:(MOVBstoreconst [c] {s} p1 mem)) 992 && x.Uses == 1 993 && a.Off() == c.Off() 994 && sequentialAddresses(p0, p1, 1) 995 && clobber(x) 996 => (MOVWstoreconst [makeValAndOff(a.Val()&0xff | c.Val()<<8, a.Off())] {s} p0 mem) 997 998 (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem)) 999 && x.Uses == 1 1000 && a.Off() + 2 == c.Off() 1001 && clobber(x) 1002 => (MOVLstoreconst [makeValAndOff(a.Val()&0xffff | c.Val()<<16, a.Off())] {s} p mem) 1003 (MOVWstoreconst [a] {s} p x:(MOVWstoreconst [c] {s} p mem)) 1004 && x.Uses == 1 1005 && ValAndOff(a).Off() + 2 == ValAndOff(c).Off() 1006 && clobber(x) 1007 => (MOVLstoreconst [makeValAndOff(a.Val()&0xffff | c.Val()<<16, a.Off())] {s} p mem) 1008 1009 (MOVWstoreconst [c] {s} p1 x:(MOVWstoreconst [a] {s} p0 mem)) 1010 && x.Uses == 1 1011 && a.Off() == c.Off() 1012 && sequentialAddresses(p0, p1, 2) 1013 && clobber(x) 1014 => (MOVLstoreconst [makeValAndOff(a.Val()&0xffff | c.Val()<<16, a.Off())] {s} p0 mem) 1015 (MOVWstoreconst [a] {s} p0 x:(MOVWstoreconst [c] {s} p1 mem)) 1016 && x.Uses == 1 1017 && a.Off() == c.Off() 1018 && sequentialAddresses(p0, p1, 2) 1019 && clobber(x) 1020 => (MOVLstoreconst [makeValAndOff(a.Val()&0xffff | c.Val()<<16, a.Off())] {s} p0 mem) 1021 1022 // Combine stores into larger (unaligned) stores. 1023 (MOVBstore [i] {s} p (SHR(W|L)const [8] w) x:(MOVBstore [i-1] {s} p w mem)) 1024 && x.Uses == 1 1025 && clobber(x) 1026 => (MOVWstore [i-1] {s} p w mem) 1027 (MOVBstore [i] {s} p w x:(MOVBstore {s} [i+1] p (SHR(W|L)const [8] w) mem)) 1028 && x.Uses == 1 1029 && clobber(x) 1030 => (MOVWstore [i] {s} p w mem) 1031 (MOVBstore [i] {s} p (SHRLconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SHRLconst [j-8] w) mem)) 1032 && x.Uses == 1 1033 && clobber(x) 1034 => (MOVWstore [i-1] {s} p w0 mem) 1035 1036 (MOVBstore [i] {s} p1 (SHR(W|L)const [8] w) x:(MOVBstore [i] {s} p0 w mem)) 1037 && x.Uses == 1 1038 && sequentialAddresses(p0, p1, 1) 1039 && clobber(x) 1040 => (MOVWstore [i] {s} p0 w mem) 1041 (MOVBstore [i] {s} p0 w x:(MOVBstore {s} [i] p1 (SHR(W|L)const [8] w) mem)) 1042 && x.Uses == 1 1043 && sequentialAddresses(p0, p1, 1) 1044 && clobber(x) 1045 => (MOVWstore [i] {s} p0 w mem) 1046 (MOVBstore [i] {s} p1 (SHRLconst [j] w) x:(MOVBstore [i] {s} p0 w0:(SHRLconst [j-8] w) mem)) 1047 && x.Uses == 1 1048 && sequentialAddresses(p0, p1, 1) 1049 && clobber(x) 1050 => (MOVWstore [i] {s} p0 w0 mem) 1051 1052 (MOVWstore [i] {s} p (SHRLconst [16] w) x:(MOVWstore [i-2] {s} p w mem)) 1053 && x.Uses == 1 1054 && clobber(x) 1055 => (MOVLstore [i-2] {s} p w mem) 1056 (MOVWstore [i] {s} p (SHRLconst [j] w) x:(MOVWstore [i-2] {s} p w0:(SHRLconst [j-16] w) mem)) 1057 && x.Uses == 1 1058 && clobber(x) 1059 => (MOVLstore [i-2] {s} p w0 mem) 1060 1061 (MOVWstore [i] {s} p1 (SHRLconst [16] w) x:(MOVWstore [i] {s} p0 w mem)) 1062 && x.Uses == 1 1063 && sequentialAddresses(p0, p1, 2) 1064 && clobber(x) 1065 => (MOVLstore [i] {s} p0 w mem) 1066 (MOVWstore [i] {s} p1 (SHRLconst [j] w) x:(MOVWstore [i] {s} p0 w0:(SHRLconst [j-16] w) mem)) 1067 && x.Uses == 1 1068 && sequentialAddresses(p0, p1, 2) 1069 && clobber(x) 1070 => (MOVLstore [i] {s} p0 w0 mem) 1071 1072 // For PIC, break floating-point constant loading into two instructions so we have 1073 // a register to use for holding the address of the constant pool entry. 1074 (MOVSSconst [c]) && config.ctxt.Flag_shared => (MOVSSconst2 (MOVSSconst1 [c])) 1075 (MOVSDconst [c]) && config.ctxt.Flag_shared => (MOVSDconst2 (MOVSDconst1 [c])) 1076 1077 (CMP(L|W|B) l:(MOV(L|W|B)load {sym} [off] ptr mem) x) && canMergeLoad(v, l) && clobber(l) => (CMP(L|W|B)load {sym} [off] ptr x mem) 1078 (CMP(L|W|B) x l:(MOV(L|W|B)load {sym} [off] ptr mem)) && canMergeLoad(v, l) && clobber(l) => (InvertFlags (CMP(L|W|B)load {sym} [off] ptr x mem)) 1079 1080 (CMP(L|W|B)const l:(MOV(L|W|B)load {sym} [off] ptr mem) [c]) 1081 && l.Uses == 1 1082 && clobber(l) => 1083 @l.Block (CMP(L|W|B)constload {sym} [makeValAndOff(int32(c),off)] ptr mem) 1084 1085 (CMPLload {sym} [off] ptr (MOVLconst [c]) mem) => (CMPLconstload {sym} [makeValAndOff(c,off)] ptr mem) 1086 (CMPWload {sym} [off] ptr (MOVLconst [c]) mem) => (CMPWconstload {sym} [makeValAndOff(int32(int16(c)),off)] ptr mem) 1087 (CMPBload {sym} [off] ptr (MOVLconst [c]) mem) => (CMPBconstload {sym} [makeValAndOff(int32(int8(c)),off)] ptr mem) 1088 1089 (MOVBload [off] {sym} (SB) _) && symIsRO(sym) => (MOVLconst [int32(read8(sym, int64(off)))]) 1090 (MOVWload [off] {sym} (SB) _) && symIsRO(sym) => (MOVLconst [int32(read16(sym, int64(off), config.ctxt.Arch.ByteOrder))]) 1091 (MOVLload [off] {sym} (SB) _) && symIsRO(sym) => (MOVLconst [int32(read32(sym, int64(off), config.ctxt.Arch.ByteOrder))])