github.com/karrick/go@v0.0.0-20170817181416-d5b0ec858b37/src/cmd/compile/internal/ssa/gen/AMD64.rules (about)

     1  // Copyright 2015 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  (Add64  x y) -> (ADDQ  x y)
     7  (AddPtr x y) && config.PtrSize == 8 -> (ADDQ x y)
     8  (AddPtr x y) && config.PtrSize == 4 -> (ADDL x y)
     9  (Add32  x y) -> (ADDL  x y)
    10  (Add16  x y) -> (ADDL  x y)
    11  (Add8   x y) -> (ADDL  x y)
    12  (Add32F x y) -> (ADDSS x y)
    13  (Add64F x y) -> (ADDSD x y)
    14  
    15  (Sub64  x y) -> (SUBQ  x y)
    16  (SubPtr x y) && config.PtrSize == 8 -> (SUBQ x y)
    17  (SubPtr x y) && config.PtrSize == 4 -> (SUBL x y)
    18  (Sub32  x y) -> (SUBL  x y)
    19  (Sub16  x y) -> (SUBL  x y)
    20  (Sub8   x y) -> (SUBL  x y)
    21  (Sub32F x y) -> (SUBSS x y)
    22  (Sub64F x y) -> (SUBSD x y)
    23  
    24  (Mul64  x y) -> (MULQ  x y)
    25  (Mul32  x y) -> (MULL  x y)
    26  (Mul16  x y) -> (MULL  x y)
    27  (Mul8   x y) -> (MULL  x y)
    28  (Mul32F x y) -> (MULSS x y)
    29  (Mul64F x y) -> (MULSD x y)
    30  
    31  (Div32F x y) -> (DIVSS x y)
    32  (Div64F x y) -> (DIVSD x y)
    33  
    34  (Div64  x y) -> (Select0 (DIVQ  x y))
    35  (Div64u x y) -> (Select0 (DIVQU x y))
    36  (Div32  x y) -> (Select0 (DIVL  x y))
    37  (Div32u x y) -> (Select0 (DIVLU x y))
    38  (Div16  x y) -> (Select0 (DIVW  x y))
    39  (Div16u x y) -> (Select0 (DIVWU x y))
    40  (Div8   x y) -> (Select0 (DIVW  (SignExt8to16 x) (SignExt8to16 y)))
    41  (Div8u  x y) -> (Select0 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y)))
    42  
    43  (Hmul64  x y) -> (HMULQ  x y)
    44  (Hmul64u x y) -> (HMULQU x y)
    45  (Hmul32  x y) -> (HMULL  x y)
    46  (Hmul32u x y) -> (HMULLU x y)
    47  
    48  (Mul64uhilo x y) -> (MULQU2 x y)
    49  (Div128u xhi xlo y) -> (DIVQU2 xhi xlo y)
    50  
    51  (Avg64u x y) -> (AVGQU x y)
    52  
    53  (Mod64  x y) -> (Select1 (DIVQ  x y))
    54  (Mod64u x y) -> (Select1 (DIVQU x y))
    55  (Mod32  x y) -> (Select1 (DIVL  x y))
    56  (Mod32u x y) -> (Select1 (DIVLU x y))
    57  (Mod16  x y) -> (Select1 (DIVW  x y))
    58  (Mod16u x y) -> (Select1 (DIVWU x y))
    59  (Mod8   x y) -> (Select1 (DIVW  (SignExt8to16 x) (SignExt8to16 y)))
    60  (Mod8u  x y) -> (Select1 (DIVWU (ZeroExt8to16 x) (ZeroExt8to16 y)))
    61  
    62  (And64 x y) -> (ANDQ x y)
    63  (And32 x y) -> (ANDL x y)
    64  (And16 x y) -> (ANDL x y)
    65  (And8  x y) -> (ANDL x y)
    66  
    67  (Or64 x y) -> (ORQ x y)
    68  (Or32 x y) -> (ORL x y)
    69  (Or16 x y) -> (ORL x y)
    70  (Or8  x y) -> (ORL x y)
    71  
    72  (Xor64 x y) -> (XORQ x y)
    73  (Xor32 x y) -> (XORL x y)
    74  (Xor16 x y) -> (XORL x y)
    75  (Xor8  x y) -> (XORL x y)
    76  
    77  (Neg64  x) -> (NEGQ x)
    78  (Neg32  x) -> (NEGL x)
    79  (Neg16  x) -> (NEGL x)
    80  (Neg8   x) -> (NEGL x)
    81  (Neg32F x) -> (PXOR x (MOVSSconst <typ.Float32> [f2i(math.Copysign(0, -1))]))
    82  (Neg64F x) -> (PXOR x (MOVSDconst <typ.Float64> [f2i(math.Copysign(0, -1))]))
    83  
    84  (Com64 x) -> (NOTQ x)
    85  (Com32 x) -> (NOTL x)
    86  (Com16 x) -> (NOTL x)
    87  (Com8  x) -> (NOTL x)
    88  
    89  // Lowering boolean ops
    90  (AndB x y) -> (ANDL x y)
    91  (OrB x y) -> (ORL x y)
    92  (Not x) -> (XORLconst [1] x)
    93  
    94  // Lowering pointer arithmetic
    95  (OffPtr [off] ptr) && config.PtrSize == 8 && is32Bit(off) -> (ADDQconst [off] ptr)
    96  (OffPtr [off] ptr) && config.PtrSize == 8 -> (ADDQ (MOVQconst [off]) ptr)
    97  (OffPtr [off] ptr) && config.PtrSize == 4 -> (ADDLconst [off] ptr)
    98  
    99  // Lowering other arithmetic
   100  (Ctz64 <t> x) -> (CMOVQEQ (Select0 <t> (BSFQ x)) (MOVQconst <t> [64]) (Select1 <types.TypeFlags> (BSFQ x)))
   101  (Ctz32 x) -> (Select0 (BSFQ (ORQ <typ.UInt64> (MOVQconst [1<<32]) x)))
   102  
   103  (BitLen64 <t> x) -> (ADDQconst [1] (CMOVQEQ <t> (Select0 <t> (BSRQ x)) (MOVQconst <t> [-1]) (Select1 <types.TypeFlags> (BSRQ x))))
   104  (BitLen32 x) -> (BitLen64 (MOVLQZX <typ.UInt64> x))
   105  
   106  (Bswap64 x) -> (BSWAPQ x)
   107  (Bswap32 x) -> (BSWAPL x)
   108  
   109  (PopCount64 x) -> (POPCNTQ x)
   110  (PopCount32 x) -> (POPCNTL x)
   111  (PopCount16 x) -> (POPCNTL (MOVWQZX <typ.UInt32> x))
   112  (PopCount8 x) -> (POPCNTL (MOVBQZX <typ.UInt32> x))
   113  
   114  (Sqrt x) -> (SQRTSD x)
   115  
   116  // Lowering extension
   117  // Note: we always extend to 64 bits even though some ops don't need that many result bits.
   118  (SignExt8to16  x) -> (MOVBQSX x)
   119  (SignExt8to32  x) -> (MOVBQSX x)
   120  (SignExt8to64  x) -> (MOVBQSX x)
   121  (SignExt16to32 x) -> (MOVWQSX x)
   122  (SignExt16to64 x) -> (MOVWQSX x)
   123  (SignExt32to64 x) -> (MOVLQSX x)
   124  
   125  (ZeroExt8to16  x) -> (MOVBQZX x)
   126  (ZeroExt8to32  x) -> (MOVBQZX x)
   127  (ZeroExt8to64  x) -> (MOVBQZX x)
   128  (ZeroExt16to32 x) -> (MOVWQZX x)
   129  (ZeroExt16to64 x) -> (MOVWQZX x)
   130  (ZeroExt32to64 x) -> (MOVLQZX x)
   131  
   132  (Slicemask <t> x) -> (SARQconst (NEGQ <t> x) [63])
   133  
   134  // Lowering truncation
   135  // Because we ignore high parts of registers, truncates are just copies.
   136  (Trunc16to8  x) -> x
   137  (Trunc32to8  x) -> x
   138  (Trunc32to16 x) -> x
   139  (Trunc64to8  x) -> x
   140  (Trunc64to16 x) -> x
   141  (Trunc64to32 x) -> x
   142  
   143  // Lowering float <-> int
   144  (Cvt32to32F x) -> (CVTSL2SS x)
   145  (Cvt32to64F x) -> (CVTSL2SD x)
   146  (Cvt64to32F x) -> (CVTSQ2SS x)
   147  (Cvt64to64F x) -> (CVTSQ2SD x)
   148  
   149  (Cvt32Fto32 x) -> (CVTTSS2SL x)
   150  (Cvt32Fto64 x) -> (CVTTSS2SQ x)
   151  (Cvt64Fto32 x) -> (CVTTSD2SL x)
   152  (Cvt64Fto64 x) -> (CVTTSD2SQ x)
   153  
   154  (Cvt32Fto64F x) -> (CVTSS2SD x)
   155  (Cvt64Fto32F x) -> (CVTSD2SS x)
   156  
   157  (Round32F x) -> x
   158  (Round64F x) -> x
   159  
   160  // Lowering shifts
   161  // Unsigned shifts need to return 0 if shift amount is >= width of shifted value.
   162  //   result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff)
   163  (Lsh64x64 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPQconst y [64])))
   164  (Lsh64x32 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPLconst y [64])))
   165  (Lsh64x16 <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPWconst y [64])))
   166  (Lsh64x8  <t> x y) -> (ANDQ (SHLQ <t> x y) (SBBQcarrymask <t> (CMPBconst y [64])))
   167  
   168  (Lsh32x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32])))
   169  (Lsh32x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32])))
   170  (Lsh32x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32])))
   171  (Lsh32x8  <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32])))
   172  
   173  (Lsh16x64 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32])))
   174  (Lsh16x32 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32])))
   175  (Lsh16x16 <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32])))
   176  (Lsh16x8  <t> x y) -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32])))
   177  
   178  (Lsh8x64 <t> x y)  -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32])))
   179  (Lsh8x32 <t> x y)  -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32])))
   180  (Lsh8x16 <t> x y)  -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32])))
   181  (Lsh8x8  <t> x y)  -> (ANDL (SHLL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32])))
   182  
   183  (Rsh64Ux64 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPQconst y [64])))
   184  (Rsh64Ux32 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPLconst y [64])))
   185  (Rsh64Ux16 <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPWconst y [64])))
   186  (Rsh64Ux8  <t> x y) -> (ANDQ (SHRQ <t> x y) (SBBQcarrymask <t> (CMPBconst y [64])))
   187  
   188  (Rsh32Ux64 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPQconst y [32])))
   189  (Rsh32Ux32 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPLconst y [32])))
   190  (Rsh32Ux16 <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPWconst y [32])))
   191  (Rsh32Ux8  <t> x y) -> (ANDL (SHRL <t> x y) (SBBLcarrymask <t> (CMPBconst y [32])))
   192  
   193  (Rsh16Ux64 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPQconst y [16])))
   194  (Rsh16Ux32 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPLconst y [16])))
   195  (Rsh16Ux16 <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPWconst y [16])))
   196  (Rsh16Ux8  <t> x y) -> (ANDL (SHRW <t> x y) (SBBLcarrymask <t> (CMPBconst y [16])))
   197  
   198  (Rsh8Ux64 <t> x y)  -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPQconst y [8])))
   199  (Rsh8Ux32 <t> x y)  -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPLconst y [8])))
   200  (Rsh8Ux16 <t> x y)  -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPWconst y [8])))
   201  (Rsh8Ux8  <t> x y)  -> (ANDL (SHRB <t> x y) (SBBLcarrymask <t> (CMPBconst y [8])))
   202  
   203  // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value.
   204  // We implement this by setting the shift value to -1 (all ones) if the shift value is >= width.
   205  (Rsh64x64 <t> x y) -> (SARQ <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [64])))))
   206  (Rsh64x32 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [64])))))
   207  (Rsh64x16 <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [64])))))
   208  (Rsh64x8  <t> x y) -> (SARQ <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [64])))))
   209  
   210  (Rsh32x64 <t> x y) -> (SARL <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [32])))))
   211  (Rsh32x32 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [32])))))
   212  (Rsh32x16 <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [32])))))
   213  (Rsh32x8  <t> x y) -> (SARL <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [32])))))
   214  
   215  (Rsh16x64 <t> x y) -> (SARW <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [16])))))
   216  (Rsh16x32 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [16])))))
   217  (Rsh16x16 <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [16])))))
   218  (Rsh16x8  <t> x y) -> (SARW <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [16])))))
   219  
   220  (Rsh8x64 <t> x y)  -> (SARB <t> x (ORQ <y.Type> y (NOTQ <y.Type> (SBBQcarrymask <y.Type> (CMPQconst y [8])))))
   221  (Rsh8x32 <t> x y)  -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPLconst y [8])))))
   222  (Rsh8x16 <t> x y)  -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPWconst y [8])))))
   223  (Rsh8x8  <t> x y)  -> (SARB <t> x (ORL <y.Type> y (NOTL <y.Type> (SBBLcarrymask <y.Type> (CMPBconst y [8])))))
   224  
   225  // Lowering comparisons
   226  (Less64  x y) -> (SETL (CMPQ x y))
   227  (Less32  x y) -> (SETL (CMPL x y))
   228  (Less16  x y) -> (SETL (CMPW x y))
   229  (Less8   x y) -> (SETL (CMPB x y))
   230  (Less64U x y) -> (SETB (CMPQ x y))
   231  (Less32U x y) -> (SETB (CMPL x y))
   232  (Less16U x y) -> (SETB (CMPW x y))
   233  (Less8U  x y) -> (SETB (CMPB x y))
   234  // Use SETGF with reversed operands to dodge NaN case
   235  (Less64F x y) -> (SETGF (UCOMISD y x))
   236  (Less32F x y) -> (SETGF (UCOMISS y x))
   237  
   238  (Leq64  x y) -> (SETLE (CMPQ x y))
   239  (Leq32  x y) -> (SETLE (CMPL x y))
   240  (Leq16  x y) -> (SETLE (CMPW x y))
   241  (Leq8   x y) -> (SETLE (CMPB x y))
   242  (Leq64U x y) -> (SETBE (CMPQ x y))
   243  (Leq32U x y) -> (SETBE (CMPL x y))
   244  (Leq16U x y) -> (SETBE (CMPW x y))
   245  (Leq8U  x y) -> (SETBE (CMPB x y))
   246  // Use SETGEF with reversed operands to dodge NaN case
   247  (Leq64F x y) -> (SETGEF (UCOMISD y x))
   248  (Leq32F x y) -> (SETGEF (UCOMISS y x))
   249  
   250  (Greater64  x y) -> (SETG (CMPQ x y))
   251  (Greater32  x y) -> (SETG (CMPL x y))
   252  (Greater16  x y) -> (SETG (CMPW x y))
   253  (Greater8   x y) -> (SETG (CMPB x y))
   254  (Greater64U x y) -> (SETA (CMPQ x y))
   255  (Greater32U x y) -> (SETA (CMPL x y))
   256  (Greater16U x y) -> (SETA (CMPW x y))
   257  (Greater8U  x y) -> (SETA (CMPB x y))
   258  // Note Go assembler gets UCOMISx operand order wrong, but it is right here
   259  // Bug is accommodated at generation of assembly language.
   260  (Greater64F x y) -> (SETGF (UCOMISD x y))
   261  (Greater32F x y) -> (SETGF (UCOMISS x y))
   262  
   263  (Geq64  x y) -> (SETGE (CMPQ x y))
   264  (Geq32  x y) -> (SETGE (CMPL x y))
   265  (Geq16  x y) -> (SETGE (CMPW x y))
   266  (Geq8   x y) -> (SETGE (CMPB x y))
   267  (Geq64U x y) -> (SETAE (CMPQ x y))
   268  (Geq32U x y) -> (SETAE (CMPL x y))
   269  (Geq16U x y) -> (SETAE (CMPW x y))
   270  (Geq8U  x y) -> (SETAE (CMPB x y))
   271  // Note Go assembler gets UCOMISx operand order wrong, but it is right here
   272  // Bug is accommodated at generation of assembly language.
   273  (Geq64F x y) -> (SETGEF (UCOMISD x y))
   274  (Geq32F x y) -> (SETGEF (UCOMISS x y))
   275  
   276  (Eq64  x y) -> (SETEQ (CMPQ x y))
   277  (Eq32  x y) -> (SETEQ (CMPL x y))
   278  (Eq16  x y) -> (SETEQ (CMPW x y))
   279  (Eq8   x y) -> (SETEQ (CMPB x y))
   280  (EqB   x y) -> (SETEQ (CMPB x y))
   281  (EqPtr x y) && config.PtrSize == 8 -> (SETEQ (CMPQ x y))
   282  (EqPtr x y) && config.PtrSize == 4 -> (SETEQ (CMPL x y))
   283  (Eq64F x y) -> (SETEQF (UCOMISD x y))
   284  (Eq32F x y) -> (SETEQF (UCOMISS x y))
   285  
   286  (Neq64  x y) -> (SETNE (CMPQ x y))
   287  (Neq32  x y) -> (SETNE (CMPL x y))
   288  (Neq16  x y) -> (SETNE (CMPW x y))
   289  (Neq8   x y) -> (SETNE (CMPB x y))
   290  (NeqB   x y) -> (SETNE (CMPB x y))
   291  (NeqPtr x y) && config.PtrSize == 8 -> (SETNE (CMPQ x y))
   292  (NeqPtr x y) && config.PtrSize == 4 -> (SETNE (CMPL x y))
   293  (Neq64F x y) -> (SETNEF (UCOMISD x y))
   294  (Neq32F x y) -> (SETNEF (UCOMISS x y))
   295  
   296  (Int64Hi x) -> (SHRQconst [32] x) // needed for amd64p32
   297  
   298  // Lowering loads
   299  (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t) && config.PtrSize == 8) -> (MOVQload ptr mem)
   300  (Load <t> ptr mem) && (is32BitInt(t) || isPtr(t) && config.PtrSize == 4) -> (MOVLload ptr mem)
   301  (Load <t> ptr mem) && is16BitInt(t) -> (MOVWload ptr mem)
   302  (Load <t> ptr mem) && (t.IsBoolean() || is8BitInt(t)) -> (MOVBload ptr mem)
   303  (Load <t> ptr mem) && is32BitFloat(t) -> (MOVSSload ptr mem)
   304  (Load <t> ptr mem) && is64BitFloat(t) -> (MOVSDload ptr mem)
   305  
   306  // Lowering stores
   307  // These more-specific FP versions of Store pattern should come first.
   308  (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 && is64BitFloat(val.Type) -> (MOVSDstore ptr val mem)
   309  (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && is32BitFloat(val.Type) -> (MOVSSstore ptr val mem)
   310  
   311  (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 -> (MOVQstore ptr val mem)
   312  (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 -> (MOVLstore ptr val mem)
   313  (Store {t} ptr val mem) && t.(*types.Type).Size() == 2 -> (MOVWstore ptr val mem)
   314  (Store {t} ptr val mem) && t.(*types.Type).Size() == 1 -> (MOVBstore ptr val mem)
   315  
   316  // Lowering moves
   317  (Move [0] _ _ mem) -> mem
   318  (Move [1] dst src mem) -> (MOVBstore dst (MOVBload src mem) mem)
   319  (Move [2] dst src mem) -> (MOVWstore dst (MOVWload src mem) mem)
   320  (Move [4] dst src mem) -> (MOVLstore dst (MOVLload src mem) mem)
   321  (Move [8] dst src mem) -> (MOVQstore dst (MOVQload src mem) mem)
   322  (Move [16] dst src mem) -> (MOVOstore dst (MOVOload src mem) mem)
   323  (Move [3] dst src mem) ->
   324  	(MOVBstore [2] dst (MOVBload [2] src mem)
   325  		(MOVWstore dst (MOVWload src mem) mem))
   326  (Move [5] dst src mem) ->
   327  	(MOVBstore [4] dst (MOVBload [4] src mem)
   328  		(MOVLstore dst (MOVLload src mem) mem))
   329  (Move [6] dst src mem) ->
   330  	(MOVWstore [4] dst (MOVWload [4] src mem)
   331  		(MOVLstore dst (MOVLload src mem) mem))
   332  (Move [7] dst src mem) ->
   333  	(MOVLstore [3] dst (MOVLload [3] src mem)
   334  		(MOVLstore dst (MOVLload src mem) mem))
   335  (Move [s] dst src mem) && s > 8 && s < 16 ->
   336  	(MOVQstore [s-8] dst (MOVQload [s-8] src mem)
   337  		(MOVQstore dst (MOVQload src mem) mem))
   338  
   339  // Adjust moves to be a multiple of 16 bytes.
   340  (Move [s] dst src mem)
   341  	&& s > 16 && s%16 != 0 && s%16 <= 8 ->
   342  	(Move [s-s%16]
   343  		(OffPtr <dst.Type> dst [s%16])
   344  		(OffPtr <src.Type> src [s%16])
   345  		(MOVQstore dst (MOVQload src mem) mem))
   346  (Move [s] dst src mem)
   347  	&& s > 16 && s%16 != 0 && s%16 > 8 ->
   348  	(Move [s-s%16]
   349  		(OffPtr <dst.Type> dst [s%16])
   350  		(OffPtr <src.Type> src [s%16])
   351  		(MOVOstore dst (MOVOload src mem) mem))
   352  
   353  // Medium copying uses a duff device.
   354  (Move [s] dst src mem)
   355  	&& s >= 32 && s <= 16*64 && s%16 == 0
   356  	&& !config.noDuffDevice ->
   357  	(DUFFCOPY [14*(64-s/16)] dst src mem)
   358  // 14 and 64 are magic constants.  14 is the number of bytes to encode:
   359  //	MOVUPS	(SI), X0
   360  //	ADDQ	$16, SI
   361  //	MOVUPS	X0, (DI)
   362  //	ADDQ	$16, DI
   363  // and 64 is the number of such blocks. See src/runtime/duff_amd64.s:duffcopy.
   364  
   365  // Large copying uses REP MOVSQ.
   366  (Move [s] dst src mem) && (s > 16*64 || config.noDuffDevice) && s%8 == 0 ->
   367  	(REPMOVSQ dst src (MOVQconst [s/8]) mem)
   368  
   369  // Lowering Zero instructions
   370  (Zero [0] _ mem) -> mem
   371  (Zero [1] destptr mem) -> (MOVBstoreconst [0] destptr mem)
   372  (Zero [2] destptr mem) -> (MOVWstoreconst [0] destptr mem)
   373  (Zero [4] destptr mem) -> (MOVLstoreconst [0] destptr mem)
   374  (Zero [8] destptr mem) -> (MOVQstoreconst [0] destptr mem)
   375  
   376  (Zero [3] destptr mem) ->
   377  	(MOVBstoreconst [makeValAndOff(0,2)] destptr
   378  		(MOVWstoreconst [0] destptr mem))
   379  (Zero [5] destptr mem) ->
   380  	(MOVBstoreconst [makeValAndOff(0,4)] destptr
   381  		(MOVLstoreconst [0] destptr mem))
   382  (Zero [6] destptr mem) ->
   383  	(MOVWstoreconst [makeValAndOff(0,4)] destptr
   384  		(MOVLstoreconst [0] destptr mem))
   385  (Zero [7] destptr mem) ->
   386  	(MOVLstoreconst [makeValAndOff(0,3)] destptr
   387  		(MOVLstoreconst [0] destptr mem))
   388  
   389  (Zero [s] destptr mem) && s > 8 && s < 16 ->
   390  	(MOVQstoreconst [makeValAndOff(0,s-8)] destptr
   391  		(MOVQstoreconst [0] destptr mem))
   392  
   393  // Adjust zeros to be a multiple of 16 bytes.
   394  (Zero [s] destptr mem) && s%16 != 0 && s > 16 && s%16 > 8 ->
   395  	(Zero [s-s%16] (OffPtr <destptr.Type> destptr [s%16])
   396  		(MOVOstore destptr (MOVOconst [0]) mem))
   397  
   398  (Zero [s] destptr mem) && s%16 != 0 && s > 16 && s%16 <= 8 ->
   399  	(Zero [s-s%16] (OffPtr <destptr.Type> destptr [s%16])
   400  		(MOVQstoreconst [0] destptr mem))
   401  
   402  (Zero [16] destptr mem) ->
   403  	(MOVOstore destptr (MOVOconst [0]) mem)
   404  (Zero [32] destptr mem) ->
   405  	(MOVOstore (OffPtr <destptr.Type> destptr [16]) (MOVOconst [0])
   406  		(MOVOstore destptr (MOVOconst [0]) mem))
   407  (Zero [48] destptr mem) ->
   408  	(MOVOstore (OffPtr <destptr.Type> destptr [32]) (MOVOconst [0])
   409  		(MOVOstore (OffPtr <destptr.Type> destptr [16]) (MOVOconst [0])
   410  			(MOVOstore destptr (MOVOconst [0]) mem)))
   411  (Zero [64] destptr mem) ->
   412  	(MOVOstore (OffPtr <destptr.Type> destptr [48]) (MOVOconst [0])
   413  		(MOVOstore (OffPtr <destptr.Type> destptr [32]) (MOVOconst [0])
   414  			(MOVOstore (OffPtr <destptr.Type> destptr [16]) (MOVOconst [0])
   415  				(MOVOstore destptr (MOVOconst [0]) mem))))
   416  
   417  // Medium zeroing uses a duff device.
   418  (Zero [s] destptr mem)
   419  	&& s > 64 && s <= 1024 && s%16 == 0 && !config.noDuffDevice ->
   420  	(DUFFZERO [s] destptr (MOVOconst [0]) mem)
   421  
   422  // Large zeroing uses REP STOSQ.
   423  (Zero [s] destptr mem)
   424  	&& (s > 1024 || (config.noDuffDevice && s > 64))
   425  	&& s%8 == 0 ->
   426  	(REPSTOSQ destptr (MOVQconst [s/8]) (MOVQconst [0]) mem)
   427  
   428  // Lowering constants
   429  (Const8   [val]) -> (MOVLconst [val])
   430  (Const16  [val]) -> (MOVLconst [val])
   431  (Const32  [val]) -> (MOVLconst [val])
   432  (Const64  [val]) -> (MOVQconst [val])
   433  (Const32F [val]) -> (MOVSSconst [val])
   434  (Const64F [val]) -> (MOVSDconst [val])
   435  (ConstNil) && config.PtrSize == 8 -> (MOVQconst [0])
   436  (ConstNil) && config.PtrSize == 4 -> (MOVLconst [0])
   437  (ConstBool [b]) -> (MOVLconst [b])
   438  
   439  // Lowering calls
   440  (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem)
   441  (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem)
   442  (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem)
   443  
   444  // Miscellaneous
   445  (Convert <t> x mem) && config.PtrSize == 8 -> (MOVQconvert <t> x mem)
   446  (Convert <t> x mem) && config.PtrSize == 4 -> (MOVLconvert <t> x mem)
   447  (IsNonNil p) && config.PtrSize == 8 -> (SETNE (TESTQ p p))
   448  (IsNonNil p) && config.PtrSize == 4 -> (SETNE (TESTL p p))
   449  (IsInBounds idx len) && config.PtrSize == 8 -> (SETB (CMPQ idx len))
   450  (IsInBounds idx len) && config.PtrSize == 4 -> (SETB (CMPL idx len))
   451  (IsSliceInBounds idx len) && config.PtrSize == 8 -> (SETBE (CMPQ idx len))
   452  (IsSliceInBounds idx len) && config.PtrSize == 4 -> (SETBE (CMPL idx len))
   453  (NilCheck ptr mem) -> (LoweredNilCheck ptr mem)
   454  (GetG mem) -> (LoweredGetG mem)
   455  (GetClosurePtr) -> (LoweredGetClosurePtr)
   456  (Addr {sym} base) && config.PtrSize == 8 -> (LEAQ {sym} base)
   457  (Addr {sym} base) && config.PtrSize == 4 -> (LEAL {sym} base)
   458  
   459  // block rewrites
   460  (If (SETL  cmp) yes no) -> (LT  cmp yes no)
   461  (If (SETLE cmp) yes no) -> (LE  cmp yes no)
   462  (If (SETG  cmp) yes no) -> (GT  cmp yes no)
   463  (If (SETGE cmp) yes no) -> (GE  cmp yes no)
   464  (If (SETEQ cmp) yes no) -> (EQ  cmp yes no)
   465  (If (SETNE cmp) yes no) -> (NE  cmp yes no)
   466  (If (SETB  cmp) yes no) -> (ULT cmp yes no)
   467  (If (SETBE cmp) yes no) -> (ULE cmp yes no)
   468  (If (SETA  cmp) yes no) -> (UGT cmp yes no)
   469  (If (SETAE cmp) yes no) -> (UGE cmp yes no)
   470  
   471  // Special case for floating point - LF/LEF not generated
   472  (If (SETGF  cmp) yes no) -> (UGT  cmp yes no)
   473  (If (SETGEF cmp) yes no) -> (UGE  cmp yes no)
   474  (If (SETEQF cmp) yes no) -> (EQF  cmp yes no)
   475  (If (SETNEF cmp) yes no) -> (NEF  cmp yes no)
   476  
   477  (If cond yes no) -> (NE (TESTB cond cond) yes no)
   478  
   479  // Atomic loads.  Other than preserving their ordering with respect to other loads, nothing special here.
   480  (AtomicLoad32 ptr mem) -> (MOVLatomicload ptr mem)
   481  (AtomicLoad64 ptr mem) -> (MOVQatomicload ptr mem)
   482  (AtomicLoadPtr ptr mem) && config.PtrSize == 8 -> (MOVQatomicload ptr mem)
   483  (AtomicLoadPtr ptr mem) && config.PtrSize == 4 -> (MOVLatomicload ptr mem)
   484  
   485  // Atomic stores.  We use XCHG to prevent the hardware reordering a subsequent load.
   486  // TODO: most runtime uses of atomic stores don't need that property.  Use normal stores for those?
   487  (AtomicStore32 ptr val mem) -> (Select1 (XCHGL <types.NewTuple(typ.UInt32,types.TypeMem)> val ptr mem))
   488  (AtomicStore64 ptr val mem) -> (Select1 (XCHGQ <types.NewTuple(typ.UInt64,types.TypeMem)> val ptr mem))
   489  (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 8 -> (Select1 (XCHGQ <types.NewTuple(typ.BytePtr,types.TypeMem)> val ptr mem))
   490  (AtomicStorePtrNoWB ptr val mem) && config.PtrSize == 4 -> (Select1 (XCHGL <types.NewTuple(typ.BytePtr,types.TypeMem)> val ptr mem))
   491  
   492  // Atomic exchanges.
   493  (AtomicExchange32 ptr val mem) -> (XCHGL val ptr mem)
   494  (AtomicExchange64 ptr val mem) -> (XCHGQ val ptr mem)
   495  
   496  // Atomic adds.
   497  (AtomicAdd32 ptr val mem) -> (AddTupleFirst32 val (XADDLlock val ptr mem))
   498  (AtomicAdd64 ptr val mem) -> (AddTupleFirst64 val (XADDQlock val ptr mem))
   499  (Select0 <t> (AddTupleFirst32 val tuple)) -> (ADDL val (Select0 <t> tuple))
   500  (Select1     (AddTupleFirst32   _ tuple)) -> (Select1 tuple)
   501  (Select0 <t> (AddTupleFirst64 val tuple)) -> (ADDQ val (Select0 <t> tuple))
   502  (Select1     (AddTupleFirst64   _ tuple)) -> (Select1 tuple)
   503  
   504  // Atomic compare and swap.
   505  (AtomicCompareAndSwap32 ptr old new_ mem) -> (CMPXCHGLlock ptr old new_ mem)
   506  (AtomicCompareAndSwap64 ptr old new_ mem) -> (CMPXCHGQlock ptr old new_ mem)
   507  
   508  // Atomic memory updates.
   509  (AtomicAnd8 ptr val mem) -> (ANDBlock ptr val mem)
   510  (AtomicOr8 ptr val mem) -> (ORBlock ptr val mem)
   511  
   512  // ***************************
   513  // Above: lowering rules
   514  // Below: optimizations
   515  // ***************************
   516  // TODO: Should the optimizations be a separate pass?
   517  
   518  // Fold boolean tests into blocks
   519  (NE (TESTB (SETL  cmp) (SETL  cmp)) yes no) -> (LT  cmp yes no)
   520  (NE (TESTB (SETLE cmp) (SETLE cmp)) yes no) -> (LE  cmp yes no)
   521  (NE (TESTB (SETG  cmp) (SETG  cmp)) yes no) -> (GT  cmp yes no)
   522  (NE (TESTB (SETGE cmp) (SETGE cmp)) yes no) -> (GE  cmp yes no)
   523  (NE (TESTB (SETEQ cmp) (SETEQ cmp)) yes no) -> (EQ  cmp yes no)
   524  (NE (TESTB (SETNE cmp) (SETNE cmp)) yes no) -> (NE  cmp yes no)
   525  (NE (TESTB (SETB  cmp) (SETB  cmp)) yes no) -> (ULT cmp yes no)
   526  (NE (TESTB (SETBE cmp) (SETBE cmp)) yes no) -> (ULE cmp yes no)
   527  (NE (TESTB (SETA  cmp) (SETA  cmp)) yes no) -> (UGT cmp yes no)
   528  (NE (TESTB (SETAE cmp) (SETAE cmp)) yes no) -> (UGE cmp yes no)
   529  
   530  // Recognize bit tests: a&(1<<b) != 0 for b suitably bounded
   531  // Note that ULT and SETB check the carry flag; they are identical to CS and SETCS.
   532  // Same, mutatis mutandis, for UGE and SETAE, and CC and SETCC.
   533  (NE (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (ULT (BTL x y))
   534  (EQ (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (UGE (BTL x y))
   535  (NE (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (ULT (BTQ x y))
   536  (EQ (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (UGE (BTQ x y))
   537  (NE (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (ULT (BTLconst [log2(c)] x))
   538  (EQ (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (UGE (BTLconst [log2(c)] x))
   539  (NE (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (ULT (BTQconst [log2(c)] x))
   540  (EQ (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (UGE (BTQconst [log2(c)] x))
   541  (NE (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (ULT (BTQconst [log2(c)] x))
   542  (EQ (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (UGE (BTQconst [log2(c)] x))
   543  (SETNE (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (SETB  (BTL x y))
   544  (SETEQ (TESTL (SHLL (MOVLconst [1]) x) y)) && !config.nacl -> (SETAE (BTL x y))
   545  (SETNE (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (SETB  (BTQ x y))
   546  (SETEQ (TESTQ (SHLQ (MOVQconst [1]) x) y)) && !config.nacl -> (SETAE (BTQ x y))
   547  (SETNE (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (SETB  (BTLconst [log2(c)] x))
   548  (SETEQ (TESTLconst [c] x)) && isPowerOfTwo(c) && log2(c) < 32 && !config.nacl -> (SETAE (BTLconst [log2(c)] x))
   549  (SETNE (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETB  (BTQconst [log2(c)] x))
   550  (SETEQ (TESTQconst [c] x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETAE (BTQconst [log2(c)] x))
   551  (SETNE (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETB  (BTQconst [log2(c)] x))
   552  (SETEQ (TESTQ (MOVQconst [c]) x)) && isPowerOfTwo(c) && log2(c) < 64 && !config.nacl -> (SETAE (BTQconst [log2(c)] x))
   553  
   554  // Fold boolean negation into SETcc.
   555  (XORLconst [1] (SETNE x)) -> (SETEQ x)
   556  (XORLconst [1] (SETEQ x)) -> (SETNE x)
   557  (XORLconst [1] (SETL  x)) -> (SETGE x)
   558  (XORLconst [1] (SETGE x)) -> (SETL  x)
   559  (XORLconst [1] (SETLE x)) -> (SETG  x)
   560  (XORLconst [1] (SETG  x)) -> (SETLE x)
   561  (XORLconst [1] (SETB  x)) -> (SETAE x)
   562  (XORLconst [1] (SETAE x)) -> (SETB  x)
   563  (XORLconst [1] (SETBE x)) -> (SETA  x)
   564  (XORLconst [1] (SETA  x)) -> (SETBE x)
   565  
   566  // Convert BTQconst to BTLconst if possible. It has a shorter encoding.
   567  (BTQconst [c] x) && c < 32 -> (BTLconst [c] x)
   568  
   569  // Special case for floating point - LF/LEF not generated
   570  (NE (TESTB (SETGF  cmp) (SETGF  cmp)) yes no) -> (UGT  cmp yes no)
   571  (NE (TESTB (SETGEF cmp) (SETGEF cmp)) yes no) -> (UGE  cmp yes no)
   572  (NE (TESTB (SETEQF cmp) (SETEQF cmp)) yes no) -> (EQF  cmp yes no)
   573  (NE (TESTB (SETNEF cmp) (SETNEF cmp)) yes no) -> (NEF  cmp yes no)
   574  
   575  // Disabled because it interferes with the pattern match above and makes worse code.
   576  // (SETNEF x) -> (ORQ (SETNE <typ.Int8> x) (SETNAN <typ.Int8> x))
   577  // (SETEQF x) -> (ANDQ (SETEQ <typ.Int8> x) (SETORD <typ.Int8> x))
   578  
   579  // fold constants into instructions
   580  (ADDQ x (MOVQconst [c])) && is32Bit(c) -> (ADDQconst [c] x)
   581  (ADDL x (MOVLconst [c])) -> (ADDLconst [c] x)
   582  
   583  (SUBQ x (MOVQconst [c])) && is32Bit(c) -> (SUBQconst x [c])
   584  (SUBQ (MOVQconst [c]) x) && is32Bit(c) -> (NEGQ (SUBQconst <v.Type> x [c]))
   585  (SUBL x (MOVLconst [c])) -> (SUBLconst x [c])
   586  (SUBL (MOVLconst [c]) x) -> (NEGL (SUBLconst <v.Type> x [c]))
   587  
   588  (MULQ x (MOVQconst [c])) && is32Bit(c) -> (MULQconst [c] x)
   589  (MULL x (MOVLconst [c])) -> (MULLconst [c] x)
   590  
   591  (ANDQ x (MOVQconst [c])) && is32Bit(c) -> (ANDQconst [c] x)
   592  (ANDL x (MOVLconst [c])) -> (ANDLconst [c] x)
   593  
   594  (ANDLconst [c] (ANDLconst [d] x)) -> (ANDLconst [c & d] x)
   595  (ANDQconst [c] (ANDQconst [d] x)) -> (ANDQconst [c & d] x)
   596  
   597  (XORLconst [c] (XORLconst [d] x)) -> (XORLconst [c ^ d] x)
   598  (XORQconst [c] (XORQconst [d] x)) -> (XORQconst [c ^ d] x)
   599  
   600  (MULLconst [c] (MULLconst [d] x)) -> (MULLconst [int64(int32(c * d))] x)
   601  (MULQconst [c] (MULQconst [d] x)) && is32Bit(c*d) -> (MULQconst [c * d] x)
   602  
   603  (ORQ x (MOVQconst [c])) && is32Bit(c) -> (ORQconst [c] x)
   604  (ORL x (MOVLconst [c])) -> (ORLconst [c] x)
   605  
   606  (XORQ x (MOVQconst [c])) && is32Bit(c) -> (XORQconst [c] x)
   607  (XORL x (MOVLconst [c])) -> (XORLconst [c] x)
   608  
   609  (SHLQ x (MOVQconst [c])) -> (SHLQconst [c&63] x)
   610  (SHLQ x (MOVLconst [c])) -> (SHLQconst [c&63] x)
   611  
   612  (SHLL x (MOVQconst [c])) -> (SHLLconst [c&31] x)
   613  (SHLL x (MOVLconst [c])) -> (SHLLconst [c&31] x)
   614  
   615  (SHRQ x (MOVQconst [c])) -> (SHRQconst [c&63] x)
   616  (SHRQ x (MOVLconst [c])) -> (SHRQconst [c&63] x)
   617  
   618  (SHRL x (MOVQconst [c])) -> (SHRLconst [c&31] x)
   619  (SHRL x (MOVLconst [c])) -> (SHRLconst [c&31] x)
   620  
   621  (SHRW x (MOVQconst [c])) && c&31 < 16 -> (SHRWconst [c&31] x)
   622  (SHRW x (MOVLconst [c])) && c&31 < 16 -> (SHRWconst [c&31] x)
   623  (SHRW _ (MOVQconst [c])) && c&31 >= 16 -> (MOVLconst [0])
   624  (SHRW _ (MOVLconst [c])) && c&31 >= 16 -> (MOVLconst [0])
   625  
   626  (SHRB x (MOVQconst [c])) && c&31 < 8 -> (SHRBconst [c&31] x)
   627  (SHRB x (MOVLconst [c])) && c&31 < 8 -> (SHRBconst [c&31] x)
   628  (SHRB _ (MOVQconst [c])) && c&31 >= 8 -> (MOVLconst [0])
   629  (SHRB _ (MOVLconst [c])) && c&31 >= 8 -> (MOVLconst [0])
   630  
   631  (SARQ x (MOVQconst [c])) -> (SARQconst [c&63] x)
   632  (SARQ x (MOVLconst [c])) -> (SARQconst [c&63] x)
   633  
   634  (SARL x (MOVQconst [c])) -> (SARLconst [c&31] x)
   635  (SARL x (MOVLconst [c])) -> (SARLconst [c&31] x)
   636  
   637  (SARW x (MOVQconst [c])) -> (SARWconst [min(c&31,15)] x)
   638  (SARW x (MOVLconst [c])) -> (SARWconst [min(c&31,15)] x)
   639  
   640  (SARB x (MOVQconst [c])) -> (SARBconst [min(c&31,7)] x)
   641  (SARB x (MOVLconst [c])) -> (SARBconst [min(c&31,7)] x)
   642  
   643  // Operations which don't affect the low 6/5 bits of the shift amount are NOPs.
   644  (SHLQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SHLQ x y)
   645  (SHRQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SHRQ x y)
   646  (SARQ x (ADDQconst [c] y)) && c & 63 == 0 -> (SARQ x y)
   647  (SHLQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SHLQ x (NEGQ <t> y))
   648  (SHRQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SHRQ x (NEGQ <t> y))
   649  (SARQ x (NEGQ <t> (ADDQconst [c] y))) && c & 63 == 0 -> (SARQ x (NEGQ <t> y))
   650  (SHLQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SHLQ x y)
   651  (SHRQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SHRQ x y)
   652  (SARQ x (ANDQconst [c] y)) && c & 63 == 63 -> (SARQ x y)
   653  (SHLQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SHLQ x (NEGQ <t> y))
   654  (SHRQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SHRQ x (NEGQ <t> y))
   655  (SARQ x (NEGQ <t> (ANDQconst [c] y))) && c & 63 == 63 -> (SARQ x (NEGQ <t> y))
   656  
   657  (SHLL x (ADDQconst [c] y)) && c & 31 == 0 -> (SHLL x y)
   658  (SHRL x (ADDQconst [c] y)) && c & 31 == 0 -> (SHRL x y)
   659  (SARL x (ADDQconst [c] y)) && c & 31 == 0 -> (SARL x y)
   660  (SHLL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SHLL x (NEGQ <t> y))
   661  (SHRL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SHRL x (NEGQ <t> y))
   662  (SARL x (NEGQ <t> (ADDQconst [c] y))) && c & 31 == 0 -> (SARL x (NEGQ <t> y))
   663  (SHLL x (ANDQconst [c] y)) && c & 31 == 31 -> (SHLL x y)
   664  (SHRL x (ANDQconst [c] y)) && c & 31 == 31 -> (SHRL x y)
   665  (SARL x (ANDQconst [c] y)) && c & 31 == 31 -> (SARL x y)
   666  (SHLL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SHLL x (NEGQ <t> y))
   667  (SHRL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SHRL x (NEGQ <t> y))
   668  (SARL x (NEGQ <t> (ANDQconst [c] y))) && c & 31 == 31 -> (SARL x (NEGQ <t> y))
   669  
   670  (SHLQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SHLQ x y)
   671  (SHRQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SHRQ x y)
   672  (SARQ x (ADDLconst [c] y)) && c & 63 == 0 -> (SARQ x y)
   673  (SHLQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SHLQ x (NEGL <t> y))
   674  (SHRQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SHRQ x (NEGL <t> y))
   675  (SARQ x (NEGL <t> (ADDLconst [c] y))) && c & 63 == 0 -> (SARQ x (NEGL <t> y))
   676  (SHLQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SHLQ x y)
   677  (SHRQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SHRQ x y)
   678  (SARQ x (ANDLconst [c] y)) && c & 63 == 63 -> (SARQ x y)
   679  (SHLQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SHLQ x (NEGL <t> y))
   680  (SHRQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SHRQ x (NEGL <t> y))
   681  (SARQ x (NEGL <t> (ANDLconst [c] y))) && c & 63 == 63 -> (SARQ x (NEGL <t> y))
   682  
   683  (SHLL x (ADDLconst [c] y)) && c & 31 == 0 -> (SHLL x y)
   684  (SHRL x (ADDLconst [c] y)) && c & 31 == 0 -> (SHRL x y)
   685  (SARL x (ADDLconst [c] y)) && c & 31 == 0 -> (SARL x y)
   686  (SHLL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SHLL x (NEGL <t> y))
   687  (SHRL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SHRL x (NEGL <t> y))
   688  (SARL x (NEGL <t> (ADDLconst [c] y))) && c & 31 == 0 -> (SARL x (NEGL <t> y))
   689  (SHLL x (ANDLconst [c] y)) && c & 31 == 31 -> (SHLL x y)
   690  (SHRL x (ANDLconst [c] y)) && c & 31 == 31 -> (SHRL x y)
   691  (SARL x (ANDLconst [c] y)) && c & 31 == 31 -> (SARL x y)
   692  (SHLL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SHLL x (NEGL <t> y))
   693  (SHRL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SHRL x (NEGL <t> y))
   694  (SARL x (NEGL <t> (ANDLconst [c] y))) && c & 31 == 31 -> (SARL x (NEGL <t> y))
   695  
   696  // Constant rotate instructions
   697  (ADDQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c])
   698  ( ORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c])
   699  (XORQ (SHLQconst x [c]) (SHRQconst x [d])) && d==64-c -> (ROLQconst x [c])
   700  
   701  (ADDL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c])
   702  ( ORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c])
   703  (XORL (SHLLconst x [c]) (SHRLconst x [d])) && d==32-c -> (ROLLconst x [c])
   704  
   705  (ADDL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c])
   706  ( ORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c])
   707  (XORL <t> (SHLLconst x [c]) (SHRWconst x [d])) && d==16-c && c < 16 && t.Size() == 2 -> (ROLWconst x [c])
   708  
   709  (ADDL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c  && c < 8 && t.Size() == 1 -> (ROLBconst x [c])
   710  ( ORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c  && c < 8 && t.Size() == 1 -> (ROLBconst x [c])
   711  (XORL <t> (SHLLconst x [c]) (SHRBconst x [d])) && d==8-c  && c < 8 && t.Size() == 1 -> (ROLBconst x [c])
   712  
   713  (ROLQconst [c] (ROLQconst [d] x)) -> (ROLQconst [(c+d)&63] x)
   714  (ROLLconst [c] (ROLLconst [d] x)) -> (ROLLconst [(c+d)&31] x)
   715  (ROLWconst [c] (ROLWconst [d] x)) -> (ROLWconst [(c+d)&15] x)
   716  (ROLBconst [c] (ROLBconst [d] x)) -> (ROLBconst [(c+d)& 7] x)
   717  
   718  // Non-constant rotates.
   719  // We want to issue a rotate when the Go source contains code like
   720  //     y &= 63
   721  //     x << y | x >> (64-y)
   722  // The shift rules above convert << to SHLx and >> to SHRx.
   723  // SHRx converts its shift argument from 64-y to -y.
   724  // A tricky situation occurs when y==0. Then the original code would be:
   725  //     x << 0 | x >> 64
   726  // But x >> 64 is 0, not x. So there's an additional mask that is ANDed in
   727  // to force the second term to 0. We don't need that mask, but we must match
   728  // it in order to strip it out.
   729  (ORQ (SHLQ x y) (ANDQ (SHRQ x (NEGQ y)) (SBBQcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [63]) [-64])) [64])))) -> (ROLQ x y)
   730  (ORQ (SHLQ x y) (ANDQ (SHRQ x (NEGL y)) (SBBQcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [63]) [-64])) [64])))) -> (ROLQ x y)
   731  (ORQ (SHRQ x y) (ANDQ (SHLQ x (NEGQ y)) (SBBQcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [63]) [-64])) [64])))) -> (RORQ x y)
   732  (ORQ (SHRQ x y) (ANDQ (SHLQ x (NEGL y)) (SBBQcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [63]) [-64])) [64])))) -> (RORQ x y)
   733  
   734  (ORL (SHLL x y) (ANDL (SHRL x (NEGQ y)) (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [31]) [-32])) [32])))) -> (ROLL x y)
   735  (ORL (SHLL x y) (ANDL (SHRL x (NEGL y)) (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [31]) [-32])) [32])))) -> (ROLL x y)
   736  (ORL (SHRL x y) (ANDL (SHLL x (NEGQ y)) (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [31]) [-32])) [32])))) -> (RORL x y)
   737  (ORL (SHRL x y) (ANDL (SHLL x (NEGL y)) (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [31]) [-32])) [32])))) -> (RORL x y)
   738  
   739  // Help with rotate detection
   740  (CMPQconst (NEGQ (ADDQconst [-16] (ANDQconst [15] _))) [32]) -> (FlagLT_ULT)
   741  (CMPQconst (NEGQ (ADDQconst [ -8] (ANDQconst  [7] _))) [32]) -> (FlagLT_ULT)
   742  
   743  (ORL (SHLL x (ANDQconst y [15]))
   744       (ANDL (SHRW x (NEGQ (ADDQconst (ANDQconst y [15]) [-16])))
   745             (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [15]) [-16])) [16]))))
   746    && v.Type.Size() == 2
   747    -> (ROLW x y)
   748  (ORL (SHLL x (ANDLconst y [15]))
   749       (ANDL (SHRW x (NEGL (ADDLconst (ANDLconst y [15]) [-16])))
   750             (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [15]) [-16])) [16]))))
   751    && v.Type.Size() == 2
   752    -> (ROLW x y)
   753  (ORL (SHRW x (ANDQconst y [15]))
   754       (SHLL x (NEGQ (ADDQconst (ANDQconst y [15]) [-16]))))
   755    && v.Type.Size() == 2
   756    -> (RORW x y)
   757  (ORL (SHRW x (ANDLconst y [15]))
   758       (SHLL x (NEGL (ADDLconst (ANDLconst y [15]) [-16]))))
   759    && v.Type.Size() == 2
   760    -> (RORW x y)
   761  
   762  (ORL (SHLL x (ANDQconst y [ 7]))
   763       (ANDL (SHRB x (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8])))
   764             (SBBLcarrymask (CMPQconst (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8])) [ 8]))))
   765    && v.Type.Size() == 1
   766    -> (ROLB x y)
   767  (ORL (SHLL x (ANDLconst y [ 7]))
   768       (ANDL (SHRB x (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8])))
   769             (SBBLcarrymask (CMPLconst (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8])) [ 8]))))
   770    && v.Type.Size() == 1
   771    -> (ROLB x y)
   772  (ORL (SHRB x (ANDQconst y [ 7]))
   773       (SHLL x (NEGQ (ADDQconst (ANDQconst y [ 7]) [ -8]))))
   774    && v.Type.Size() == 1
   775    -> (RORB x y)
   776  (ORL (SHRB x (ANDLconst y [ 7]))
   777       (SHLL x (NEGL (ADDLconst (ANDLconst y [ 7]) [ -8]))))
   778    && v.Type.Size() == 1
   779    -> (RORB x y)
   780  
   781  // rotate left negative = rotate right
   782  (ROLQ x (NEGQ y)) -> (RORQ x y)
   783  (ROLQ x (NEGL y)) -> (RORQ x y)
   784  (ROLL x (NEGQ y)) -> (RORL x y)
   785  (ROLL x (NEGL y)) -> (RORL x y)
   786  (ROLW x (NEGQ y)) -> (RORW x y)
   787  (ROLW x (NEGL y)) -> (RORW x y)
   788  (ROLB x (NEGQ y)) -> (RORB x y)
   789  (ROLB x (NEGL y)) -> (RORB x y)
   790  
   791  // rotate right negative = rotate left
   792  (RORQ x (NEGQ y)) -> (ROLQ x y)
   793  (RORQ x (NEGL y)) -> (ROLQ x y)
   794  (RORL x (NEGQ y)) -> (ROLL x y)
   795  (RORL x (NEGL y)) -> (ROLL x y)
   796  (RORW x (NEGQ y)) -> (ROLW x y)
   797  (RORW x (NEGL y)) -> (ROLW x y)
   798  (RORB x (NEGQ y)) -> (ROLB x y)
   799  (RORB x (NEGL y)) -> (ROLB x y)
   800  
   801  // rotate by constants
   802  (ROLQ x (MOVQconst [c])) -> (ROLQconst [c&63] x)
   803  (ROLQ x (MOVLconst [c])) -> (ROLQconst [c&63] x)
   804  (ROLL x (MOVQconst [c])) -> (ROLLconst [c&31] x)
   805  (ROLL x (MOVLconst [c])) -> (ROLLconst [c&31] x)
   806  (ROLW x (MOVQconst [c])) -> (ROLWconst [c&15] x)
   807  (ROLW x (MOVLconst [c])) -> (ROLWconst [c&15] x)
   808  (ROLB x (MOVQconst [c])) -> (ROLBconst [c&7 ] x)
   809  (ROLB x (MOVLconst [c])) -> (ROLBconst [c&7 ] x)
   810  
   811  (RORQ x (MOVQconst [c])) -> (ROLQconst [(-c)&63] x)
   812  (RORQ x (MOVLconst [c])) -> (ROLQconst [(-c)&63] x)
   813  (RORL x (MOVQconst [c])) -> (ROLLconst [(-c)&31] x)
   814  (RORL x (MOVLconst [c])) -> (ROLLconst [(-c)&31] x)
   815  (RORW x (MOVQconst [c])) -> (ROLWconst [(-c)&15] x)
   816  (RORW x (MOVLconst [c])) -> (ROLWconst [(-c)&15] x)
   817  (RORB x (MOVQconst [c])) -> (ROLBconst [(-c)&7 ] x)
   818  (RORB x (MOVLconst [c])) -> (ROLBconst [(-c)&7 ] x)
   819  
   820  // Constant shift simplifications
   821  (SHLQconst x [0]) -> x
   822  (SHRQconst x [0]) -> x
   823  (SARQconst x [0]) -> x
   824  
   825  (SHLLconst x [0]) -> x
   826  (SHRLconst x [0]) -> x
   827  (SARLconst x [0]) -> x
   828  
   829  (SHRWconst x [0]) -> x
   830  (SARWconst x [0]) -> x
   831  
   832  (SHRBconst x [0]) -> x
   833  (SARBconst x [0]) -> x
   834  
   835  (ROLQconst x [0]) -> x
   836  (ROLLconst x [0]) -> x
   837  (ROLWconst x [0]) -> x
   838  (ROLBconst x [0]) -> x
   839  
   840  // Note: the word and byte shifts keep the low 5 bits (not the low 4 or 3 bits)
   841  // because the x86 instructions are defined to use all 5 bits of the shift even
   842  // for the small shifts. I don't think we'll ever generate a weird shift (e.g.
   843  // (SHRW x (MOVLconst [24])), but just in case.
   844  
   845  (CMPQ x (MOVQconst [c])) && is32Bit(c) -> (CMPQconst x [c])
   846  (CMPQ (MOVQconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPQconst x [c]))
   847  (CMPL x (MOVLconst [c])) -> (CMPLconst x [c])
   848  (CMPL (MOVLconst [c]) x) -> (InvertFlags (CMPLconst x [c]))
   849  (CMPW x (MOVLconst [c])) -> (CMPWconst x [int64(int16(c))])
   850  (CMPW (MOVLconst [c]) x) -> (InvertFlags (CMPWconst x [int64(int16(c))]))
   851  (CMPB x (MOVLconst [c])) -> (CMPBconst x [int64(int8(c))])
   852  (CMPB (MOVLconst [c]) x) -> (InvertFlags (CMPBconst x [int64(int8(c))]))
   853  
   854  // Using MOVZX instead of AND is cheaper.
   855  (ANDLconst [0xFF] x) -> (MOVBQZX x)
   856  (ANDLconst [0xFFFF] x) -> (MOVWQZX x)
   857  (ANDQconst [0xFF] x) -> (MOVBQZX x)
   858  (ANDQconst [0xFFFF] x) -> (MOVWQZX x)
   859  (ANDQconst [0xFFFFFFFF] x) -> (MOVLQZX x)
   860  
   861  // strength reduction
   862  // Assumes that the following costs from https://gmplib.org/~tege/x86-timing.pdf:
   863  //    1 - addq, shlq, leaq, negq
   864  //    3 - imulq
   865  // This limits the rewrites to two instructions.
   866  // TODO: 27, 81
   867  (MULQconst [-1] x) -> (NEGQ x)
   868  (MULQconst [0] _) -> (MOVQconst [0])
   869  (MULQconst [1] x) -> x
   870  (MULQconst [3] x) -> (LEAQ2 x x)
   871  (MULQconst [5] x) -> (LEAQ4 x x)
   872  (MULQconst [7] x) -> (LEAQ8 (NEGQ <v.Type> x) x)
   873  (MULQconst [9] x) -> (LEAQ8 x x)
   874  (MULQconst [11] x) -> (LEAQ2 x (LEAQ4 <v.Type> x x))
   875  (MULQconst [13] x) -> (LEAQ4 x (LEAQ2 <v.Type> x x))
   876  (MULQconst [21] x) -> (LEAQ4 x (LEAQ4 <v.Type> x x))
   877  (MULQconst [25] x) -> (LEAQ8 x (LEAQ2 <v.Type> x x))
   878  (MULQconst [37] x) -> (LEAQ4 x (LEAQ8 <v.Type> x x))
   879  (MULQconst [41] x) -> (LEAQ8 x (LEAQ4 <v.Type> x x))
   880  (MULQconst [73] x) -> (LEAQ8 x (LEAQ8 <v.Type> x x))
   881  
   882  (MULQconst [c] x) && isPowerOfTwo(c) -> (SHLQconst [log2(c)] x)
   883  (MULQconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUBQ (SHLQconst <v.Type> [log2(c+1)] x) x)
   884  (MULQconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (LEAQ1 (SHLQconst <v.Type> [log2(c-1)] x) x)
   885  (MULQconst [c] x) && isPowerOfTwo(c-2) && c >= 34 -> (LEAQ2 (SHLQconst <v.Type> [log2(c-2)] x) x)
   886  (MULQconst [c] x) && isPowerOfTwo(c-4) && c >= 68 -> (LEAQ4 (SHLQconst <v.Type> [log2(c-4)] x) x)
   887  (MULQconst [c] x) && isPowerOfTwo(c-8) && c >= 136 -> (LEAQ8 (SHLQconst <v.Type> [log2(c-8)] x) x)
   888  (MULQconst [c] x) && c%3 == 0 && isPowerOfTwo(c/3) -> (SHLQconst [log2(c/3)] (LEAQ2 <v.Type> x x))
   889  (MULQconst [c] x) && c%5 == 0 && isPowerOfTwo(c/5) -> (SHLQconst [log2(c/5)] (LEAQ4 <v.Type> x x))
   890  (MULQconst [c] x) && c%9 == 0 && isPowerOfTwo(c/9) -> (SHLQconst [log2(c/9)] (LEAQ8 <v.Type> x x))
   891  
   892  // combine add/shift into LEAQ
   893  (ADDQ x (SHLQconst [3] y)) -> (LEAQ8 x y)
   894  (ADDQ x (SHLQconst [2] y)) -> (LEAQ4 x y)
   895  (ADDQ x (SHLQconst [1] y)) -> (LEAQ2 x y)
   896  (ADDQ x (ADDQ y y)) -> (LEAQ2 x y)
   897  (ADDQ x (ADDQ x y)) -> (LEAQ2 y x)
   898  
   899  // combine ADDQ/ADDQconst into LEAQ1
   900  (ADDQconst [c] (ADDQ x y)) -> (LEAQ1 [c] x y)
   901  (ADDQ (ADDQconst [c] x) y) -> (LEAQ1 [c] x y)
   902  
   903  // fold ADDQ into LEAQ
   904  (ADDQconst [c] (LEAQ [d] {s} x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x)
   905  (LEAQ [c] {s} (ADDQconst [d] x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x)
   906  (LEAQ [c] {s} (ADDQ x y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y)
   907  (ADDQ x (LEAQ [c] {s} y)) && x.Op != OpSB && y.Op != OpSB -> (LEAQ1 [c] {s} x y)
   908  
   909  // fold ADDQconst into LEAQx
   910  (ADDQconst [c] (LEAQ1 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ1 [c+d] {s} x y)
   911  (ADDQconst [c] (LEAQ2 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ2 [c+d] {s} x y)
   912  (ADDQconst [c] (LEAQ4 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ4 [c+d] {s} x y)
   913  (ADDQconst [c] (LEAQ8 [d] {s} x y)) && is32Bit(c+d) -> (LEAQ8 [c+d] {s} x y)
   914  (LEAQ1 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d)   && x.Op != OpSB -> (LEAQ1 [c+d] {s} x y)
   915  (LEAQ2 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d)   && x.Op != OpSB -> (LEAQ2 [c+d] {s} x y)
   916  (LEAQ2 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+2*d) && y.Op != OpSB -> (LEAQ2 [c+2*d] {s} x y)
   917  (LEAQ4 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d)   && x.Op != OpSB -> (LEAQ4 [c+d] {s} x y)
   918  (LEAQ4 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+4*d) && y.Op != OpSB -> (LEAQ4 [c+4*d] {s} x y)
   919  (LEAQ8 [c] {s} (ADDQconst [d] x) y) && is32Bit(c+d)   && x.Op != OpSB -> (LEAQ8 [c+d] {s} x y)
   920  (LEAQ8 [c] {s} x (ADDQconst [d] y)) && is32Bit(c+8*d) && y.Op != OpSB -> (LEAQ8 [c+8*d] {s} x y)
   921  
   922  // fold shifts into LEAQx
   923  (LEAQ1 [c] {s} x (SHLQconst [1] y)) -> (LEAQ2 [c] {s} x y)
   924  (LEAQ1 [c] {s} x (SHLQconst [2] y)) -> (LEAQ4 [c] {s} x y)
   925  (LEAQ1 [c] {s} x (SHLQconst [3] y)) -> (LEAQ8 [c] {s} x y)
   926  (LEAQ2 [c] {s} x (SHLQconst [1] y)) -> (LEAQ4 [c] {s} x y)
   927  (LEAQ2 [c] {s} x (SHLQconst [2] y)) -> (LEAQ8 [c] {s} x y)
   928  (LEAQ4 [c] {s} x (SHLQconst [1] y)) -> (LEAQ8 [c] {s} x y)
   929  
   930  // reverse ordering of compare instruction
   931  (SETL (InvertFlags x)) -> (SETG x)
   932  (SETG (InvertFlags x)) -> (SETL x)
   933  (SETB (InvertFlags x)) -> (SETA x)
   934  (SETA (InvertFlags x)) -> (SETB x)
   935  (SETLE (InvertFlags x)) -> (SETGE x)
   936  (SETGE (InvertFlags x)) -> (SETLE x)
   937  (SETBE (InvertFlags x)) -> (SETAE x)
   938  (SETAE (InvertFlags x)) -> (SETBE x)
   939  (SETEQ (InvertFlags x)) -> (SETEQ x)
   940  (SETNE (InvertFlags x)) -> (SETNE x)
   941  
   942  // sign extended loads
   943  // Note: The combined instruction must end up in the same block
   944  // as the original load. If not, we end up making a value with
   945  // memory type live in two different blocks, which can lead to
   946  // multiple memory values alive simultaneously.
   947  // Make sure we don't combine these ops if the load has another use.
   948  // This prevents a single load from being split into multiple loads
   949  // which then might return different values.  See test/atomicload.go.
   950  (MOVBQSX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem)
   951  (MOVBQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem)
   952  (MOVBQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem)
   953  (MOVBQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBQSXload <v.Type> [off] {sym} ptr mem)
   954  (MOVBQZX x:(MOVBload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem)
   955  (MOVBQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem)
   956  (MOVBQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem)
   957  (MOVBQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem)
   958  (MOVWQSX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem)
   959  (MOVWQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem)
   960  (MOVWQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWQSXload <v.Type> [off] {sym} ptr mem)
   961  (MOVWQZX x:(MOVWload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem)
   962  (MOVWQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem)
   963  (MOVWQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem)
   964  (MOVLQSX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem)
   965  (MOVLQSX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLQSXload <v.Type> [off] {sym} ptr mem)
   966  (MOVLQZX x:(MOVLload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem)
   967  (MOVLQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload <v.Type> [off] {sym} ptr mem)
   968  
   969  (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBloadidx1 <v.Type> [off] {sym} ptr idx mem)
   970  (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx1 <v.Type> [off] {sym} ptr idx mem)
   971  (MOVWQZX x:(MOVWloadidx2 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx2 <v.Type> [off] {sym} ptr idx mem)
   972  (MOVLQZX x:(MOVLloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx1 <v.Type> [off] {sym} ptr idx mem)
   973  (MOVLQZX x:(MOVLloadidx4 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLloadidx4 <v.Type> [off] {sym} ptr idx mem)
   974  
   975  // replace load from same location as preceding store with zero/sign extension (or copy in case of full width)
   976  (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBQZX x)
   977  (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWQZX x)
   978  (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVLQZX x)
   979  (MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   980  (MOVBQSXload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBQSX x)
   981  (MOVWQSXload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWQSX x)
   982  (MOVLQSXload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVLQSX x)
   983  
   984  // Fold extensions and ANDs together.
   985  (MOVBQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xff] x)
   986  (MOVWQZX (ANDLconst [c] x)) -> (ANDLconst [c & 0xffff] x)
   987  (MOVLQZX (ANDLconst [c] x)) -> (ANDLconst [c] x)
   988  (MOVBQSX (ANDLconst [c] x)) && c & 0x80 == 0 -> (ANDLconst [c & 0x7f] x)
   989  (MOVWQSX (ANDLconst [c] x)) && c & 0x8000 == 0 -> (ANDLconst [c & 0x7fff] x)
   990  (MOVLQSX (ANDLconst [c] x)) && c & 0x80000000 == 0 -> (ANDLconst [c & 0x7fffffff] x)
   991  
   992  // Don't extend before storing
   993  (MOVLstore [off] {sym} ptr (MOVLQSX x) mem) -> (MOVLstore [off] {sym} ptr x mem)
   994  (MOVWstore [off] {sym} ptr (MOVWQSX x) mem) -> (MOVWstore [off] {sym} ptr x mem)
   995  (MOVBstore [off] {sym} ptr (MOVBQSX x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   996  (MOVLstore [off] {sym} ptr (MOVLQZX x) mem) -> (MOVLstore [off] {sym} ptr x mem)
   997  (MOVWstore [off] {sym} ptr (MOVWQZX x) mem) -> (MOVWstore [off] {sym} ptr x mem)
   998  (MOVBstore [off] {sym} ptr (MOVBQZX x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   999  
  1000  // fold constants into memory operations
  1001  // Note that this is not always a good idea because if not all the uses of
  1002  // the ADDQconst get eliminated, we still have to compute the ADDQconst and we now
  1003  // have potentially two live values (ptr and (ADDQconst [off] ptr)) instead of one.
  1004  // Nevertheless, let's do it!
  1005  (MOVQload  [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload  [off1+off2] {sym} ptr mem)
  1006  (MOVLload  [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload  [off1+off2] {sym} ptr mem)
  1007  (MOVWload  [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload  [off1+off2] {sym} ptr mem)
  1008  (MOVBload  [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload  [off1+off2] {sym} ptr mem)
  1009  (MOVSSload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSSload [off1+off2] {sym} ptr mem)
  1010  (MOVSDload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVSDload [off1+off2] {sym} ptr mem)
  1011  (MOVOload  [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVOload  [off1+off2] {sym} ptr mem)
  1012  
  1013  (MOVQstore  [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore  [off1+off2] {sym} ptr val mem)
  1014  (MOVLstore  [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore  [off1+off2] {sym} ptr val mem)
  1015  (MOVWstore  [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore  [off1+off2] {sym} ptr val mem)
  1016  (MOVBstore  [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore  [off1+off2] {sym} ptr val mem)
  1017  (MOVSSstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSSstore [off1+off2] {sym} ptr val mem)
  1018  (MOVSDstore [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSDstore [off1+off2] {sym} ptr val mem)
  1019  (MOVOstore  [off1] {sym} (ADDQconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVOstore  [off1+off2] {sym} ptr val mem)
  1020  
  1021  // Fold constants into stores.
  1022  (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) ->
  1023  	(MOVQstoreconst [makeValAndOff(c,off)] {sym} ptr mem)
  1024  (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) ->
  1025  	(MOVLstoreconst [makeValAndOff(int64(int32(c)),off)] {sym} ptr mem)
  1026  (MOVWstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) ->
  1027  	(MOVWstoreconst [makeValAndOff(int64(int16(c)),off)] {sym} ptr mem)
  1028  (MOVBstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) ->
  1029  	(MOVBstoreconst [makeValAndOff(int64(int8(c)),off)] {sym} ptr mem)
  1030  
  1031  // Fold address offsets into constant stores.
  1032  (MOVQstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  1033  	(MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  1034  (MOVLstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  1035  	(MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  1036  (MOVWstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  1037  	(MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  1038  (MOVBstoreconst [sc] {s} (ADDQconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  1039  	(MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  1040  
  1041  // We need to fold LEAQ into the MOVx ops so that the live variable analysis knows
  1042  // what variables are being read/written by the ops.
  1043  (MOVQload  [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1044  	(MOVQload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1045  (MOVLload  [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1046  	(MOVLload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1047  (MOVWload  [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1048  	(MOVWload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1049  (MOVBload  [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1050  	(MOVBload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1051  (MOVSSload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1052  	(MOVSSload [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1053  (MOVSDload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1054  	(MOVSDload [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1055  (MOVOload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1056  	(MOVOload [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1057  
  1058  (MOVBQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1059  	(MOVBQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1060  (MOVWQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1061  	(MOVWQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1062  (MOVLQSXload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1063  	(MOVLQSXload [off1+off2] {mergeSym(sym1,sym2)} base mem)
  1064  
  1065  (MOVQstore  [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1066  	(MOVQstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1067  (MOVLstore  [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1068  	(MOVLstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1069  (MOVWstore  [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1070  	(MOVWstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1071  (MOVBstore  [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1072  	(MOVBstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1073  (MOVSSstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1074  	(MOVSSstore [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1075  (MOVSDstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1076  	(MOVSDstore [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1077  (MOVOstore [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1078  	(MOVOstore [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  1079  
  1080  (MOVQstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  1081  	(MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  1082  (MOVLstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  1083  	(MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  1084  (MOVWstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  1085  	(MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  1086  (MOVBstoreconst [sc] {sym1} (LEAQ [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  1087  	(MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  1088  
  1089  // generating indexed loads and stores
  1090  (MOVBload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1091  	(MOVBloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1092  (MOVWload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1093  	(MOVWloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1094  (MOVWload [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1095  	(MOVWloadidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1096  (MOVLload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1097  	(MOVLloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1098  (MOVLload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1099  	(MOVLloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1100  (MOVQload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1101  	(MOVQloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1102  (MOVQload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1103  	(MOVQloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1104  (MOVSSload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1105  	(MOVSSloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1106  (MOVSSload [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1107  	(MOVSSloadidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1108  (MOVSDload [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1109  	(MOVSDloadidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1110  (MOVSDload [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1111  	(MOVSDloadidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
  1112  
  1113  (MOVBstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1114  	(MOVBstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1115  (MOVWstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1116  	(MOVWstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1117  (MOVWstore [off1] {sym1} (LEAQ2 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1118  	(MOVWstoreidx2 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1119  (MOVLstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1120  	(MOVLstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1121  (MOVLstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1122  	(MOVLstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1123  (MOVQstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1124  	(MOVQstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1125  (MOVQstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1126  	(MOVQstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1127  (MOVSSstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1128  	(MOVSSstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1129  (MOVSSstore [off1] {sym1} (LEAQ4 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1130  	(MOVSSstoreidx4 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1131  (MOVSDstore [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1132  	(MOVSDstoreidx1 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1133  (MOVSDstore [off1] {sym1} (LEAQ8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1134  	(MOVSDstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
  1135  
  1136  (MOVBload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVBloadidx1 [off] {sym} ptr idx mem)
  1137  (MOVWload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVWloadidx1 [off] {sym} ptr idx mem)
  1138  (MOVLload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVLloadidx1 [off] {sym} ptr idx mem)
  1139  (MOVQload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVQloadidx1 [off] {sym} ptr idx mem)
  1140  (MOVSSload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSSloadidx1 [off] {sym} ptr idx mem)
  1141  (MOVSDload [off] {sym} (ADDQ ptr idx) mem) && ptr.Op != OpSB -> (MOVSDloadidx1 [off] {sym} ptr idx mem)
  1142  (MOVBstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVBstoreidx1 [off] {sym} ptr idx val mem)
  1143  (MOVWstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVWstoreidx1 [off] {sym} ptr idx val mem)
  1144  (MOVLstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVLstoreidx1 [off] {sym} ptr idx val mem)
  1145  (MOVQstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVQstoreidx1 [off] {sym} ptr idx val mem)
  1146  (MOVSSstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSSstoreidx1 [off] {sym} ptr idx val mem)
  1147  (MOVSDstore [off] {sym} (ADDQ ptr idx) val mem) && ptr.Op != OpSB -> (MOVSDstoreidx1 [off] {sym} ptr idx val mem)
  1148  
  1149  (MOVBstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1150  	(MOVBstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1151  (MOVWstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1152  	(MOVWstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1153  (MOVWstoreconst [x] {sym1} (LEAQ2 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1154  	(MOVWstoreconstidx2 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1155  (MOVLstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1156  	(MOVLstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1157  (MOVLstoreconst [x] {sym1} (LEAQ4 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1158  	(MOVLstoreconstidx4 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1159  (MOVQstoreconst [x] {sym1} (LEAQ1 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1160  	(MOVQstoreconstidx1 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1161  (MOVQstoreconst [x] {sym1} (LEAQ8 [off] {sym2} ptr idx) mem) && canMergeSym(sym1, sym2) ->
  1162  	(MOVQstoreconstidx8 [ValAndOff(x).add(off)] {mergeSym(sym1,sym2)} ptr idx mem)
  1163  
  1164  (MOVBstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVBstoreconstidx1 [x] {sym} ptr idx mem)
  1165  (MOVWstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVWstoreconstidx1 [x] {sym} ptr idx mem)
  1166  (MOVLstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVLstoreconstidx1 [x] {sym} ptr idx mem)
  1167  (MOVQstoreconst [x] {sym} (ADDQ ptr idx) mem) -> (MOVQstoreconstidx1 [x] {sym} ptr idx mem)
  1168  
  1169  // combine SHLQ into indexed loads and stores
  1170  (MOVWloadidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWloadidx2 [c] {sym} ptr idx mem)
  1171  (MOVLloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLloadidx4 [c] {sym} ptr idx mem)
  1172  (MOVQloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQloadidx8 [c] {sym} ptr idx mem)
  1173  (MOVSSloadidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVSSloadidx4 [c] {sym} ptr idx mem)
  1174  (MOVSDloadidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVSDloadidx8 [c] {sym} ptr idx mem)
  1175  (MOVWstoreidx1 [c] {sym} ptr (SHLQconst [1] idx) val mem) -> (MOVWstoreidx2 [c] {sym} ptr idx val mem)
  1176  (MOVLstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVLstoreidx4 [c] {sym} ptr idx val mem)
  1177  (MOVQstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVQstoreidx8 [c] {sym} ptr idx val mem)
  1178  (MOVSSstoreidx1 [c] {sym} ptr (SHLQconst [2] idx) val mem) -> (MOVSSstoreidx4 [c] {sym} ptr idx val mem)
  1179  (MOVSDstoreidx1 [c] {sym} ptr (SHLQconst [3] idx) val mem) -> (MOVSDstoreidx8 [c] {sym} ptr idx val mem)
  1180  (MOVWstoreconstidx1 [c] {sym} ptr (SHLQconst [1] idx) mem) -> (MOVWstoreconstidx2 [c] {sym} ptr idx mem)
  1181  (MOVLstoreconstidx1 [c] {sym} ptr (SHLQconst [2] idx) mem) -> (MOVLstoreconstidx4 [c] {sym} ptr idx mem)
  1182  (MOVQstoreconstidx1 [c] {sym} ptr (SHLQconst [3] idx) mem) -> (MOVQstoreconstidx8 [c] {sym} ptr idx mem)
  1183  
  1184  // combine ADDQ into indexed loads and stores
  1185  (MOVBloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem)
  1186  (MOVWloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem)
  1187  (MOVWloadidx2 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVWloadidx2 [c+d] {sym} ptr idx mem)
  1188  (MOVLloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem)
  1189  (MOVLloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVLloadidx4 [c+d] {sym} ptr idx mem)
  1190  (MOVQloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem)
  1191  (MOVQloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVQloadidx8 [c+d] {sym} ptr idx mem)
  1192  (MOVSSloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem)
  1193  (MOVSSloadidx4 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSSloadidx4 [c+d] {sym} ptr idx mem)
  1194  (MOVSDloadidx1 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem)
  1195  (MOVSDloadidx8 [c] {sym} (ADDQconst [d] ptr) idx mem) -> (MOVSDloadidx8 [c+d] {sym} ptr idx mem)
  1196  
  1197  (MOVBstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem)
  1198  (MOVWstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem)
  1199  (MOVWstoreidx2 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVWstoreidx2 [c+d] {sym} ptr idx val mem)
  1200  (MOVLstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem)
  1201  (MOVLstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVLstoreidx4 [c+d] {sym} ptr idx val mem)
  1202  (MOVQstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem)
  1203  (MOVQstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVQstoreidx8 [c+d] {sym} ptr idx val mem)
  1204  (MOVSSstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem)
  1205  (MOVSSstoreidx4 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSSstoreidx4 [c+d] {sym} ptr idx val mem)
  1206  (MOVSDstoreidx1 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem)
  1207  (MOVSDstoreidx8 [c] {sym} (ADDQconst [d] ptr) idx val mem) -> (MOVSDstoreidx8 [c+d] {sym} ptr idx val mem)
  1208  
  1209  (MOVBloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVBloadidx1 [c+d] {sym} ptr idx mem)
  1210  (MOVWloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx1 [c+d] {sym} ptr idx mem)
  1211  (MOVWloadidx2 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVWloadidx2 [c+2*d] {sym} ptr idx mem)
  1212  (MOVLloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx1 [c+d] {sym} ptr idx mem)
  1213  (MOVLloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVLloadidx4 [c+4*d] {sym} ptr idx mem)
  1214  (MOVQloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx1 [c+d] {sym} ptr idx mem)
  1215  (MOVQloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVQloadidx8 [c+8*d] {sym} ptr idx mem)
  1216  (MOVSSloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx1 [c+d] {sym} ptr idx mem)
  1217  (MOVSSloadidx4 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSSloadidx4 [c+4*d] {sym} ptr idx mem)
  1218  (MOVSDloadidx1 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx1 [c+d] {sym} ptr idx mem)
  1219  (MOVSDloadidx8 [c] {sym} ptr (ADDQconst [d] idx) mem) -> (MOVSDloadidx8 [c+8*d] {sym} ptr idx mem)
  1220  
  1221  (MOVBstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVBstoreidx1 [c+d] {sym} ptr idx val mem)
  1222  (MOVWstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx1 [c+d] {sym} ptr idx val mem)
  1223  (MOVWstoreidx2 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVWstoreidx2 [c+2*d] {sym} ptr idx val mem)
  1224  (MOVLstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx1 [c+d] {sym} ptr idx val mem)
  1225  (MOVLstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVLstoreidx4 [c+4*d] {sym} ptr idx val mem)
  1226  (MOVQstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx1 [c+d] {sym} ptr idx val mem)
  1227  (MOVQstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVQstoreidx8 [c+8*d] {sym} ptr idx val mem)
  1228  (MOVSSstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx1 [c+d] {sym} ptr idx val mem)
  1229  (MOVSSstoreidx4 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSSstoreidx4 [c+4*d] {sym} ptr idx val mem)
  1230  (MOVSDstoreidx1 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx1 [c+d] {sym} ptr idx val mem)
  1231  (MOVSDstoreidx8 [c] {sym} ptr (ADDQconst [d] idx) val mem) -> (MOVSDstoreidx8 [c+8*d] {sym} ptr idx val mem)
  1232  
  1233  (MOVBstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1234  	(MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1235  (MOVWstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1236  	(MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1237  (MOVWstoreconstidx2 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1238  	(MOVWstoreconstidx2 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1239  (MOVLstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1240  	(MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1241  (MOVLstoreconstidx4 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1242  	(MOVLstoreconstidx4 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1243  (MOVQstoreconstidx1 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1244  	(MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1245  (MOVQstoreconstidx8 [x] {sym} (ADDQconst [c] ptr) idx mem) ->
  1246  	(MOVQstoreconstidx8 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1247  
  1248  (MOVBstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1249  	(MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1250  (MOVWstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1251  	(MOVWstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1252  (MOVWstoreconstidx2 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1253  	(MOVWstoreconstidx2 [ValAndOff(x).add(2*c)] {sym} ptr idx mem)
  1254  (MOVLstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1255  	(MOVLstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1256  (MOVLstoreconstidx4 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1257  	(MOVLstoreconstidx4 [ValAndOff(x).add(4*c)] {sym} ptr idx mem)
  1258  (MOVQstoreconstidx1 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1259  	(MOVQstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem)
  1260  (MOVQstoreconstidx8 [x] {sym} ptr (ADDQconst [c] idx) mem) ->
  1261  	(MOVQstoreconstidx8 [ValAndOff(x).add(8*c)] {sym} ptr idx mem)
  1262  
  1263  // fold LEAQs together
  1264  (LEAQ [off1] {sym1} (LEAQ [off2] {sym2} x)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1265        (LEAQ [off1+off2] {mergeSym(sym1,sym2)} x)
  1266  
  1267  // LEAQ into LEAQ1
  1268  (LEAQ1 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB ->
  1269         (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1270  
  1271  // LEAQ1 into LEAQ
  1272  (LEAQ [off1] {sym1} (LEAQ1 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1273         (LEAQ1 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1274  
  1275  // LEAQ into LEAQ[248]
  1276  (LEAQ2 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB ->
  1277         (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1278  (LEAQ4 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB ->
  1279         (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1280  (LEAQ8 [off1] {sym1} (LEAQ [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB ->
  1281         (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1282  
  1283  // LEAQ[248] into LEAQ
  1284  (LEAQ [off1] {sym1} (LEAQ2 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1285        (LEAQ2 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1286  (LEAQ [off1] {sym1} (LEAQ4 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1287        (LEAQ4 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1288  (LEAQ [off1] {sym1} (LEAQ8 [off2] {sym2} x y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  1289        (LEAQ8 [off1+off2] {mergeSym(sym1,sym2)} x y)
  1290  
  1291  // Absorb InvertFlags into branches.
  1292  (LT (InvertFlags cmp) yes no) -> (GT cmp yes no)
  1293  (GT (InvertFlags cmp) yes no) -> (LT cmp yes no)
  1294  (LE (InvertFlags cmp) yes no) -> (GE cmp yes no)
  1295  (GE (InvertFlags cmp) yes no) -> (LE cmp yes no)
  1296  (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no)
  1297  (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no)
  1298  (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no)
  1299  (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no)
  1300  (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no)
  1301  (NE (InvertFlags cmp) yes no) -> (NE cmp yes no)
  1302  
  1303  // Constant comparisons.
  1304  (CMPQconst (MOVQconst [x]) [y]) && x==y -> (FlagEQ)
  1305  (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)<uint64(y) -> (FlagLT_ULT)
  1306  (CMPQconst (MOVQconst [x]) [y]) && x<y && uint64(x)>uint64(y) -> (FlagLT_UGT)
  1307  (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)<uint64(y) -> (FlagGT_ULT)
  1308  (CMPQconst (MOVQconst [x]) [y]) && x>y && uint64(x)>uint64(y) -> (FlagGT_UGT)
  1309  (CMPLconst (MOVLconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ)
  1310  (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT)
  1311  (CMPLconst (MOVLconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT)
  1312  (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT)
  1313  (CMPLconst (MOVLconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT)
  1314  (CMPWconst (MOVLconst [x]) [y]) && int16(x)==int16(y) -> (FlagEQ)
  1315  (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)<uint16(y) -> (FlagLT_ULT)
  1316  (CMPWconst (MOVLconst [x]) [y]) && int16(x)<int16(y) && uint16(x)>uint16(y) -> (FlagLT_UGT)
  1317  (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)<uint16(y) -> (FlagGT_ULT)
  1318  (CMPWconst (MOVLconst [x]) [y]) && int16(x)>int16(y) && uint16(x)>uint16(y) -> (FlagGT_UGT)
  1319  (CMPBconst (MOVLconst [x]) [y]) && int8(x)==int8(y) -> (FlagEQ)
  1320  (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)<uint8(y) -> (FlagLT_ULT)
  1321  (CMPBconst (MOVLconst [x]) [y]) && int8(x)<int8(y) && uint8(x)>uint8(y) -> (FlagLT_UGT)
  1322  (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)<uint8(y) -> (FlagGT_ULT)
  1323  (CMPBconst (MOVLconst [x]) [y]) && int8(x)>int8(y) && uint8(x)>uint8(y) -> (FlagGT_UGT)
  1324  
  1325  // Other known comparisons.
  1326  (CMPQconst (MOVBQZX _) [c]) && 0xFF < c -> (FlagLT_ULT)
  1327  (CMPQconst (MOVWQZX _) [c]) && 0xFFFF < c -> (FlagLT_ULT)
  1328  (CMPQconst (MOVLQZX _) [c]) && 0xFFFFFFFF < c -> (FlagLT_ULT)
  1329  (CMPLconst (SHRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT_ULT)
  1330  (CMPQconst (SHRQconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT)
  1331  (CMPQconst (ANDQconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT)
  1332  (CMPQconst (ANDLconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT)
  1333  (CMPLconst (ANDLconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT)
  1334  (CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT)
  1335  (CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT)
  1336  
  1337  // TODO: DIVxU also.
  1338  
  1339  // Absorb flag constants into SBB ops.
  1340  (SBBQcarrymask (FlagEQ)) -> (MOVQconst [0])
  1341  (SBBQcarrymask (FlagLT_ULT)) -> (MOVQconst [-1])
  1342  (SBBQcarrymask (FlagLT_UGT)) -> (MOVQconst [0])
  1343  (SBBQcarrymask (FlagGT_ULT)) -> (MOVQconst [-1])
  1344  (SBBQcarrymask (FlagGT_UGT)) -> (MOVQconst [0])
  1345  (SBBLcarrymask (FlagEQ)) -> (MOVLconst [0])
  1346  (SBBLcarrymask (FlagLT_ULT)) -> (MOVLconst [-1])
  1347  (SBBLcarrymask (FlagLT_UGT)) -> (MOVLconst [0])
  1348  (SBBLcarrymask (FlagGT_ULT)) -> (MOVLconst [-1])
  1349  (SBBLcarrymask (FlagGT_UGT)) -> (MOVLconst [0])
  1350  
  1351  // Absorb flag constants into branches.
  1352  (EQ (FlagEQ) yes no) -> (First nil yes no)
  1353  (EQ (FlagLT_ULT) yes no) -> (First nil no yes)
  1354  (EQ (FlagLT_UGT) yes no) -> (First nil no yes)
  1355  (EQ (FlagGT_ULT) yes no) -> (First nil no yes)
  1356  (EQ (FlagGT_UGT) yes no) -> (First nil no yes)
  1357  
  1358  (NE (FlagEQ) yes no) -> (First nil no yes)
  1359  (NE (FlagLT_ULT) yes no) -> (First nil yes no)
  1360  (NE (FlagLT_UGT) yes no) -> (First nil yes no)
  1361  (NE (FlagGT_ULT) yes no) -> (First nil yes no)
  1362  (NE (FlagGT_UGT) yes no) -> (First nil yes no)
  1363  
  1364  (LT (FlagEQ) yes no) -> (First nil no yes)
  1365  (LT (FlagLT_ULT) yes no) -> (First nil yes no)
  1366  (LT (FlagLT_UGT) yes no) -> (First nil yes no)
  1367  (LT (FlagGT_ULT) yes no) -> (First nil no yes)
  1368  (LT (FlagGT_UGT) yes no) -> (First nil no yes)
  1369  
  1370  (LE (FlagEQ) yes no) -> (First nil yes no)
  1371  (LE (FlagLT_ULT) yes no) -> (First nil yes no)
  1372  (LE (FlagLT_UGT) yes no) -> (First nil yes no)
  1373  (LE (FlagGT_ULT) yes no) -> (First nil no yes)
  1374  (LE (FlagGT_UGT) yes no) -> (First nil no yes)
  1375  
  1376  (GT (FlagEQ) yes no) -> (First nil no yes)
  1377  (GT (FlagLT_ULT) yes no) -> (First nil no yes)
  1378  (GT (FlagLT_UGT) yes no) -> (First nil no yes)
  1379  (GT (FlagGT_ULT) yes no) -> (First nil yes no)
  1380  (GT (FlagGT_UGT) yes no) -> (First nil yes no)
  1381  
  1382  (GE (FlagEQ) yes no) -> (First nil yes no)
  1383  (GE (FlagLT_ULT) yes no) -> (First nil no yes)
  1384  (GE (FlagLT_UGT) yes no) -> (First nil no yes)
  1385  (GE (FlagGT_ULT) yes no) -> (First nil yes no)
  1386  (GE (FlagGT_UGT) yes no) -> (First nil yes no)
  1387  
  1388  (ULT (FlagEQ) yes no) -> (First nil no yes)
  1389  (ULT (FlagLT_ULT) yes no) -> (First nil yes no)
  1390  (ULT (FlagLT_UGT) yes no) -> (First nil no yes)
  1391  (ULT (FlagGT_ULT) yes no) -> (First nil yes no)
  1392  (ULT (FlagGT_UGT) yes no) -> (First nil no yes)
  1393  
  1394  (ULE (FlagEQ) yes no) -> (First nil yes no)
  1395  (ULE (FlagLT_ULT) yes no) -> (First nil yes no)
  1396  (ULE (FlagLT_UGT) yes no) -> (First nil no yes)
  1397  (ULE (FlagGT_ULT) yes no) -> (First nil yes no)
  1398  (ULE (FlagGT_UGT) yes no) -> (First nil no yes)
  1399  
  1400  (UGT (FlagEQ) yes no) -> (First nil no yes)
  1401  (UGT (FlagLT_ULT) yes no) -> (First nil no yes)
  1402  (UGT (FlagLT_UGT) yes no) -> (First nil yes no)
  1403  (UGT (FlagGT_ULT) yes no) -> (First nil no yes)
  1404  (UGT (FlagGT_UGT) yes no) -> (First nil yes no)
  1405  
  1406  (UGE (FlagEQ) yes no) -> (First nil yes no)
  1407  (UGE (FlagLT_ULT) yes no) -> (First nil no yes)
  1408  (UGE (FlagLT_UGT) yes no) -> (First nil yes no)
  1409  (UGE (FlagGT_ULT) yes no) -> (First nil no yes)
  1410  (UGE (FlagGT_UGT) yes no) -> (First nil yes no)
  1411  
  1412  // Absorb flag constants into SETxx ops.
  1413  (SETEQ (FlagEQ)) -> (MOVLconst [1])
  1414  (SETEQ (FlagLT_ULT)) -> (MOVLconst [0])
  1415  (SETEQ (FlagLT_UGT)) -> (MOVLconst [0])
  1416  (SETEQ (FlagGT_ULT)) -> (MOVLconst [0])
  1417  (SETEQ (FlagGT_UGT)) -> (MOVLconst [0])
  1418  
  1419  (SETNE (FlagEQ)) -> (MOVLconst [0])
  1420  (SETNE (FlagLT_ULT)) -> (MOVLconst [1])
  1421  (SETNE (FlagLT_UGT)) -> (MOVLconst [1])
  1422  (SETNE (FlagGT_ULT)) -> (MOVLconst [1])
  1423  (SETNE (FlagGT_UGT)) -> (MOVLconst [1])
  1424  
  1425  (SETL (FlagEQ)) -> (MOVLconst [0])
  1426  (SETL (FlagLT_ULT)) -> (MOVLconst [1])
  1427  (SETL (FlagLT_UGT)) -> (MOVLconst [1])
  1428  (SETL (FlagGT_ULT)) -> (MOVLconst [0])
  1429  (SETL (FlagGT_UGT)) -> (MOVLconst [0])
  1430  
  1431  (SETLE (FlagEQ)) -> (MOVLconst [1])
  1432  (SETLE (FlagLT_ULT)) -> (MOVLconst [1])
  1433  (SETLE (FlagLT_UGT)) -> (MOVLconst [1])
  1434  (SETLE (FlagGT_ULT)) -> (MOVLconst [0])
  1435  (SETLE (FlagGT_UGT)) -> (MOVLconst [0])
  1436  
  1437  (SETG (FlagEQ)) -> (MOVLconst [0])
  1438  (SETG (FlagLT_ULT)) -> (MOVLconst [0])
  1439  (SETG (FlagLT_UGT)) -> (MOVLconst [0])
  1440  (SETG (FlagGT_ULT)) -> (MOVLconst [1])
  1441  (SETG (FlagGT_UGT)) -> (MOVLconst [1])
  1442  
  1443  (SETGE (FlagEQ)) -> (MOVLconst [1])
  1444  (SETGE (FlagLT_ULT)) -> (MOVLconst [0])
  1445  (SETGE (FlagLT_UGT)) -> (MOVLconst [0])
  1446  (SETGE (FlagGT_ULT)) -> (MOVLconst [1])
  1447  (SETGE (FlagGT_UGT)) -> (MOVLconst [1])
  1448  
  1449  (SETB (FlagEQ)) -> (MOVLconst [0])
  1450  (SETB (FlagLT_ULT)) -> (MOVLconst [1])
  1451  (SETB (FlagLT_UGT)) -> (MOVLconst [0])
  1452  (SETB (FlagGT_ULT)) -> (MOVLconst [1])
  1453  (SETB (FlagGT_UGT)) -> (MOVLconst [0])
  1454  
  1455  (SETBE (FlagEQ)) -> (MOVLconst [1])
  1456  (SETBE (FlagLT_ULT)) -> (MOVLconst [1])
  1457  (SETBE (FlagLT_UGT)) -> (MOVLconst [0])
  1458  (SETBE (FlagGT_ULT)) -> (MOVLconst [1])
  1459  (SETBE (FlagGT_UGT)) -> (MOVLconst [0])
  1460  
  1461  (SETA (FlagEQ)) -> (MOVLconst [0])
  1462  (SETA (FlagLT_ULT)) -> (MOVLconst [0])
  1463  (SETA (FlagLT_UGT)) -> (MOVLconst [1])
  1464  (SETA (FlagGT_ULT)) -> (MOVLconst [0])
  1465  (SETA (FlagGT_UGT)) -> (MOVLconst [1])
  1466  
  1467  (SETAE (FlagEQ)) -> (MOVLconst [1])
  1468  (SETAE (FlagLT_ULT)) -> (MOVLconst [0])
  1469  (SETAE (FlagLT_UGT)) -> (MOVLconst [1])
  1470  (SETAE (FlagGT_ULT)) -> (MOVLconst [0])
  1471  (SETAE (FlagGT_UGT)) -> (MOVLconst [1])
  1472  
  1473  // Remove redundant *const ops
  1474  (ADDQconst [0] x) -> x
  1475  (ADDLconst [c] x) && int32(c)==0 -> x
  1476  (SUBQconst [0] x) -> x
  1477  (SUBLconst [c] x) && int32(c) == 0 -> x
  1478  (ANDQconst [0] _)                 -> (MOVQconst [0])
  1479  (ANDLconst [c] _) && int32(c)==0  -> (MOVLconst [0])
  1480  (ANDQconst [-1] x)                -> x
  1481  (ANDLconst [c] x) && int32(c)==-1 -> x
  1482  (ORQconst [0] x)                  -> x
  1483  (ORLconst [c] x) && int32(c)==0   -> x
  1484  (ORQconst [-1] _)                 -> (MOVQconst [-1])
  1485  (ORLconst [c] _) && int32(c)==-1  -> (MOVLconst [-1])
  1486  (XORQconst [0] x)                  -> x
  1487  (XORLconst [c] x) && int32(c)==0   -> x
  1488  // TODO: since we got rid of the W/B versions, we might miss
  1489  // things like (ANDLconst [0x100] x) which were formerly
  1490  // (ANDBconst [0] x).  Probably doesn't happen very often.
  1491  // If we cared, we might do:
  1492  //  (ANDLconst <t> [c] x) && t.Size()==1 && int8(x)==0 -> (MOVLconst [0])
  1493  
  1494  // Convert constant subtracts to constant adds
  1495  (SUBQconst [c] x) && c != -(1<<31) -> (ADDQconst [-c] x)
  1496  (SUBLconst [c] x) -> (ADDLconst [int64(int32(-c))] x)
  1497  
  1498  // generic constant folding
  1499  // TODO: more of this
  1500  (ADDQconst [c] (MOVQconst [d])) -> (MOVQconst [c+d])
  1501  (ADDLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c+d))])
  1502  (ADDQconst [c] (ADDQconst [d] x)) && is32Bit(c+d) -> (ADDQconst [c+d] x)
  1503  (ADDLconst [c] (ADDLconst [d] x)) -> (ADDLconst [int64(int32(c+d))] x)
  1504  (SUBQconst (MOVQconst [d]) [c]) -> (MOVQconst [d-c])
  1505  (SUBQconst (SUBQconst x [d]) [c]) && is32Bit(-c-d) -> (ADDQconst [-c-d] x)
  1506  (SARQconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
  1507  (SARLconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
  1508  (SARWconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
  1509  (SARBconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
  1510  (NEGQ (MOVQconst [c])) -> (MOVQconst [-c])
  1511  (NEGL (MOVLconst [c])) -> (MOVLconst [int64(int32(-c))])
  1512  (MULQconst [c] (MOVQconst [d])) -> (MOVQconst [c*d])
  1513  (MULLconst [c] (MOVLconst [d])) -> (MOVLconst [int64(int32(c*d))])
  1514  (ANDQconst [c] (MOVQconst [d])) -> (MOVQconst [c&d])
  1515  (ANDLconst [c] (MOVLconst [d])) -> (MOVLconst [c&d])
  1516  (ORQconst [c] (MOVQconst [d])) -> (MOVQconst [c|d])
  1517  (ORLconst [c] (MOVLconst [d])) -> (MOVLconst [c|d])
  1518  (XORQconst [c] (MOVQconst [d])) -> (MOVQconst [c^d])
  1519  (XORLconst [c] (MOVLconst [d])) -> (MOVLconst [c^d])
  1520  (NOTQ (MOVQconst [c])) -> (MOVQconst [^c])
  1521  (NOTL (MOVLconst [c])) -> (MOVLconst [^c])
  1522  
  1523  // generic simplifications
  1524  // TODO: more of this
  1525  (ADDQ x (NEGQ y)) -> (SUBQ x y)
  1526  (ADDL x (NEGL y)) -> (SUBL x y)
  1527  (SUBQ x x) -> (MOVQconst [0])
  1528  (SUBL x x) -> (MOVLconst [0])
  1529  (ANDQ x x) -> x
  1530  (ANDL x x) -> x
  1531  (ORQ x x) -> x
  1532  (ORL x x) -> x
  1533  (XORQ x x) -> (MOVQconst [0])
  1534  (XORL x x) -> (MOVLconst [0])
  1535  (NEGQ (ADDQconst [c] (NEGQ x))) && c != -(1<<31) -> (ADDQconst [-c] x)
  1536  
  1537  // checking AND against 0.
  1538  (CMPQconst (ANDQ x y) [0]) -> (TESTQ x y)
  1539  (CMPLconst (ANDL x y) [0]) -> (TESTL x y)
  1540  (CMPWconst (ANDL x y) [0]) -> (TESTW x y)
  1541  (CMPBconst (ANDL x y) [0]) -> (TESTB x y)
  1542  (CMPQconst (ANDQconst [c] x) [0]) -> (TESTQconst [c] x)
  1543  (CMPLconst (ANDLconst [c] x) [0]) -> (TESTLconst [c] x)
  1544  (CMPWconst (ANDLconst [c] x) [0]) -> (TESTWconst [int64(int16(c))] x)
  1545  (CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x)
  1546  
  1547  // Convert TESTx to TESTxconst if possible.
  1548  (TESTQ (MOVQconst [c]) x) && is32Bit(c) -> (TESTQconst [c] x)
  1549  (TESTL (MOVLconst [c]) x) -> (TESTLconst [c] x)
  1550  (TESTW (MOVLconst [c]) x) -> (TESTWconst [c] x)
  1551  (TESTB (MOVLconst [c]) x) -> (TESTBconst [c] x)
  1552  
  1553  // TEST %reg,%reg is shorter than CMP
  1554  (CMPQconst x [0]) -> (TESTQ x x)
  1555  (CMPLconst x [0]) -> (TESTL x x)
  1556  (CMPWconst x [0]) -> (TESTW x x)
  1557  (CMPBconst x [0]) -> (TESTB x x)
  1558  
  1559  // Combining byte loads into larger (unaligned) loads.
  1560  // There are many ways these combinations could occur.  This is
  1561  // designed to match the way encoding/binary.LittleEndian does it.
  1562  
  1563  // Little-endian loads
  1564  
  1565  (ORL                  x0:(MOVBload [i0] {s} p mem)
  1566      sh:(SHLLconst [8] x1:(MOVBload [i1] {s} p mem)))
  1567    && i1 == i0+1
  1568    && x0.Uses == 1
  1569    && x1.Uses == 1
  1570    && sh.Uses == 1
  1571    && mergePoint(b,x0,x1) != nil
  1572    && clobber(x0)
  1573    && clobber(x1)
  1574    && clobber(sh)
  1575    -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem)
  1576  
  1577  (ORQ                  x0:(MOVBload [i0] {s} p mem)
  1578      sh:(SHLQconst [8] x1:(MOVBload [i1] {s} p mem)))
  1579    && i1 == i0+1
  1580    && x0.Uses == 1
  1581    && x1.Uses == 1
  1582    && sh.Uses == 1
  1583    && mergePoint(b,x0,x1) != nil
  1584    && clobber(x0)
  1585    && clobber(x1)
  1586    && clobber(sh)
  1587    -> @mergePoint(b,x0,x1) (MOVWload [i0] {s} p mem)
  1588  
  1589  (ORL                   x0:(MOVWload [i0] {s} p mem)
  1590      sh:(SHLLconst [16] x1:(MOVWload [i1] {s} p mem)))
  1591    && i1 == i0+2
  1592    && x0.Uses == 1
  1593    && x1.Uses == 1
  1594    && sh.Uses == 1
  1595    && mergePoint(b,x0,x1) != nil
  1596    && clobber(x0)
  1597    && clobber(x1)
  1598    && clobber(sh)
  1599    -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem)
  1600  
  1601  (ORQ                   x0:(MOVWload [i0] {s} p mem)
  1602      sh:(SHLQconst [16] x1:(MOVWload [i1] {s} p mem)))
  1603    && i1 == i0+2
  1604    && x0.Uses == 1
  1605    && x1.Uses == 1
  1606    && sh.Uses == 1
  1607    && mergePoint(b,x0,x1) != nil
  1608    && clobber(x0)
  1609    && clobber(x1)
  1610    && clobber(sh)
  1611    -> @mergePoint(b,x0,x1) (MOVLload [i0] {s} p mem)
  1612  
  1613  (ORQ                   x0:(MOVLload [i0] {s} p mem)
  1614      sh:(SHLQconst [32] x1:(MOVLload [i1] {s} p mem)))
  1615    && i1 == i0+4
  1616    && x0.Uses == 1
  1617    && x1.Uses == 1
  1618    && sh.Uses == 1
  1619    && mergePoint(b,x0,x1) != nil
  1620    && clobber(x0)
  1621    && clobber(x1)
  1622    && clobber(sh)
  1623    -> @mergePoint(b,x0,x1) (MOVQload [i0] {s} p mem)
  1624  
  1625  (ORL
  1626      s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem))
  1627      or:(ORL
  1628          s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem))
  1629  	y))
  1630    && i1 == i0+1
  1631    && j1 == j0+8
  1632    && j0 % 16 == 0
  1633    && x0.Uses == 1
  1634    && x1.Uses == 1
  1635    && s0.Uses == 1
  1636    && s1.Uses == 1
  1637    && or.Uses == 1
  1638    && mergePoint(b,x0,x1) != nil
  1639    && clobber(x0)
  1640    && clobber(x1)
  1641    && clobber(s0)
  1642    && clobber(s1)
  1643    && clobber(or)
  1644    -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y)
  1645  
  1646  (ORQ
  1647      s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem))
  1648      or:(ORQ
  1649          s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem))
  1650  	y))
  1651    && i1 == i0+1
  1652    && j1 == j0+8
  1653    && j0 % 16 == 0
  1654    && x0.Uses == 1
  1655    && x1.Uses == 1
  1656    && s0.Uses == 1
  1657    && s1.Uses == 1
  1658    && or.Uses == 1
  1659    && mergePoint(b,x0,x1) != nil
  1660    && clobber(x0)
  1661    && clobber(x1)
  1662    && clobber(s0)
  1663    && clobber(s1)
  1664    && clobber(or)
  1665    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWload [i0] {s} p mem)) y)
  1666  
  1667  (ORQ
  1668      s1:(SHLQconst [j1] x1:(MOVWload [i1] {s} p mem))
  1669      or:(ORQ
  1670          s0:(SHLQconst [j0] x0:(MOVWload [i0] {s} p mem))
  1671  	y))
  1672    && i1 == i0+2
  1673    && j1 == j0+16
  1674    && j0 % 32 == 0
  1675    && x0.Uses == 1
  1676    && x1.Uses == 1
  1677    && s0.Uses == 1
  1678    && s1.Uses == 1
  1679    && or.Uses == 1
  1680    && mergePoint(b,x0,x1) != nil
  1681    && clobber(x0)
  1682    && clobber(x1)
  1683    && clobber(s0)
  1684    && clobber(s1)
  1685    && clobber(or)
  1686    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLload [i0] {s} p mem)) y)
  1687  
  1688  // Little-endian indexed loads
  1689  
  1690  (ORL                  x0:(MOVBloadidx1 [i0] {s} p idx mem)
  1691      sh:(SHLLconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem)))
  1692    && i1 == i0+1
  1693    && x0.Uses == 1
  1694    && x1.Uses == 1
  1695    && sh.Uses == 1
  1696    && mergePoint(b,x0,x1) != nil
  1697    && clobber(x0)
  1698    && clobber(x1)
  1699    && clobber(sh)
  1700    -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem)
  1701  
  1702  (ORQ                  x0:(MOVBloadidx1 [i0] {s} p idx mem)
  1703      sh:(SHLQconst [8] x1:(MOVBloadidx1 [i1] {s} p idx mem)))
  1704    && i1 == i0+1
  1705    && x0.Uses == 1
  1706    && x1.Uses == 1
  1707    && sh.Uses == 1
  1708    && mergePoint(b,x0,x1) != nil
  1709    && clobber(x0)
  1710    && clobber(x1)
  1711    && clobber(sh)
  1712    -> @mergePoint(b,x0,x1) (MOVWloadidx1 <v.Type> [i0] {s} p idx mem)
  1713  
  1714  (ORL                   x0:(MOVWloadidx1 [i0] {s} p idx mem)
  1715      sh:(SHLLconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem)))
  1716    && i1 == i0+2
  1717    && x0.Uses == 1
  1718    && x1.Uses == 1
  1719    && sh.Uses == 1
  1720    && mergePoint(b,x0,x1) != nil
  1721    && clobber(x0)
  1722    && clobber(x1)
  1723    && clobber(sh)
  1724    -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem)
  1725  
  1726  (ORQ                   x0:(MOVWloadidx1 [i0] {s} p idx mem)
  1727      sh:(SHLQconst [16] x1:(MOVWloadidx1 [i1] {s} p idx mem)))
  1728    && i1 == i0+2
  1729    && x0.Uses == 1
  1730    && x1.Uses == 1
  1731    && sh.Uses == 1
  1732    && mergePoint(b,x0,x1) != nil
  1733    && clobber(x0)
  1734    && clobber(x1)
  1735    && clobber(sh)
  1736    -> @mergePoint(b,x0,x1) (MOVLloadidx1 [i0] {s} p idx mem)
  1737  
  1738  (ORQ                   x0:(MOVLloadidx1 [i0] {s} p idx mem)
  1739      sh:(SHLQconst [32] x1:(MOVLloadidx1 [i1] {s} p idx mem)))
  1740    && i1 == i0+4
  1741    && x0.Uses == 1
  1742    && x1.Uses == 1
  1743    && sh.Uses == 1
  1744    && mergePoint(b,x0,x1) != nil
  1745    && clobber(x0)
  1746    && clobber(x1)
  1747    && clobber(sh)
  1748    -> @mergePoint(b,x0,x1) (MOVQloadidx1 [i0] {s} p idx mem)
  1749  
  1750  (ORL
  1751      s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem))
  1752      or:(ORL
  1753          s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem))
  1754  	y))
  1755    && i1 == i0+1
  1756    && j1 == j0+8
  1757    && j0 % 16 == 0
  1758    && x0.Uses == 1
  1759    && x1.Uses == 1
  1760    && s0.Uses == 1
  1761    && s1.Uses == 1
  1762    && or.Uses == 1
  1763    && mergePoint(b,x0,x1) != nil
  1764    && clobber(x0)
  1765    && clobber(x1)
  1766    && clobber(s0)
  1767    && clobber(s1)
  1768    && clobber(or)
  1769    -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y)
  1770  
  1771  (ORQ
  1772      s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem))
  1773      or:(ORQ
  1774          s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem))
  1775  	y))
  1776    && i1 == i0+1
  1777    && j1 == j0+8
  1778    && j0 % 16 == 0
  1779    && x0.Uses == 1
  1780    && x1.Uses == 1
  1781    && s0.Uses == 1
  1782    && s1.Uses == 1
  1783    && or.Uses == 1
  1784    && mergePoint(b,x0,x1) != nil
  1785    && clobber(x0)
  1786    && clobber(x1)
  1787    && clobber(s0)
  1788    && clobber(s1)
  1789    && clobber(or)
  1790    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVWloadidx1 [i0] {s} p idx mem)) y)
  1791  
  1792  (ORQ
  1793      s1:(SHLQconst [j1] x1:(MOVWloadidx1 [i1] {s} p idx mem))
  1794      or:(ORQ
  1795          s0:(SHLQconst [j0] x0:(MOVWloadidx1 [i0] {s} p idx mem))
  1796  	y))
  1797    && i1 == i0+2
  1798    && j1 == j0+16
  1799    && j0 % 32 == 0
  1800    && x0.Uses == 1
  1801    && x1.Uses == 1
  1802    && s0.Uses == 1
  1803    && s1.Uses == 1
  1804    && or.Uses == 1
  1805    && mergePoint(b,x0,x1) != nil
  1806    && clobber(x0)
  1807    && clobber(x1)
  1808    && clobber(s0)
  1809    && clobber(s1)
  1810    && clobber(or)
  1811    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j0] (MOVLloadidx1 [i0] {s} p idx mem)) y)
  1812  
  1813  // Big-endian loads
  1814  
  1815  (ORL
  1816                         x1:(MOVBload [i1] {s} p mem)
  1817      sh:(SHLLconst [8]  x0:(MOVBload [i0] {s} p mem)))
  1818    && i1 == i0+1
  1819    && x0.Uses == 1
  1820    && x1.Uses == 1
  1821    && sh.Uses == 1
  1822    && mergePoint(b,x0,x1) != nil
  1823    && clobber(x0)
  1824    && clobber(x1)
  1825    && clobber(sh)
  1826    -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem))
  1827  
  1828  (ORQ
  1829                         x1:(MOVBload [i1] {s} p mem)
  1830      sh:(SHLQconst [8]  x0:(MOVBload [i0] {s} p mem)))
  1831    && i1 == i0+1
  1832    && x0.Uses == 1
  1833    && x1.Uses == 1
  1834    && sh.Uses == 1
  1835    && mergePoint(b,x0,x1) != nil
  1836    && clobber(x0)
  1837    && clobber(x1)
  1838    && clobber(sh)
  1839    -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWload [i0] {s} p mem))
  1840  
  1841  (ORL
  1842                          r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem))
  1843      sh:(SHLLconst [16]  r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem))))
  1844    && i1 == i0+2
  1845    && x0.Uses == 1
  1846    && x1.Uses == 1
  1847    && r0.Uses == 1
  1848    && r1.Uses == 1
  1849    && sh.Uses == 1
  1850    && mergePoint(b,x0,x1) != nil
  1851    && clobber(x0)
  1852    && clobber(x1)
  1853    && clobber(r0)
  1854    && clobber(r1)
  1855    && clobber(sh)
  1856    -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem))
  1857  
  1858  (ORQ
  1859                          r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem))
  1860      sh:(SHLQconst [16]  r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem))))
  1861    && i1 == i0+2
  1862    && x0.Uses == 1
  1863    && x1.Uses == 1
  1864    && r0.Uses == 1
  1865    && r1.Uses == 1
  1866    && sh.Uses == 1
  1867    && mergePoint(b,x0,x1) != nil
  1868    && clobber(x0)
  1869    && clobber(x1)
  1870    && clobber(r0)
  1871    && clobber(r1)
  1872    && clobber(sh)
  1873    -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLload [i0] {s} p mem))
  1874  
  1875  (ORQ
  1876                          r1:(BSWAPL x1:(MOVLload [i1] {s} p mem))
  1877      sh:(SHLQconst [32]  r0:(BSWAPL x0:(MOVLload [i0] {s} p mem))))
  1878    && i1 == i0+4
  1879    && x0.Uses == 1
  1880    && x1.Uses == 1
  1881    && r0.Uses == 1
  1882    && r1.Uses == 1
  1883    && sh.Uses == 1
  1884    && mergePoint(b,x0,x1) != nil
  1885    && clobber(x0)
  1886    && clobber(x1)
  1887    && clobber(r0)
  1888    && clobber(r1)
  1889    && clobber(sh)
  1890    -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQload [i0] {s} p mem))
  1891  
  1892  (ORL
  1893      s0:(SHLLconst [j0] x0:(MOVBload [i0] {s} p mem))
  1894      or:(ORL
  1895          s1:(SHLLconst [j1] x1:(MOVBload [i1] {s} p mem))
  1896  	y))
  1897    && i1 == i0+1
  1898    && j1 == j0-8
  1899    && j1 % 16 == 0
  1900    && x0.Uses == 1
  1901    && x1.Uses == 1
  1902    && s0.Uses == 1
  1903    && s1.Uses == 1
  1904    && or.Uses == 1
  1905    && mergePoint(b,x0,x1) != nil
  1906    && clobber(x0)
  1907    && clobber(x1)
  1908    && clobber(s0)
  1909    && clobber(s1)
  1910    && clobber(or)
  1911    -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWload [i0] {s} p mem))) y)
  1912  
  1913  (ORQ
  1914      s0:(SHLQconst [j0] x0:(MOVBload [i0] {s} p mem))
  1915      or:(ORQ
  1916          s1:(SHLQconst [j1] x1:(MOVBload [i1] {s} p mem))
  1917  	y))
  1918    && i1 == i0+1
  1919    && j1 == j0-8
  1920    && j1 % 16 == 0
  1921    && x0.Uses == 1
  1922    && x1.Uses == 1
  1923    && s0.Uses == 1
  1924    && s1.Uses == 1
  1925    && or.Uses == 1
  1926    && mergePoint(b,x0,x1) != nil
  1927    && clobber(x0)
  1928    && clobber(x1)
  1929    && clobber(s0)
  1930    && clobber(s1)
  1931    && clobber(or)
  1932    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWload [i0] {s} p mem))) y)
  1933  
  1934  (ORQ
  1935      s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWload [i0] {s} p mem)))
  1936      or:(ORQ
  1937          s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWload [i1] {s} p mem)))
  1938  	y))
  1939    && i1 == i0+2
  1940    && j1 == j0-16
  1941    && j1 % 32 == 0
  1942    && x0.Uses == 1
  1943    && x1.Uses == 1
  1944    && r0.Uses == 1
  1945    && r1.Uses == 1
  1946    && s0.Uses == 1
  1947    && s1.Uses == 1
  1948    && or.Uses == 1
  1949    && mergePoint(b,x0,x1) != nil
  1950    && clobber(x0)
  1951    && clobber(x1)
  1952    && clobber(r0)
  1953    && clobber(r1)
  1954    && clobber(s0)
  1955    && clobber(s1)
  1956    && clobber(or)
  1957    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <typ.UInt32> (MOVLload [i0] {s} p mem))) y)
  1958  
  1959  // Big-endian indexed loads
  1960  
  1961  (ORL
  1962                         x1:(MOVBloadidx1 [i1] {s} p idx mem)
  1963      sh:(SHLLconst [8]  x0:(MOVBloadidx1 [i0] {s} p idx mem)))
  1964    && i1 == i0+1
  1965    && x0.Uses == 1
  1966    && x1.Uses == 1
  1967    && sh.Uses == 1
  1968    && mergePoint(b,x0,x1) != nil
  1969    && clobber(x0)
  1970    && clobber(x1)
  1971    && clobber(sh)
  1972    -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem))
  1973  
  1974  (ORQ
  1975                         x1:(MOVBloadidx1 [i1] {s} p idx mem)
  1976      sh:(SHLQconst [8]  x0:(MOVBloadidx1 [i0] {s} p idx mem)))
  1977    && i1 == i0+1
  1978    && x0.Uses == 1
  1979    && x1.Uses == 1
  1980    && sh.Uses == 1
  1981    && mergePoint(b,x0,x1) != nil
  1982    && clobber(x0)
  1983    && clobber(x1)
  1984    && clobber(sh)
  1985    -> @mergePoint(b,x0,x1) (ROLWconst <v.Type> [8] (MOVWloadidx1 [i0] {s} p idx mem))
  1986  
  1987  (ORL
  1988                          r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem))
  1989      sh:(SHLLconst [16]  r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem))))
  1990    && i1 == i0+2
  1991    && x0.Uses == 1
  1992    && x1.Uses == 1
  1993    && r0.Uses == 1
  1994    && r1.Uses == 1
  1995    && sh.Uses == 1
  1996    && mergePoint(b,x0,x1) != nil
  1997    && clobber(x0)
  1998    && clobber(x1)
  1999    && clobber(r0)
  2000    && clobber(r1)
  2001    && clobber(sh)
  2002    -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem))
  2003  
  2004  (ORQ
  2005                          r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem))
  2006      sh:(SHLQconst [16]  r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem))))
  2007    && i1 == i0+2
  2008    && x0.Uses == 1
  2009    && x1.Uses == 1
  2010    && r0.Uses == 1
  2011    && r1.Uses == 1
  2012    && sh.Uses == 1
  2013    && mergePoint(b,x0,x1) != nil
  2014    && clobber(x0)
  2015    && clobber(x1)
  2016    && clobber(r0)
  2017    && clobber(r1)
  2018    && clobber(sh)
  2019    -> @mergePoint(b,x0,x1) (BSWAPL <v.Type> (MOVLloadidx1 [i0] {s} p idx mem))
  2020  
  2021  (ORQ
  2022                          r1:(BSWAPL x1:(MOVLloadidx1 [i1] {s} p idx mem))
  2023      sh:(SHLQconst [32]  r0:(BSWAPL x0:(MOVLloadidx1 [i0] {s} p idx mem))))
  2024    && i1 == i0+4
  2025    && x0.Uses == 1
  2026    && x1.Uses == 1
  2027    && r0.Uses == 1
  2028    && r1.Uses == 1
  2029    && sh.Uses == 1
  2030    && mergePoint(b,x0,x1) != nil
  2031    && clobber(x0)
  2032    && clobber(x1)
  2033    && clobber(r0)
  2034    && clobber(r1)
  2035    && clobber(sh)
  2036    -> @mergePoint(b,x0,x1) (BSWAPQ <v.Type> (MOVQloadidx1 [i0] {s} p idx mem))
  2037  
  2038  (ORL
  2039      s0:(SHLLconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem))
  2040      or:(ORL
  2041          s1:(SHLLconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem))
  2042  	y))
  2043    && i1 == i0+1
  2044    && j1 == j0-8
  2045    && j1 % 16 == 0
  2046    && x0.Uses == 1
  2047    && x1.Uses == 1
  2048    && s0.Uses == 1
  2049    && s1.Uses == 1
  2050    && or.Uses == 1
  2051    && mergePoint(b,x0,x1) != nil
  2052    && clobber(x0)
  2053    && clobber(x1)
  2054    && clobber(s0)
  2055    && clobber(s1)
  2056    && clobber(or)
  2057    -> @mergePoint(b,x0,x1) (ORL <v.Type> (SHLLconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y)
  2058  
  2059  (ORQ
  2060      s0:(SHLQconst [j0] x0:(MOVBloadidx1 [i0] {s} p idx mem))
  2061      or:(ORQ
  2062          s1:(SHLQconst [j1] x1:(MOVBloadidx1 [i1] {s} p idx mem))
  2063  	y))
  2064    && i1 == i0+1
  2065    && j1 == j0-8
  2066    && j1 % 16 == 0
  2067    && x0.Uses == 1
  2068    && x1.Uses == 1
  2069    && s0.Uses == 1
  2070    && s1.Uses == 1
  2071    && or.Uses == 1
  2072    && mergePoint(b,x0,x1) != nil
  2073    && clobber(x0)
  2074    && clobber(x1)
  2075    && clobber(s0)
  2076    && clobber(s1)
  2077    && clobber(or)
  2078    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (ROLWconst <typ.UInt16> [8] (MOVWloadidx1 [i0] {s} p idx mem))) y)
  2079  
  2080  (ORQ
  2081      s0:(SHLQconst [j0] r0:(ROLWconst [8] x0:(MOVWloadidx1 [i0] {s} p idx mem)))
  2082      or:(ORQ
  2083          s1:(SHLQconst [j1] r1:(ROLWconst [8] x1:(MOVWloadidx1 [i1] {s} p idx mem)))
  2084  	y))
  2085    && i1 == i0+2
  2086    && j1 == j0-16
  2087    && j1 % 32 == 0
  2088    && x0.Uses == 1
  2089    && x1.Uses == 1
  2090    && r0.Uses == 1
  2091    && r1.Uses == 1
  2092    && s0.Uses == 1
  2093    && s1.Uses == 1
  2094    && or.Uses == 1
  2095    && mergePoint(b,x0,x1) != nil
  2096    && clobber(x0)
  2097    && clobber(x1)
  2098    && clobber(r0)
  2099    && clobber(r1)
  2100    && clobber(s0)
  2101    && clobber(s1)
  2102    && clobber(or)
  2103    -> @mergePoint(b,x0,x1) (ORQ <v.Type> (SHLQconst <v.Type> [j1] (BSWAPL <typ.UInt32> (MOVLloadidx1 [i0] {s} p idx mem))) y)
  2104  
  2105  // Combine 2 byte stores + shift into rolw 8 + word store
  2106  (MOVBstore [i] {s} p w
  2107    x0:(MOVBstore [i-1] {s} p (SHRWconst [8] w) mem))
  2108    && x0.Uses == 1
  2109    && clobber(x0)
  2110    -> (MOVWstore [i-1] {s} p (ROLWconst <w.Type> [8] w) mem)
  2111  
  2112  (MOVBstoreidx1 [i] {s} p idx w
  2113    x0:(MOVBstoreidx1 [i-1] {s} p idx (SHRWconst [8] w) mem))
  2114    && x0.Uses == 1
  2115    && clobber(x0)
  2116    -> (MOVWstoreidx1 [i-1] {s} p idx (ROLWconst <w.Type> [8] w) mem)
  2117  
  2118  // Combine stores + shifts into bswap and larger (unaligned) stores
  2119  (MOVBstore [i] {s} p w
  2120    x2:(MOVBstore [i-1] {s} p (SHRLconst [8] w)
  2121    x1:(MOVBstore [i-2] {s} p (SHRLconst [16] w)
  2122    x0:(MOVBstore [i-3] {s} p (SHRLconst [24] w) mem))))
  2123    && x0.Uses == 1
  2124    && x1.Uses == 1
  2125    && x2.Uses == 1
  2126    && clobber(x0)
  2127    && clobber(x1)
  2128    && clobber(x2)
  2129    -> (MOVLstore [i-3] {s} p (BSWAPL <w.Type> w) mem)
  2130  
  2131  (MOVBstoreidx1 [i] {s} p idx w
  2132    x2:(MOVBstoreidx1 [i-1] {s} p idx (SHRLconst [8] w)
  2133    x1:(MOVBstoreidx1 [i-2] {s} p idx (SHRLconst [16] w)
  2134    x0:(MOVBstoreidx1 [i-3] {s} p idx (SHRLconst [24] w) mem))))
  2135    && x0.Uses == 1
  2136    && x1.Uses == 1
  2137    && x2.Uses == 1
  2138    && clobber(x0)
  2139    && clobber(x1)
  2140    && clobber(x2)
  2141    -> (MOVLstoreidx1 [i-3] {s} p idx (BSWAPL <w.Type> w) mem)
  2142  
  2143  (MOVBstore [i] {s} p w
  2144    x6:(MOVBstore [i-1] {s} p (SHRQconst [8] w)
  2145    x5:(MOVBstore [i-2] {s} p (SHRQconst [16] w)
  2146    x4:(MOVBstore [i-3] {s} p (SHRQconst [24] w)
  2147    x3:(MOVBstore [i-4] {s} p (SHRQconst [32] w)
  2148    x2:(MOVBstore [i-5] {s} p (SHRQconst [40] w)
  2149    x1:(MOVBstore [i-6] {s} p (SHRQconst [48] w)
  2150    x0:(MOVBstore [i-7] {s} p (SHRQconst [56] w) mem))))))))
  2151    && x0.Uses == 1
  2152    && x1.Uses == 1
  2153    && x2.Uses == 1
  2154    && x3.Uses == 1
  2155    && x4.Uses == 1
  2156    && x5.Uses == 1
  2157    && x6.Uses == 1
  2158    && clobber(x0)
  2159    && clobber(x1)
  2160    && clobber(x2)
  2161    && clobber(x3)
  2162    && clobber(x4)
  2163    && clobber(x5)
  2164    && clobber(x6)
  2165    -> (MOVQstore [i-7] {s} p (BSWAPQ <w.Type> w) mem)
  2166  
  2167  (MOVBstoreidx1 [i] {s} p idx w
  2168    x6:(MOVBstoreidx1 [i-1] {s} p idx (SHRQconst [8] w)
  2169    x5:(MOVBstoreidx1 [i-2] {s} p idx (SHRQconst [16] w)
  2170    x4:(MOVBstoreidx1 [i-3] {s} p idx (SHRQconst [24] w)
  2171    x3:(MOVBstoreidx1 [i-4] {s} p idx (SHRQconst [32] w)
  2172    x2:(MOVBstoreidx1 [i-5] {s} p idx (SHRQconst [40] w)
  2173    x1:(MOVBstoreidx1 [i-6] {s} p idx (SHRQconst [48] w)
  2174    x0:(MOVBstoreidx1 [i-7] {s} p idx (SHRQconst [56] w) mem))))))))
  2175    && x0.Uses == 1
  2176    && x1.Uses == 1
  2177    && x2.Uses == 1
  2178    && x3.Uses == 1
  2179    && x4.Uses == 1
  2180    && x5.Uses == 1
  2181    && x6.Uses == 1
  2182    && clobber(x0)
  2183    && clobber(x1)
  2184    && clobber(x2)
  2185    && clobber(x3)
  2186    && clobber(x4)
  2187    && clobber(x5)
  2188    && clobber(x6)
  2189    -> (MOVQstoreidx1 [i-7] {s} p idx (BSWAPQ <w.Type> w) mem)
  2190  
  2191  // Combine constant stores into larger (unaligned) stores.
  2192  (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem))
  2193    && x.Uses == 1
  2194    && ValAndOff(a).Off() + 1 == ValAndOff(c).Off()
  2195    && clobber(x)
  2196    -> (MOVWstoreconst [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p mem)
  2197  (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem))
  2198    && x.Uses == 1
  2199    && ValAndOff(a).Off() + 2 == ValAndOff(c).Off()
  2200    && clobber(x)
  2201    -> (MOVLstoreconst [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p mem)
  2202  (MOVLstoreconst [c] {s} p x:(MOVLstoreconst [a] {s} p mem))
  2203    && x.Uses == 1
  2204    && ValAndOff(a).Off() + 4 == ValAndOff(c).Off()
  2205    && clobber(x)
  2206    -> (MOVQstore [ValAndOff(a).Off()] {s} p (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem)
  2207  (MOVQstoreconst [c] {s} p x:(MOVQstoreconst [c2] {s} p mem))
  2208    && x.Uses == 1
  2209    && ValAndOff(c2).Off() + 8 == ValAndOff(c).Off()
  2210    && ValAndOff(c).Val() == 0
  2211    && ValAndOff(c2).Val() == 0
  2212    && clobber(x)
  2213    -> (MOVOstore [ValAndOff(c2).Off()] {s} p (MOVOconst [0]) mem)
  2214  
  2215  (MOVBstoreconstidx1 [c] {s} p i x:(MOVBstoreconstidx1 [a] {s} p i mem))
  2216    && x.Uses == 1
  2217    && ValAndOff(a).Off() + 1 == ValAndOff(c).Off()
  2218    && clobber(x)
  2219    -> (MOVWstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xff | ValAndOff(c).Val()<<8, ValAndOff(a).Off())] {s} p i mem)
  2220  (MOVWstoreconstidx1 [c] {s} p i x:(MOVWstoreconstidx1 [a] {s} p i mem))
  2221    && x.Uses == 1
  2222    && ValAndOff(a).Off() + 2 == ValAndOff(c).Off()
  2223    && clobber(x)
  2224    -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p i mem)
  2225  (MOVLstoreconstidx1 [c] {s} p i x:(MOVLstoreconstidx1 [a] {s} p i mem))
  2226    && x.Uses == 1
  2227    && ValAndOff(a).Off() + 4 == ValAndOff(c).Off()
  2228    && clobber(x)
  2229    -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p i (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem)
  2230  
  2231  (MOVWstoreconstidx2 [c] {s} p i x:(MOVWstoreconstidx2 [a] {s} p i mem))
  2232    && x.Uses == 1
  2233    && ValAndOff(a).Off() + 2 == ValAndOff(c).Off()
  2234    && clobber(x)
  2235    -> (MOVLstoreconstidx1 [makeValAndOff(ValAndOff(a).Val()&0xffff | ValAndOff(c).Val()<<16, ValAndOff(a).Off())] {s} p (SHLQconst <i.Type> [1] i) mem)
  2236  (MOVLstoreconstidx4 [c] {s} p i x:(MOVLstoreconstidx4 [a] {s} p i mem))
  2237    && x.Uses == 1
  2238    && ValAndOff(a).Off() + 4 == ValAndOff(c).Off()
  2239    && clobber(x)
  2240    -> (MOVQstoreidx1 [ValAndOff(a).Off()] {s} p (SHLQconst <i.Type> [2] i) (MOVQconst [ValAndOff(a).Val()&0xffffffff | ValAndOff(c).Val()<<32]) mem)
  2241  
  2242  // Combine stores into larger (unaligned) stores.
  2243  (MOVBstore [i] {s} p (SHRQconst [8] w) x:(MOVBstore [i-1] {s} p w mem))
  2244    && x.Uses == 1
  2245    && clobber(x)
  2246    -> (MOVWstore [i-1] {s} p w mem)
  2247  (MOVBstore [i] {s} p (SHRQconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SHRQconst [j-8] w) mem))
  2248    && x.Uses == 1
  2249    && clobber(x)
  2250    -> (MOVWstore [i-1] {s} p w0 mem)
  2251  (MOVWstore [i] {s} p (SHRQconst [16] w) x:(MOVWstore [i-2] {s} p w mem))
  2252    && x.Uses == 1
  2253    && clobber(x)
  2254    -> (MOVLstore [i-2] {s} p w mem)
  2255  (MOVWstore [i] {s} p (SHRQconst [j] w) x:(MOVWstore [i-2] {s} p w0:(SHRQconst [j-16] w) mem))
  2256    && x.Uses == 1
  2257    && clobber(x)
  2258    -> (MOVLstore [i-2] {s} p w0 mem)
  2259  (MOVLstore [i] {s} p (SHRQconst [32] w) x:(MOVLstore [i-4] {s} p w mem))
  2260    && x.Uses == 1
  2261    && clobber(x)
  2262    -> (MOVQstore [i-4] {s} p w mem)
  2263  (MOVLstore [i] {s} p (SHRQconst [j] w) x:(MOVLstore [i-4] {s} p w0:(SHRQconst [j-32] w) mem))
  2264    && x.Uses == 1
  2265    && clobber(x)
  2266    -> (MOVQstore [i-4] {s} p w0 mem)
  2267  
  2268  (MOVBstoreidx1 [i] {s} p idx (SHRQconst [8] w) x:(MOVBstoreidx1 [i-1] {s} p idx w mem))
  2269    && x.Uses == 1
  2270    && clobber(x)
  2271    -> (MOVWstoreidx1 [i-1] {s} p idx w mem)
  2272  (MOVBstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVBstoreidx1 [i-1] {s} p idx w0:(SHRQconst [j-8] w) mem))
  2273    && x.Uses == 1
  2274    && clobber(x)
  2275    -> (MOVWstoreidx1 [i-1] {s} p idx w0 mem)
  2276  (MOVWstoreidx1 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx1 [i-2] {s} p idx w mem))
  2277    && x.Uses == 1
  2278    && clobber(x)
  2279    -> (MOVLstoreidx1 [i-2] {s} p idx w mem)
  2280  (MOVWstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx1 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem))
  2281    && x.Uses == 1
  2282    && clobber(x)
  2283    -> (MOVLstoreidx1 [i-2] {s} p idx w0 mem)
  2284  (MOVLstoreidx1 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx1 [i-4] {s} p idx w mem))
  2285    && x.Uses == 1
  2286    && clobber(x)
  2287    -> (MOVQstoreidx1 [i-4] {s} p idx w mem)
  2288  (MOVLstoreidx1 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx1 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem))
  2289    && x.Uses == 1
  2290    && clobber(x)
  2291    -> (MOVQstoreidx1 [i-4] {s} p idx w0 mem)
  2292  
  2293  (MOVWstoreidx2 [i] {s} p idx (SHRQconst [16] w) x:(MOVWstoreidx2 [i-2] {s} p idx w mem))
  2294    && x.Uses == 1
  2295    && clobber(x)
  2296    -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w mem)
  2297  (MOVWstoreidx2 [i] {s} p idx (SHRQconst [j] w) x:(MOVWstoreidx2 [i-2] {s} p idx w0:(SHRQconst [j-16] w) mem))
  2298    && x.Uses == 1
  2299    && clobber(x)
  2300    -> (MOVLstoreidx1 [i-2] {s} p (SHLQconst <idx.Type> [1] idx) w0 mem)
  2301  (MOVLstoreidx4 [i] {s} p idx (SHRQconst [32] w) x:(MOVLstoreidx4 [i-4] {s} p idx w mem))
  2302    && x.Uses == 1
  2303    && clobber(x)
  2304    -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w mem)
  2305  (MOVLstoreidx4 [i] {s} p idx (SHRQconst [j] w) x:(MOVLstoreidx4 [i-4] {s} p idx w0:(SHRQconst [j-32] w) mem))
  2306    && x.Uses == 1
  2307    && clobber(x)
  2308    -> (MOVQstoreidx1 [i-4] {s} p (SHLQconst <idx.Type> [2] idx) w0 mem)
  2309  
  2310  // amd64p32 rules
  2311  // same as the rules above, but with 32 instead of 64 bit pointer arithmetic.
  2312  // LEAQ,ADDQ -> LEAL,ADDL
  2313  (ADDLconst [c] (LEAL [d] {s} x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x)
  2314  (LEAL [c] {s} (ADDLconst [d] x)) && is32Bit(c+d) -> (LEAL [c+d] {s} x)
  2315  
  2316  (MOVQload  [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) ->
  2317  	(MOVQload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  2318  (MOVLload  [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) ->
  2319  	(MOVLload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  2320  (MOVWload  [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) ->
  2321  	(MOVWload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  2322  (MOVBload  [off1] {sym1} (LEAL [off2] {sym2} base) mem) && canMergeSym(sym1, sym2) ->
  2323  	(MOVBload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
  2324  
  2325  (MOVQstore  [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) ->
  2326  	(MOVQstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  2327  (MOVLstore  [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) ->
  2328  	(MOVLstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  2329  (MOVWstore  [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) ->
  2330  	(MOVWstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  2331  (MOVBstore  [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && canMergeSym(sym1, sym2) ->
  2332  	(MOVBstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
  2333  
  2334  (MOVQstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  2335  	(MOVQstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  2336  (MOVLstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  2337  	(MOVLstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  2338  (MOVWstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  2339  	(MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  2340  (MOVBstoreconst [sc] {sym1} (LEAL [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
  2341  	(MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
  2342  
  2343  (MOVQload  [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVQload  [off1+off2] {sym} ptr mem)
  2344  (MOVLload  [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVLload  [off1+off2] {sym} ptr mem)
  2345  (MOVWload  [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVWload  [off1+off2] {sym} ptr mem)
  2346  (MOVBload  [off1] {sym} (ADDLconst [off2] ptr) mem) && is32Bit(off1+off2) -> (MOVBload  [off1+off2] {sym} ptr mem)
  2347  (MOVQstore  [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVQstore  [off1+off2] {sym} ptr val mem)
  2348  (MOVLstore  [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVLstore  [off1+off2] {sym} ptr val mem)
  2349  (MOVWstore  [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVWstore  [off1+off2] {sym} ptr val mem)
  2350  (MOVBstore  [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVBstore  [off1+off2] {sym} ptr val mem)
  2351  (MOVQstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  2352  	(MOVQstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  2353  (MOVLstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  2354  	(MOVLstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  2355  (MOVWstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  2356  	(MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  2357  (MOVBstoreconst [sc] {s} (ADDLconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
  2358  	(MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
  2359  
  2360  // Merge load and op
  2361  // TODO: add indexed variants?
  2362  (ADDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDQmem x [off] {sym} ptr mem)
  2363  (ADDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDLmem x [off] {sym} ptr mem)
  2364  (SUBQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBQmem x [off] {sym} ptr mem)
  2365  (SUBL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBLmem x [off] {sym} ptr mem)
  2366  (ANDQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDQmem x [off] {sym} ptr mem)
  2367  (ANDL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ANDLmem x [off] {sym} ptr mem)
  2368  (ORQ  x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORQmem x [off] {sym} ptr mem)
  2369  (ORL  x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ORLmem x [off] {sym} ptr mem)
  2370  (XORQ x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORQmem x [off] {sym} ptr mem)
  2371  (XORL x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (XORLmem x [off] {sym} ptr mem)
  2372  (ADDSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSDmem x [off] {sym} ptr mem)
  2373  (ADDSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (ADDSSmem x [off] {sym} ptr mem)
  2374  (SUBSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSDmem x [off] {sym} ptr mem)
  2375  (SUBSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (SUBSSmem x [off] {sym} ptr mem)
  2376  (MULSD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSDmem x [off] {sym} ptr mem)
  2377  (MULSS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (MULSSmem x [off] {sym} ptr mem)
  2378  
  2379  // Merge ADDQconst and LEAQ into atomic loads.
  2380  (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) ->
  2381  	(MOVQatomicload [off1+off2] {sym} ptr mem)
  2382  (MOVLatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) ->
  2383  	(MOVLatomicload [off1+off2] {sym} ptr mem)
  2384  (MOVQatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  2385  	(MOVQatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
  2386  (MOVLatomicload [off1] {sym1} (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
  2387  	(MOVLatomicload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
  2388  
  2389  // Merge ADDQconst and LEAQ into atomic stores.
  2390  (XCHGQ [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) ->
  2391  	(XCHGQ [off1+off2] {sym} val ptr mem)
  2392  (XCHGQ [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB ->
  2393  	(XCHGQ [off1+off2] {mergeSym(sym1,sym2)} val ptr mem)
  2394  (XCHGL [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) ->
  2395  	(XCHGL [off1+off2] {sym} val ptr mem)
  2396  (XCHGL [off1] {sym1} val (LEAQ [off2] {sym2} ptr) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && ptr.Op != OpSB ->
  2397  	(XCHGL [off1+off2] {mergeSym(sym1,sym2)} val ptr mem)
  2398  
  2399  // Merge ADDQconst into atomic adds.
  2400  // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions.
  2401  (XADDQlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) ->
  2402  	(XADDQlock [off1+off2] {sym} val ptr mem)
  2403  (XADDLlock [off1] {sym} val (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) ->
  2404  	(XADDLlock [off1+off2] {sym} val ptr mem)
  2405  
  2406  // Merge ADDQconst into atomic compare and swaps.
  2407  // TODO: merging LEAQ doesn't work, assembler doesn't like the resulting instructions.
  2408  (CMPXCHGQlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) ->
  2409  	(CMPXCHGQlock [off1+off2] {sym} ptr old new_ mem)
  2410  (CMPXCHGLlock [off1] {sym} (ADDQconst [off2] ptr) old new_ mem) && is32Bit(off1+off2) ->
  2411  	(CMPXCHGLlock [off1+off2] {sym} ptr old new_ mem)
  2412  
  2413  // We don't need the conditional move if we know the arg of BSF is not zero.
  2414  (CMOVQEQ x _ (Select1 (BSFQ (ORQconst [c] _)))) && c != 0 -> x
  2415  // Extension is unnecessary for trailing zeros.
  2416  (BSFQ (ORQconst <t> [1<<8] (MOVBQZX x))) -> (BSFQ (ORQconst <t> [1<<8] x))
  2417  (BSFQ (ORQconst <t> [1<<16] (MOVWQZX x))) -> (BSFQ (ORQconst <t> [1<<16] x))
  2418  
  2419  // Redundant sign/zero extensions
  2420  (MOVLQSX x:(MOVLQSX _)) -> x
  2421  (MOVLQSX x:(MOVWQSX _)) -> x
  2422  (MOVLQSX x:(MOVBQSX _)) -> x
  2423  (MOVWQSX x:(MOVWQSX _)) -> x
  2424  (MOVWQSX x:(MOVBQSX _)) -> x
  2425  (MOVBQSX x:(MOVBQSX _)) -> x
  2426  (MOVLQZX x:(MOVLQZX _)) -> x
  2427  (MOVLQZX x:(MOVWQZX _)) -> x
  2428  (MOVLQZX x:(MOVBQZX _)) -> x
  2429  (MOVWQZX x:(MOVWQZX _)) -> x
  2430  (MOVWQZX x:(MOVBQZX _)) -> x
  2431  (MOVBQZX x:(MOVBQZX _)) -> x