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