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