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