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